Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
[Feat]: Capture LLM Prompts and Responses in Trace Events (#354)
patcher9ae200425c58d
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex 73ebfb7c..f01a8b6e 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.16.2"+version = "1.17.0"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]repository = "https://github.com/openlit/openlit/tree/main/openlit/python"diff --git a/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py b/sdk/python/src/openlit/instrumentation/anthropic/anthropic.pyindex a0a2778f..4cda8573 100644--- a/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py+++ b/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py@@ -130,7 +130,7 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,kwargs.get("top_k", ""))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- finish_reason)+ [finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -140,10 +140,18 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -234,7 +242,7 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,kwargs.get("top_k", ""))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.stop_reason)+ [response.stop_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.input_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -244,11 +252,21 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,response.usage.output_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)+if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.content[0].text if response.content else "")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.content[0].text if response.content else "",+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py b/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.pyindex a3227342..4f822141 100644--- a/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py+++ b/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py@@ -130,7 +130,7 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,kwargs.get("top_k", ""))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- finish_reason)+ [finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -140,10 +140,18 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -234,7 +242,7 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,kwargs.get("top_k", ""))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.stop_reason)+ [response.stop_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.input_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -245,10 +253,19 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.content[0].text if response.content else "")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.content[0].text if response.content else "",+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.pyindex bca07c78..0d710445 100644--- a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py+++ b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py@@ -96,7 +96,6 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,try:message_prompt = method_kwargs.get("messages", "")- print(message_prompt)formatted_messages = []for message in message_prompt:role = message["role"]@@ -144,10 +143,19 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response["output"]["message"]["content"][0]["text"])+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response["output"]["message"]["content"][0]["text"],+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/cohere/cohere.py b/sdk/python/src/openlit/instrumentation/cohere/cohere.pyindex e3bcd78f..b96b3c07 100644--- a/sdk/python/src/openlit/instrumentation/cohere/cohere.py+++ b/sdk/python/src/openlit/instrumentation/cohere/cohere.py@@ -89,8 +89,12 @@ def embed(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))@@ -205,7 +209,7 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,response.generation_id)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.finish_reason)+ [response.finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.meta.billed_units.input_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -215,11 +219,20 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,response.meta.billed_units.output_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)+if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("message", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -348,7 +361,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,response_id)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- finish_reason)+ [finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -358,10 +371,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("message", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py b/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.pyindex 11ed8859..36a8b586 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py@@ -80,8 +80,12 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- str(kwargs.get("text", "")))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.pyindex 235c0463..536a0b8b 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py@@ -86,8 +86,12 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- str(kwargs.get("text", "")))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py b/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.pyindex 1dc764b8..9c6b5494 100644--- a/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py+++ b/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py@@ -107,10 +107,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,True)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)@@ -195,10 +203,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)@@ -313,8 +329,12 @@ def embed(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/groq/async_groq.py b/sdk/python/src/openlit/instrumentation/groq/async_groq.pyindex d269bd8d..48434c88 100644--- a/sdk/python/src/openlit/instrumentation/groq/async_groq.py+++ b/sdk/python/src/openlit/instrumentation/groq/async_groq.py@@ -141,10 +141,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -237,8 +245,12 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -254,23 +266,31 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original responsediff --git a/sdk/python/src/openlit/instrumentation/groq/groq.py b/sdk/python/src/openlit/instrumentation/groq/groq.pyindex 9ccc7ecc..d057d937 100644--- a/sdk/python/src/openlit/instrumentation/groq/groq.py+++ b/sdk/python/src/openlit/instrumentation/groq/groq.py@@ -141,10 +141,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -237,8 +245,12 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -254,23 +266,31 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original responsediff --git a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.pyindex 28621165..9603711e 100644--- a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py+++ b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py@@ -103,7 +103,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -113,10 +113,19 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.choices[0].message.content if response.choices[0].message.content else "")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",+ },+ )span.set_status(Status(StatusCode.OK))@@ -260,7 +269,7 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,True)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- finish_reason)+ [finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -270,10 +279,18 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -378,8 +395,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/mistral/mistral.py b/sdk/python/src/openlit/instrumentation/mistral/mistral.pyindex 8a7453c5..983d63eb 100644--- a/sdk/python/src/openlit/instrumentation/mistral/mistral.py+++ b/sdk/python/src/openlit/instrumentation/mistral/mistral.py@@ -102,7 +102,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -112,10 +112,19 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.choices[0].message.content if response.choices[0].message.content else "")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ # pylint: disable=line-too-long+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",+ },+ )span.set_status(Status(StatusCode.OK))@@ -259,7 +268,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,True)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- finish_reason)+ [finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -269,10 +278,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -377,8 +394,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.pyindex dfd74fdf..f97294a3 100644--- a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py+++ b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py@@ -120,10 +120,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -198,10 +206,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response['message']['content'])+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],+ },+ )# Calculate cost of the operationcost = 0@@ -216,7 +232,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response["done_reason"])+ [response["done_reason"]])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)@@ -345,10 +361,19 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -404,10 +429,18 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response['response'])+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],+ },+ )# Calculate cost of the operationcost = 0@@ -422,7 +455,7 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response["done_reason"])+ [response["done_reason"]])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)@@ -525,8 +558,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get('prompt', ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/ollama/ollama.py b/sdk/python/src/openlit/instrumentation/ollama/ollama.pyindex 78e94e30..79071d3f 100644--- a/sdk/python/src/openlit/instrumentation/ollama/ollama.py+++ b/sdk/python/src/openlit/instrumentation/ollama/ollama.py@@ -120,10 +120,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -198,10 +206,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response['message']['content'])+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],+ },+ )# Calculate cost of the operationcost = 0@@ -216,7 +232,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response["done_reason"])+ [response["done_reason"]])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)@@ -345,10 +361,19 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -404,10 +429,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response['response'])+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],+ },+ )# Calculate cost of the operationcost = 0@@ -422,7 +455,7 @@ def generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response["done_reason"])+ [response["done_reason"]])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)@@ -525,8 +558,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get('prompt', ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/openai/async_azure_openai.py b/sdk/python/src/openlit/instrumentation/openai/async_azure_openai.pyindex f909b3e2..16704f98 100644--- a/sdk/python/src/openlit/instrumentation/openai/async_azure_openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/async_azure_openai.py@@ -143,10 +143,18 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicatspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -238,8 +246,12 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicatspan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -255,23 +267,31 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicatspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original response@@ -284,8 +304,12 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicatresponse.usage.prompt_tokens,response.usage.completion_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- "Function called with tools")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -443,10 +467,18 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_nspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -519,8 +551,12 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_nspan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -536,23 +572,31 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_nspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].text,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].text)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].text,+ },+ )i += 1return response@@ -563,8 +607,12 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_nresponse.usage.prompt_tokens,response.usage.completion_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- "Function called with tools")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -679,8 +727,12 @@ def azure_async_embedding(gen_ai_endpoint, version, environment, application_namresponse.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))@@ -796,12 +848,19 @@ def azure_async_image_generate(gen_ai_endpoint, version, environment, applicatiospan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,kwargs.get("user", ""))if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))-+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name,- getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1diff --git a/sdk/python/src/openlit/instrumentation/openai/async_openai.py b/sdk/python/src/openlit/instrumentation/openai/async_openai.pyindex 0d7d43ec..2768ea22 100644--- a/sdk/python/src/openlit/instrumentation/openai/async_openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/async_openai.py@@ -144,10 +144,18 @@ def async_chat_completions(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -240,8 +248,12 @@ def async_chat_completions(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))@@ -259,23 +271,31 @@ def async_chat_completions(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original response@@ -288,8 +308,12 @@ def async_chat_completions(gen_ai_endpoint, version, environment, application_napricing_info, response.usage.prompt_tokens,response.usage.completion_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- "Function called with tools")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -405,8 +429,12 @@ def async_embedding(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))@@ -611,12 +639,19 @@ def async_image_generate(gen_ai_endpoint, version, environment, application_namespan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,kwargs.get("user", ""))if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))-+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name,- getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1@@ -729,11 +764,13 @@ def async_image_variatons(gen_ai_endpoint, version, environment, application_namspan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,"standard")if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get(SemanticConvetion.GEN_AI_TYPE_IMAGE, ""))-attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name, getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1@@ -838,8 +875,12 @@ def async_audio_create(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/openai/azure_openai.py b/sdk/python/src/openlit/instrumentation/openai/azure_openai.pyindex fd02aea2..eebd9b69 100644--- a/sdk/python/src/openlit/instrumentation/openai/azure_openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/azure_openai.py@@ -143,10 +143,18 @@ def azure_chat_completions(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -237,6 +245,13 @@ def azure_chat_completions(gen_ai_endpoint, version, environment, application_nakwargs.get("seed", ""))span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)+ if trace_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )if trace_content:span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,prompt)@@ -255,23 +270,31 @@ def azure_chat_completions(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original response@@ -284,8 +307,12 @@ def azure_chat_completions(gen_ai_endpoint, version, environment, application_naresponse.usage.prompt_tokens,response.usage.completion_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- "Function called with tools")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -441,10 +468,18 @@ def azure_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -517,8 +552,12 @@ def azure_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -534,23 +573,31 @@ def azure_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].text,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].text)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].text,+ },+ )i += 1return response@@ -678,8 +725,12 @@ def azure_embedding(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))@@ -795,12 +846,19 @@ def azure_image_generate(gen_ai_endpoint, version, environment, application_namespan.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,kwargs.get("user", ""))if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))-+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name,- getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1diff --git a/sdk/python/src/openlit/instrumentation/openai/openai.py b/sdk/python/src/openlit/instrumentation/openai/openai.pyindex 93b01013..3ee03f6b 100644--- a/sdk/python/src/openlit/instrumentation/openai/openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/openai.py@@ -145,10 +145,18 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -241,8 +249,12 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,False)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )# Set span attributes when tools is not passed to the function callif "tools" not in kwargs:@@ -258,23 +270,31 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,response.usage.total_tokens)span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- response.choices[0].finish_reason)+ [response.choices[0].finish_reason])span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)# Set span attributes for when n = 1 (default)if "n" not in kwargs or kwargs["n"] == 1:if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.choices[0].message.content)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,+ },+ )# Set span attributes for when n > 0else:i = 0while i < kwargs["n"] and trace_content is True:- attribute_name = f"gen_ai.completion.{i}"- span.set_attribute(attribute_name,- response.choices[i].message.content)+ attribute_name = f"gen_ai.content.completion.{i}"+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,+ },+ )i += 1# Return original response@@ -286,9 +306,12 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),pricing_info, response.usage.prompt_tokens,response.usage.completion_tokens)-- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- "Function called with tools")+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",+ },+ )span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,response.usage.prompt_tokens)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,@@ -404,8 +427,12 @@ def embedding(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))@@ -626,12 +653,19 @@ def image_generate(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,kwargs.get("user", ""))if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("prompt", ""))-+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),+ },+ )attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name,- getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1@@ -744,12 +778,13 @@ def image_variatons(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,"standard")if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get(SemanticConvetion.GEN_AI_TYPE_IMAGE, ""))-attribute_name = f"gen_ai.response.image.{images_count}"- span.set_attribute(attribute_name,- getattr(items, image))+ span.add_event(+ name=attribute_name,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),+ },+ )images_count+=1@@ -854,8 +889,12 @@ def audio_create(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- kwargs.get("input", ""))+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/transformers/transformers.py b/sdk/python/src/openlit/instrumentation/transformers/transformers.pyindex e96e61f9..16a0c8f0 100644--- a/sdk/python/src/openlit/instrumentation/transformers/transformers.py+++ b/sdk/python/src/openlit/instrumentation/transformers/transformers.py@@ -88,29 +88,33 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,forward_params.get("top_p", "null"))span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,forward_params.get("max_length", -1))- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,- prompt_tokens)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,+ prompt_tokens)i = 0completion_tokens = 0for completion in response:if len(response) > 1:- attribute_name = f"gen_ai.completion.{i}"+ attribute_name = f"gen_ai.content.completion.{i}"else:- attribute_name = SemanticConvetion.GEN_AI_CONTENT_COMPLETION- if i == 0:- if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- completion["generated_text"])- completion_tokens += general_tokens(completion["generated_text"])- else:- if trace_content:- span.set_attribute(attribute_name,- completion["generated_text"])- completion_tokens += general_tokens(completion["generated_text"])+ attribute_name = SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT+ if trace_content:+ span.add_event(+ name=attribute_name,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: completion["generated_text"],+ },+ )+ completion_tokens += general_tokens(completion["generated_text"])+i=i+1span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,completion_tokens)diff --git a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.pyindex 91ec4bd7..b1d0f651 100644--- a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py+++ b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py@@ -103,10 +103,18 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -181,10 +189,19 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_naspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.candidates[0].content.parts[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.candidates[0].content.parts[0].text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -316,10 +333,18 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -394,11 +419,19 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.candidates[0].content.parts[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.candidates[0].content.parts[0].text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -516,10 +549,18 @@ def predict_async(gen_ai_endpoint, version, environment, application_name, tracespan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -648,10 +689,18 @@ def predict_streaming_async(gen_ai_endpoint, version, environment, application_nspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -765,10 +814,18 @@ def start_chat_async(gen_ai_endpoint, version, environment, application_name, trspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -895,10 +952,18 @@ def start_chat_streaming_async(gen_ai_endpoint, version, environment, applicatiospan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -1006,8 +1071,12 @@ def embeddings_async(gen_ai_endpoint, version, environment, application_name, trspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.pyindex 2657dfae..c0da193f 100644--- a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py+++ b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py@@ -103,10 +103,18 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, trspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -181,10 +189,19 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, trspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.candidates[0].content.parts[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.candidates[0].content.parts[0].text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -316,10 +333,18 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracerspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -394,11 +419,19 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracerspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- response.candidates[0].content.parts[0].text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ # pylint: disable=line-too-long+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.candidates[0].content.parts[0].text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -516,10 +549,18 @@ def predict(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -648,10 +689,18 @@ def predict_streaming(gen_ai_endpoint, version, environment, application_name, tspan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -765,10 +814,18 @@ def start_chat(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- # pylint: disable=line-too-long- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.text)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,+ },+ )span.set_status(Status(StatusCode.OK))@@ -895,10 +952,18 @@ def start_chat_streaming(gen_ai_endpoint, version, environment, application_namespan.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,- llmresponse)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,+ },+ )span.set_status(Status(StatusCode.OK))@@ -1006,8 +1071,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)if trace_content:- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,- prompt)+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )span.set_status(Status(StatusCode.OK))diff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.pyindex f527244c..34682538 100644--- a/sdk/python/src/openlit/semcov/__init__.py+++ b/sdk/python/src/openlit/semcov/__init__.py@@ -70,7 +70,9 @@ class SemanticConvetion:GEN_AI_RESPONSE_IMAGE = "gen_ai.response.image" # Not used directly in code yet# GenAI Content+ GEN_AI_CONTENT_PROMPT_EVENT = "gen_ai.content.prompt"GEN_AI_CONTENT_PROMPT = "gen_ai.prompt"+ GEN_AI_CONTENT_COMPLETION_EVENT = "gen_ai.content.completion"GEN_AI_CONTENT_COMPLETION = "gen_ai.completion"GEN_AI_CONTENT_REVISED_PROMPT = "gen_ai.content.revised_prompt"@@ -94,7 +96,7 @@ class SemanticConvetion:GEN_AI_SYSTEM_COHERE = "cohere"GEN_AI_SYSTEM_MISTRAL = "mistral"GEN_AI_SYSTEM_BEDROCK = "bedrock"- GEN_AI_SYSTEM_VERTEXAI = "vertexai"+ GEN_AI_SYSTEM_VERTEXAI = "vertex_ai"GEN_AI_SYSTEM_GROQ = "groq"GEN_AI_SYSTEM_OLLAMA = "ollama"GEN_AI_SYSTEM_GPT4ALL = "gpt4all"diff --git a/src/client/src/constants/traces.ts b/src/client/src/constants/traces.tsindex 7906c289..a3f6340a 100644--- a/src/client/src/constants/traces.ts+++ b/src/client/src/constants/traces.ts@@ -264,8 +264,8 @@ export const TraceMapping: Record<prompt: {label: "Prompt",type: "string",- path: "prompt",- prefix: SpanAttributesGenAIPrefix,+ path: ["Events.Attributes", "0", "gen_ai.prompt"],+ isRoot: true,},finishReason: {label: "Finish Reason",@@ -276,8 +276,8 @@ export const TraceMapping: Record<response: {label: "Response",type: "string",- path: "completion",- prefix: SpanAttributesGenAIPrefix,+ path: ["Events.Attributes", "1", "gen_ai.completion"],+ isRoot: true,},randomSeed: {label: "Random seed",@@ -473,4 +473,4 @@ export interface TraceRow {TraceState: string;Attributes: Record<string, string>;}[];-}\ No newline at end of file+}