Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: trace not pass through when trace_id has settled

mrFranklindd4fa371fa59
diff --git a/litellm/integrations/opik/opik.py b/litellm/integrations/opik/opik.py
index 5d98f220f38..9fa3482f663 100644
--- a/litellm/integrations/opik/opik.py
+++ b/litellm/integrations/opik/opik.py
@@ -224,12 +224,13 @@ class OpikLogger(CustomBatchLogger):
else:
trace_id = None
parent_span_id = None
-
+
# Create Opik tags
opik_tags = litellm_opik_metadata.get("tags", [])
if kwargs.get("custom_llm_provider"):
opik_tags.append(kwargs["custom_llm_provider"])
- # Create thread id
+
+ # Get thread_id if present
thread_id = litellm_opik_metadata.get("thread_id", None)
# Override with any opik_ headers from proxy request
@@ -242,10 +243,6 @@ class OpikLogger(CustomBatchLogger):
project_name = value
elif param_key == "thread_id" and value:
thread_id = value
- elif param_key == "trace_id" and value:
- trace_id = value
- elif param_key == "parent_span_id" and value:
- parent_span_id = value
elif param_key == "tags" and value:
try:
parsed_tags = json.loads(value)
@@ -319,21 +316,20 @@ class OpikLogger(CustomBatchLogger):
verbose_logger.debug(
f"OpikLogger creating payload for trace with id {trace_id}"
)
-
- payload.append(
- {
- "project_name": project_name,
- "id": trace_id,
- "name": trace_name,
- "start_time": start_time.astimezone(timezone.utc).isoformat().replace("+00:00", "Z"),
- "end_time": end_time.astimezone(timezone.utc).isoformat().replace("+00:00", "Z"),
- "input": input_data,
- "output": output_data,
- "metadata": metadata,
- "tags": opik_tags,
- "thread_id": thread_id,
- }
- )
+ payload.append(
+ {
+ "project_name": project_name,
+ "id": trace_id,
+ "name": trace_name,
+ "start_time": start_time.astimezone(timezone.utc).isoformat().replace("+00:00", "Z"),
+ "end_time": end_time.astimezone(timezone.utc).isoformat().replace("+00:00", "Z"),
+ "input": input_data,
+ "output": output_data,
+ "metadata": metadata,
+ "tags": opik_tags,
+ "thread_id": thread_id,
+ }
+ )
span_id = create_uuid7()
verbose_logger.debug(