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]: Use OpenTelemetry events for Content logging in Ollama and AI21 (#637)
Patcher6cb8b63e214d
diff --git a/docs/latest/features/tracing.mdx b/docs/latest/features/tracing.mdxindex 727d9c2b..8df856ae 100644--- a/docs/latest/features/tracing.mdx+++ b/docs/latest/features/tracing.mdx@@ -57,7 +57,7 @@ However, you may want to disable this logging for privacy reasons, as they may cExample:```python-openlit.init(trace_content=False)+openlit.init(capture_message_content=False)```## Disable Batchdiff --git a/docs/latest/sdk-configuration.mdx b/docs/latest/sdk-configuration.mdxindex 29c6c5bd..b9eb0873 100644--- a/docs/latest/sdk-configuration.mdx+++ b/docs/latest/sdk-configuration.mdx@@ -21,7 +21,7 @@ Below is a detailed overview of the configuration options available, allowing yo| `otlp_endpoint` | Specifies the OTLP endpoint for transmitting telemetry data. | `None` | No || `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No || `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |-| `trace_content` | Enables tracing of content for deeper insights. | `True` | No |+| `capture_message_content` | Enables tracing of content for deeper insights. | `True` | No || `disabled_instrumentors`| List of instrumentors to disable. | `None` | No || `disable_metrics` | If set, disables the collection of metrics. | `False` | No || `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |diff --git a/sdk/python/.pylintrc b/sdk/python/.pylintrcindex 3bfcf9bd..91ba1442 100644--- a/sdk/python/.pylintrc+++ b/sdk/python/.pylintrc@@ -7,7 +7,7 @@ max-locals=30max-args=25# Maximum number of positional arguments (see R0917).-max-positional-arguments=12+max-positional-arguments=15# Maximum allowed line lengthmax-line-length=120@@ -27,4 +27,5 @@ disable=too-many-lines,no-name-in-module,protected-access,- bare-except\ No newline at end of file+ bare-except,+ expression-not-assigned\ No newline at end of filediff --git a/sdk/python/README.md b/sdk/python/README.mdindex 761d322c..59803e03 100644--- a/sdk/python/README.md+++ b/sdk/python/README.md@@ -187,7 +187,7 @@ Below is a detailed overview of the configuration options available, allowing yo| `otlp_endpoint` | Specifies the OTLP endpoint for transmitting telemetry data. | `None` | No || `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No || `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |-| `trace_content` | Enables tracing of content for deeper insights. | `True` | No |+| `capture_message_content` | Enables tracing of content for deeper insights. | `True` | No || `disabled_instrumentors`| List of instrumentors to disable. | `None` | No || `disable_metrics` | If set, disables the collection of metrics. | `False` | No || `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex eea7ee41..e87cf8a4 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.33.10"+version = "1.33.11"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]license = "Apache-2.0"diff --git a/sdk/python/src/openlit/__helpers.py b/sdk/python/src/openlit/__helpers.pyindex 5a7de73a..e287e8b8 100644--- a/sdk/python/src/openlit/__helpers.py+++ b/sdk/python/src/openlit/__helpers.py@@ -11,6 +11,7 @@ import requestsimport tiktokenfrom opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENTfrom opentelemetry.trace import Status, StatusCode+from opentelemetry._events import Eventfrom openlit.semcov import SemanticConvetion# Set up logging@@ -285,3 +286,75 @@ def set_server_address_and_port(client_instance: Any,server_port = default_server_portreturn server_address, server_port++def otel_event(name, attributes, body):+ """+ Returns an OpenTelemetry Event object+ """++ return Event(+ name=name,+ attributes=attributes,+ body=body,+ )++def extract_and_format_input(messages):+ """+ Process a list of messages to extract content and categorize+ them into fixed roles like 'user', 'assistant', 'system'.+ """++ fixed_roles = ['user', 'assistant', 'system', 'tool'] # Ensure these are your fixed keys+ # Initialize the dictionary with fixed keys and empty structures+ formatted_messages = {role_key: {"role": "", "content": ""} for role_key in fixed_roles}++ for message in messages:+ # Normalize the message structure+ message = response_as_dict(message)++ # Extract role and content+ role = message.get("role")+ if role not in fixed_roles:+ continue # Skip any role not in our predefined roles++ content = message.get("content", "")++ # Prepare content as a string+ if isinstance(content, list):+ content_str = ", ".join(+ # pylint: disable=line-too-long+ f'{item.get("type", "text")}: {item.get("text", item.get("image_url", "").get("url", "") if isinstance(item.get("image_url", ""), dict) else item.get("image_url", ""))}'+ for item in content+ )+ else:+ content_str = content++ # Set the role in the formatted message and concatenate content+ if not formatted_messages[role]["role"]:+ formatted_messages[role]["role"] = role++ if formatted_messages[role]["content"]:+ formatted_messages[role]["content"] += " " + content_str+ else:+ formatted_messages[role]["content"] = content_str++ return formatted_messages++# To be removed one the change to log events (from span events) is complete+def concatenate_all_contents(formatted_messages):+ """+ Concatenate all 'content' fields from the formatted messages+ dictionary into a single string.++ Parameters:+ - formatted_messages: Dictionary with roles as keys and corresponding+ role and content as values.++ Returns:+ - A single string with all content concatenated.+ """+ return " ".join(+ message_data['content']+ for message_data in formatted_messages.values()+ if message_data['content']+ )diff --git a/sdk/python/src/openlit/__init__.py b/sdk/python/src/openlit/__init__.pyindex 4a8850e2..4da6f21c 100644--- a/sdk/python/src/openlit/__init__.py+++ b/sdk/python/src/openlit/__init__.py@@ -21,9 +21,9 @@ from opentelemetry.sdk.resources import SERVICE_NAME, DEPLOYMENT_ENVIRONMENTfrom openlit.semcov import SemanticConvetionfrom openlit.otel.tracing import setup_tracingfrom openlit.otel.metrics import setup_meter+from openlit.otel.events import setup_eventsfrom openlit.__helpers import fetch_pricing_info, get_env_variable-# Instrumentors for various large language models.from openlit.instrumentation.openai import OpenAIInstrumentorfrom openlit.instrumentation.anthropic import AnthropicInstrumentor@@ -85,10 +85,11 @@ class OpenlitConfig:application_name (str): Name of the application using openLIT.pricing_info (Dict[str, Any]): Pricing information.tracer (Optional[Any]): Tracer instance for OpenTelemetry.+ event_provider (Optional[Any]): Event logger provider for OpenTelemetry.otlp_endpoint (Optional[str]): Endpoint for OTLP.otlp_headers (Optional[Dict[str, str]]): Headers for OTLP.disable_batch (bool): Flag to disable batch span processing in tracing.- trace_content (bool): Flag to enable or disable tracing of content.+ capture_message_content (bool): Flag to enable or disable tracing of content."""_instance = None@@ -107,11 +108,12 @@ class OpenlitConfig:cls.application_name = "default"cls.pricing_info = {}cls.tracer = None+ cls.event_provider = Nonecls.metrics_dict = {}cls.otlp_endpoint = Nonecls.otlp_headers = Nonecls.disable_batch = False- cls.trace_content = True+ cls.capture_message_content = Truecls.disable_metrics = False@classmethod@@ -120,10 +122,11 @@ class OpenlitConfig:environment,application_name,tracer,+ event_provider,otlp_endpoint,otlp_headers,disable_batch,- trace_content,+ capture_message_content,metrics_dict,disable_metrics,pricing_json,@@ -135,22 +138,26 @@ class OpenlitConfig:environment (str): Deployment environment.application_name (str): Application name.tracer: Tracer instance.+ event_provider: Event logger provider instance.meter: Metric Instanceotlp_endpoint (str): OTLP endpoint.otlp_headers (Dict[str, str]): OTLP headers.disable_batch (bool): Disable batch span processing flag.- trace_content (bool): Enable or disable content tracing.+ capture_message_content (bool): Enable or disable content tracing.+ metrics_dict: Dictionary of metrics.+ disable_metrics (bool): Flag to disable metrics.pricing_json(str): path or url to the pricing json file"""cls.environment = environmentcls.application_name = application_namecls.pricing_info = fetch_pricing_info(pricing_json)cls.tracer = tracer+ cls.event_provider = event_providercls.metrics_dict = metrics_dictcls.otlp_endpoint = otlp_endpointcls.otlp_headers = otlp_headerscls.disable_batch = disable_batch- cls.trace_content = trace_content+ cls.capture_message_content = capture_message_contentcls.disable_metrics = disable_metrics@@ -187,8 +194,9 @@ def instrument_if_available(environment=config.environment,application_name=config.application_name,tracer=config.tracer,+ event_provider=config.event_provider,pricing_info=config.pricing_info,- trace_content=config.trace_content,+ capture_message_content=config.capture_message_content,metrics_dict=config.metrics_dict,disable_metrics=config.disable_metrics,)@@ -207,10 +215,11 @@ def init(environment="default",application_name="default",tracer=None,+ event_logger=None,otlp_endpoint=None,otlp_headers=None,disable_batch=False,- trace_content=True,+ capture_message_content=True,disabled_instrumentors=None,meter=None,disable_metrics=False,@@ -227,11 +236,12 @@ def init(environment (str): Deployment environment.application_name (str): Application name.tracer: Tracer instance (Optional).+ event_logger: EventLoggerProvider instance (Optional).meter: OpenTelemetry Metrics Instance (Optional).otlp_endpoint (str): OTLP endpoint for exporter (Optional).otlp_headers (Dict[str, str]): OTLP headers for exporter (Optional).disable_batch (bool): Flag to disable batch span processing (Optional).- trace_content (bool): Flag to trace content (Optional).+ capture_message_content (bool): Flag to trace content (Optional).disabled_instrumentors (List[str]): Optional. List of instrumentor names to disable.disable_metrics (bool): Flag to disable metrics (Optional).pricing_json(str): File path or url to the pricing json (Optional).@@ -308,9 +318,22 @@ def init()if not tracer:- logger.error("openLIT tracing setup failed. Tracing will not be available.")+ logger.error("OpenLIT tracing setup failed. Tracing will not be available.")return+ # Setup events based on the provided or default configuration.+ event_provider = setup_events(+ application_name=application_name,+ environment=environment,+ event_logger=event_logger,+ otlp_endpoint=None,+ otlp_headers=None,+ disable_batch=disable_batch,+ )++ if not event_provider:+ logger.error("OpenLIT events setup failed. Events will not be available")+# Setup meter and receive metrics_dict instead of meter.metrics_dict, err = setup_meter(application_name=application_name,@@ -326,15 +349,19 @@ def init()return+ if os.getenv("OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT", "").lower == "false":+ capture_message_content=False+# Update global configuration with the provided settings.config.update_config(environment,application_name,tracer,+ event_provider,otlp_endpoint,otlp_headers,disable_batch,- trace_content,+ capture_message_content,metrics_dict,disable_metrics,pricing_json,diff --git a/sdk/python/src/openlit/instrumentation/ag2/__init__.py b/sdk/python/src/openlit/instrumentation/ag2/__init__.pyindex b952f804..7362213e 100644--- a/sdk/python/src/openlit/instrumentation/ag2/__init__.py+++ b/sdk/python/src/openlit/instrumentation/ag2/__init__.py@@ -1,4 +1,3 @@-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code"""Initializer of Auto Instrumentation of AG2 Functions"""from typing import Collection@@ -7,7 +6,7 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentorfrom wrapt import wrap_function_wrapperfrom openlit.instrumentation.ag2.ag2 import (- wrap_ag2+ conversable_agent, agent_run)_instruments = ("ag2 >= 0.3.2",)@@ -24,27 +23,27 @@ class AG2Instrumentor(BaseInstrumentor):application_name = kwargs.get("application_name", "default_application")environment = kwargs.get("environment", "default_environment")tracer = kwargs.get("tracer")+ event_provider = kwargs.get("event_provider")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("ag2")wrap_function_wrapper("autogen.agentchat.conversable_agent",- "ConversableAgent.initiate_chat",- wrap_ag2("ag2.initiate_chat", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ "ConversableAgent.__init__",+ conversable_agent(version, environment, application_name,+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("autogen.agentchat.conversable_agent",- "ConversableAgent.generate_reply",- wrap_ag2("ag2.generate_reply", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ "ConversableAgent.run",+ agent_run(version, environment, application_name,+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)-def _uninstrument(self, **kwargs):# Proper uninstrumentation logic to revert patched methodspassdiff --git a/sdk/python/src/openlit/instrumentation/ag2/ag2.py b/sdk/python/src/openlit/instrumentation/ag2/ag2.pyindex 343807a6..53834635 100644--- a/sdk/python/src/openlit/instrumentation/ag2/ag2.py+++ b/sdk/python/src/openlit/instrumentation/ag2/ag2.py@@ -1,98 +1,163 @@-# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument"""-Module for monitoring AG2.+Module for monitoring AG2 API calls."""import logging+import timefrom opentelemetry.trace import SpanKind, Status, StatusCodefrom opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT-from openlit.__helpers import handle_exception+from openlit.__helpers import (+ handle_exception,+ get_chat_model_cost,+ otel_event,+)from openlit.semcov import SemanticConvetion# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)-def wrap_ag2(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+AGENT_NAME = ''+REQUEST_MODEL = ''+SYSTEM_MESSAGE = ''+MODEL_AND_NAME_SET = False++def set_span_attributes(span, version, operation_name, environment,+ application_name, server_address, server_port, request_model):+ """+ Set common attributes for the span.+ """++ # Set Span attributes (OTel Semconv)+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ span.set_attribute(SemanticConvetion.GEN_AI_OPERATION, operation_name)+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM, SemanticConvetion.GEN_AI_SYSTEM_AG2)+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_NAME, AGENT_NAME)+ span.set_attribute(SemanticConvetion.SERVER_ADDRESS, server_address)+ span.set_attribute(SemanticConvetion.SERVER_PORT, server_port)+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL, request_model)++ # Set Span attributes (Extras)+ span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)+ span.set_attribute(SERVICE_NAME, application_name)+ span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION, version)++def calculate_tokens_and_cost(response, request_model, pricing_info):"""- Creates a wrapper around a function call to trace and log its execution metrics.-- This function wraps any given function to measure its execution time,- log its operation, and trace its execution using OpenTelemetry.-- Parameters:- - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.- - version (str): The version of the Langchain application.- - environment (str): The deployment environment (e.g., 'production', 'development').- - application_name (str): Name of the Langchain application.- - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- - pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.-- Returns:- - function: A higher-order function that takes a function 'wrapped' and returns- a new function that wraps 'wrapped' with additional tracing and logging.+ Calculate the input, output tokens, and their respective costs."""+ input_tokens = 0+ output_tokens = 0+ for usage_data in response.cost.values():+ if isinstance(usage_data, dict):+ for model_data in usage_data.values():+ if isinstance(model_data, dict):+ input_tokens += model_data.get('prompt_tokens', 0)+ output_tokens += model_data.get('completion_tokens', 0)++ cost = get_chat_model_cost(request_model, pricing_info, input_tokens, output_tokens)+ return input_tokens, output_tokens, cost++def emit_events(response, event_provider, capture_message_content):+ """+ Emit OpenTelemetry events for each chat history entry.+ """+ for chat in response.chat_history:+ event_type = (+ SemanticConvetion.GEN_AI_CHOICE if chat['role'] == 'user'+ else SemanticConvetion.GEN_AI_USER_MESSAGE+ )+ choice_event = otel_event(+ name=event_type,+ attributes={+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_AG2+ },+ body={+ "index": response.chat_history.index(chat),+ "message": {+ **({"content": chat['content']} if capture_message_content else {}),+ "role": 'assistant' if chat['role'] == 'user' else 'user'+ }+ }+ )+ event_provider.emit(choice_event)++def conversable_agent(version, environment, application_name,+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):+ """+ Generates a telemetry wrapper for GenAI function call+ """def wrapper(wrapped, instance, args, kwargs):- """- An inner wrapper function that executes the wrapped function, measures execution- time, and records trace data using OpenTelemetry.-- Parameters:- - wrapped (Callable): The original function that this wrapper will execute.- - instance (object): The instance to which the wrapped function belongs. This- is used for instance methods. For static and classmethods,- this may be None.- - args (tuple): Positional arguments passed to the wrapped function.- - kwargs (dict): Keyword arguments passed to the wrapped function.-- Returns:- - The result of the wrapped function call.-- The wrapper initiates a span with the provided tracer, sets various attributes- on the span based on the function's execution and response, and ensures- errors are handled and logged appropriately.- """-- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:- response = wrapped(*args, **kwargs)-- if isinstance(instance.__dict__.get('llm_config'), dict):- llm_model = instance.__dict__['llm_config'].get('model', 'gpt-4')- else:- # Fallback to default if 'llm_config' is not a dictionary- llm_model = None+ server_address, server_port = '127.0.0.1', 80+ global AGENT_NAME, MODEL_AND_NAME_SET, REQUEST_MODEL, SYSTEM_MESSAGE++ if not MODEL_AND_NAME_SET:+ AGENT_NAME = kwargs.get("name", "NOT_FOUND")+ REQUEST_MODEL = kwargs.get("llm_config", {}).get('model', 'gpt-4o')+ SYSTEM_MESSAGE = kwargs.get('system_message', '')+ MODEL_AND_NAME_SET = True+ span_name = f"{SemanticConvetion.GEN_AI_OPERATION_TYPE_CREATE_AGENT} {AGENT_NAME}"++ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:try:- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,- gen_ai_endpoint)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AG2)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)- span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,- instance.name)- if llm_model:- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- llm_model)+ start_time = time.time()+ response = wrapped(*args, **kwargs)+ end_time = time.time()+ set_span_attributes(span, version, SemanticConvetion.GEN_AI_OPERATION_TYPE_CREATE_AGENT,+ environment, application_name, server_address, server_port, REQUEST_MODEL)+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_DESCRIPTION, SYSTEM_MESSAGE)+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL, REQUEST_MODEL)+ span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT, end_time - start_time)span.set_status(Status(StatusCode.OK))- # Return original responsereturn responseexcept Exception as e:handle_exception(span, e)logger.error("Error in trace creation: %s", e)+ return response++ return wrapper++def agent_run(version, environment, application_name,+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):+ """+ Generates a telemetry wrapper for GenAI function call+ """+ def wrapper(wrapped, instance, args, kwargs):+ server_address, server_port = '127.0.0.1', 80++ span_name = f"{SemanticConvetion.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK} {AGENT_NAME}"++ with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:+ try:+ start_time = time.time()+ response = wrapped(*args, **kwargs)+ end_time = time.time()++ input_tokens, output_tokens, cost = calculate_tokens_and_cost(response, REQUEST_MODEL, pricing_info)+ response_model = list(response.cost.get('usage_including_cached_inference', {}).keys())[1]++ set_span_attributes(span, version, SemanticConvetion.GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK,+ environment, application_name, server_address, server_port, REQUEST_MODEL)+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL, response_model)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_CLIENT_TOKEN_USAGE, input_tokens + output_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)+ span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT, end_time - start_time)++ emit_events(response, event_provider, capture_message_content)+ span.set_status(Status(StatusCode.OK))++ return response- # Return original response+ except Exception as e:+ handle_exception(span, e)+ logger.error("Error in trace creation: %s", e)return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/ai21/__init__.py b/sdk/python/src/openlit/instrumentation/ai21/__init__.pyindex 97099bbe..9606edc5 100644--- a/sdk/python/src/openlit/instrumentation/ai21/__init__.py+++ b/sdk/python/src/openlit/instrumentation/ai21/__init__.py@@ -27,9 +27,10 @@ class AI21Instrumentor(BaseInstrumentor):application_name = kwargs.get("application_name", "default_application")environment = kwargs.get("environment", "default_environment")tracer = kwargs.get("tracer")+ event_provider = kwargs.get("event_provider")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("ai21")@@ -38,13 +39,13 @@ class AI21Instrumentor(BaseInstrumentor):"ai21.clients.studio.resources.chat.chat_completions","ChatCompletions.create",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("ai21.clients.studio.resources.studio_conversational_rag","StudioConversationalRag.create",chat_rag(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)#Async@@ -52,13 +53,13 @@ class AI21Instrumentor(BaseInstrumentor):"ai21.clients.studio.resources.chat.async_chat_completions","AsyncChatCompletions.create",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("ai21.clients.studio.resources.studio_conversational_rag","AsyncStudioConversationalRag.create",async_chat_rag(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/ai21/ai21.py b/sdk/python/src/openlit/instrumentation/ai21/ai21.pyindex d35a5739..16b7642f 100644--- a/sdk/python/src/openlit/instrumentation/ai21/ai21.py+++ b/sdk/python/src/openlit/instrumentation/ai21/ai21.py@@ -4,55 +4,40 @@ Module for monitoring AI21 calls.import loggingimport time-from opentelemetry.trace import SpanKind, Status, StatusCode-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import SpanKindfrom openlit.__helpers import (- get_chat_model_cost,handle_exception,response_as_dict,- calculate_ttft,- calculate_tbt,- create_metrics_attributes,set_server_address_and_port,- general_tokens)+from openlit.instrumentation.ai21.utils import (+ process_chunk,+ process_chat_response,+ process_streaming_chat_response,+ process_chat_rag_response+)+from openlit.semcov import SemanticConvetion# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)def chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the AI21 SDK.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of AI21 usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""class TracedSyncStream:"""- Wrapper for streaming responses to collect metrics and trace data.- Wraps the response to collect message IDs and aggregated response.-- This class implements the '__aiter__' and '__anext__' methods that- handle asynchronous streaming responses.-- This class also implements '__aenter__' and '__aexit__' methods that- handle asynchronous context management protocol.+ Wrapper for streaming responses to collect telemetry."""+def __init__(self,wrapped,span,+ span_name,kwargs,server_address,server_port,@@ -60,12 +45,14 @@ def chat(version, environment, application_name,):self.__wrapped__ = wrappedself._span = span+ self._span_name = span_name# Placeholder for aggregating streaming responseself._llmresponse = ""self._response_id = ""self._finish_reason = ""self._input_tokens = 0self._output_tokens = 0+ self._choices = []self._args = argsself._kwargs = kwargs@@ -94,192 +81,36 @@ def chat(version, environment, application_name,def __next__(self):try:chunk = self.__wrapped__.__next__()- end_time = time.time()- # Record the timestamp for the current chunk- self._timestamps.append(end_time)-- if len(self._timestamps) == 1:- # Calculate time to first chunk- self._ttft = calculate_ttft(self._timestamps, self._start_time)-- chunked = response_as_dict(chunk)- if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and- 'content' in chunked.get('choices')[0].get('delta'))):-- content = chunked.get('choices')[0].get('delta').get('content')- if content:- self._llmresponse += content-- if chunked.get('usage'):- self._input_tokens = chunked.get('usage').get("prompt_tokens")- self._output_tokens = chunked.get('usage').get("completion_tokens")-- self._response_id = chunked.get('id')- self._finish_reason = chunked.get('choices')[0].get('finish_reason')+ process_chunk(self, chunk)return chunkexcept StopIteration:# Handling exception ensure observability without disrupting operationtry:- self._end_time = time.time()- if len(self._timestamps) > 1:- self._tbt = calculate_tbt(self._timestamps)-- # Format 'messages' into a single string- message_prompt = self._kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- request_model = self._kwargs.get("model", "jamba-1.5-mini")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, self._input_tokens,- self._output_tokens)-- # Set Span attributes (OTel Semconv)- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- self._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- self._kwargs.get("seed", ""))- self._span.set_attribute(SemanticConvetion.SERVER_PORT,- self._server_port)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- self._kwargs.get("frequency_penalty", 0.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- self._kwargs.get("max_tokens", -1))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- self._kwargs.get("presence_penalty", 0.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- self._kwargs.get("stop", []))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- self._kwargs.get("temperature", 0.4))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- self._kwargs.get("top_p", 1.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [self._finish_reason])- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- self._response_id)- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- self._input_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- self._output_tokens)- self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- self._server_address)-- if isinstance(self._llmresponse, str):- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- else:- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Set Span attributes (Extra)- self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- self._span.set_attribute(SERVICE_NAME,- application_name)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- True)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- self._input_tokens + self._output_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT,- self._tbt)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- self._ttft)- self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,- },+ with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version)- self._span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=self._server_address,- server_port=self._server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- self._input_tokens + self._output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- self._end_time - self._start_time, attributes- )- metrics["genai_server_tbt"].record(- self._tbt, attributes- )- metrics["genai_server_ttft"].record(- self._ttft, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(self._output_tokens, attributes)- metrics["genai_prompt_tokens"].add(self._input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-except Exception as e:handle_exception(self._span, e)logger.error("Error in trace creation: %s", e)- finally:- self._span.end()raisedef wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""# Check if streaming is enabled for the API callstreaming = kwargs.get("stream", False)+server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)request_model = kwargs.get("model", "jamba-1.5-mini")@@ -290,197 +121,44 @@ def chat(version, environment, application_name,# Special handling for streaming response to accommodate the nature of data flowawaited_wrapped = wrapped(*args, **kwargs)span = tracer.start_span(span_name, kind=SpanKind.CLIENT)-- return TracedSyncStream(awaited_wrapped, span, kwargs, server_address, server_port)+ return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)# Handling for non-streaming responseselse:with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = response_dict.get('usage').get('prompt_tokens')- output_tokens = response_dict.get('usage').get('completion_tokens')-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- kwargs.get("seed", ""))- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- kwargs.get("frequency_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- kwargs.get("max_tokens", -1))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- kwargs.get("presence_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- kwargs.get("stop", []))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- kwargs.get("temperature", 0.4))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- kwargs.get("top_p", 1.0))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- response_dict.get("id"))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )-- for i in range(kwargs.get('n',1)):- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [response_dict.get('choices')[i].get('finish_reason')])- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('choices')[i].get('message').get('tool_calls')))-- if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- elif response_dict.get('choices')[i].get('message').get('content') is not None:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_response(+ response=response_as_dict(response),+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdef chat_rag(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the AI21 SDK.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of AI21 usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)@@ -491,165 +169,24 @@ def chat_rag(version, environment, application_name,with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = general_tokens(prompt)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- kwargs.get("seed", ""))- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- kwargs.get("frequency_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- kwargs.get("max_tokens", -1))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- kwargs.get("presence_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- kwargs.get("stop", []))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- kwargs.get("temperature", 0.4))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- kwargs.get("top_p", 1.0))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- response_dict.get("id"))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- span.set_attribute(SemanticConvetion.GEN_AI_RAG_MAX_SEGMENTS,- kwargs.get("max_segments", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_STRATEGY,- kwargs.get("retrieval_strategy", "segments"))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_SIMILARITY_THRESHOLD,- kwargs.get("retrieval_similarity_threshold", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_MAX_NEIGHBORS,- kwargs.get("max_neighbors", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_FILE_IDS,- str(kwargs.get("file_ids", "")))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_DOCUMENTS_PATH,- kwargs.get("path", ""))- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )-- output_tokens = 0- for i in range(kwargs.get('n',1)):- output_tokens += general_tokens(response_dict.get('choices')[i].get('content'))-- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('choices')[i].get('message').get('tool_calls')))-- if isinstance(response_dict.get('choices')[i].get('content'), str):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- elif response_dict.get('choices')[i].get('content') is not None:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_rag_response(+ response=response_as_dict(response),+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/ai21/async_ai21.py b/sdk/python/src/openlit/instrumentation/ai21/async_ai21.pyindex 5f471280..11359aa8 100644--- a/sdk/python/src/openlit/instrumentation/ai21/async_ai21.py+++ b/sdk/python/src/openlit/instrumentation/ai21/async_ai21.py@@ -4,55 +4,40 @@ Module for monitoring AI21 calls.import loggingimport time-from opentelemetry.trace import SpanKind, Status, StatusCode-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import SpanKindfrom openlit.__helpers import (- get_chat_model_cost,handle_exception,response_as_dict,- calculate_ttft,- calculate_tbt,- create_metrics_attributes,set_server_address_and_port,- general_tokens)+from openlit.instrumentation.ai21.utils import (+ process_chunk,+ process_chat_response,+ process_streaming_chat_response,+ process_chat_rag_response+)+from openlit.semcov import SemanticConvetion# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)def async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the AI21 SDK.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of AI21 usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""class TracedAsyncStream:"""- Wrapper for streaming responses to collect metrics and trace data.- Wraps the response to collect message IDs and aggregated response.-- This class implements the '__aiter__' and '__anext__' methods that- handle asynchronous streaming responses.-- This class also implements '__aenter__' and '__aexit__' methods that- handle asynchronous context management protocol.+ Wrapper for streaming responses to collect telemetry."""+def __init__(self,wrapped,span,+ span_name,kwargs,server_address,server_port,@@ -60,12 +45,14 @@ def async_chat(version, environment, application_name,):self.__wrapped__ = wrappedself._span = span+ self._span_name = span_name# Placeholder for aggregating streaming responseself._llmresponse = ""self._response_id = ""self._finish_reason = ""self._input_tokens = 0self._output_tokens = 0+ self._choices = []self._args = argsself._kwargs = kwargs@@ -94,192 +81,36 @@ def async_chat(version, environment, application_name,async def __anext__(self):try:chunk = await self.__wrapped__.__anext__()- end_time = time.time()- # Record the timestamp for the current chunk- self._timestamps.append(end_time)-- if len(self._timestamps) == 1:- # Calculate time to first chunk- self._ttft = calculate_ttft(self._timestamps, self._start_time)-- chunked = response_as_dict(chunk)- if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and- 'content' in chunked.get('choices')[0].get('delta'))):-- content = chunked.get('choices')[0].get('delta').get('content')- if content:- self._llmresponse += content-- if chunked.get('usage'):- self._input_tokens = chunked.get('usage').get("prompt_tokens")- self._output_tokens = chunked.get('usage').get("completion_tokens")-- self._response_id = chunked.get('id')- self._finish_reason = chunked.get('choices')[0].get('finish_reason')+ process_chunk(self, chunk)return chunkexcept StopAsyncIteration:# Handling exception ensure observability without disrupting operationtry:- self._end_time = time.time()- if len(self._timestamps) > 1:- self._tbt = calculate_tbt(self._timestamps)-- # Format 'messages' into a single string- message_prompt = self._kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- request_model = self._kwargs.get("model", "jamba-1.5-mini")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, self._input_tokens,- self._output_tokens)-- # Set Span attributes (OTel Semconv)- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- self._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- self._kwargs.get("seed", ""))- self._span.set_attribute(SemanticConvetion.SERVER_PORT,- self._server_port)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- self._kwargs.get("frequency_penalty", 0.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- self._kwargs.get("max_tokens", -1))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- self._kwargs.get("presence_penalty", 0.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- self._kwargs.get("stop", []))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- self._kwargs.get("temperature", 0.4))- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- self._kwargs.get("top_p", 1.0))- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [self._finish_reason])- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- self._response_id)- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- self._input_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- self._output_tokens)- self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- self._server_address)-- if isinstance(self._llmresponse, str):- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- else:- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Set Span attributes (Extra)- self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- self._span.set_attribute(SERVICE_NAME,- application_name)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- True)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- self._input_tokens + self._output_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT,- self._tbt)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- self._ttft)- self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,- },+ with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version)- self._span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=self._server_address,- server_port=self._server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- self._input_tokens + self._output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- self._end_time - self._start_time, attributes- )- metrics["genai_server_tbt"].record(- self._tbt, attributes- )- metrics["genai_server_ttft"].record(- self._ttft, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(self._output_tokens, attributes)- metrics["genai_prompt_tokens"].add(self._input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-except Exception as e:handle_exception(self._span, e)logger.error("Error in trace creation: %s", e)- finally:- self._span.end()raiseasync def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""# Check if streaming is enabled for the API callstreaming = kwargs.get("stream", False)+server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)request_model = kwargs.get("model", "jamba-1.5-mini")@@ -290,197 +121,44 @@ def async_chat(version, environment, application_name,# Special handling for streaming response to accommodate the nature of data flowawaited_wrapped = await wrapped(*args, **kwargs)span = tracer.start_span(span_name, kind=SpanKind.CLIENT)-- return TracedAsyncStream(awaited_wrapped, span, kwargs, server_address, server_port)+ return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)# Handling for non-streaming responseselse:with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = await wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = response_dict.get('usage').get('prompt_tokens')- output_tokens = response_dict.get('usage').get('completion_tokens')-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- kwargs.get("seed", ""))- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- kwargs.get("frequency_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- kwargs.get("max_tokens", -1))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- kwargs.get("presence_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- kwargs.get("stop", []))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- kwargs.get("temperature", 0.4))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- kwargs.get("top_p", 1.0))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- response_dict.get("id"))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )-- for i in range(kwargs.get('n',1)):- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [response_dict.get('choices')[i].get('finish_reason')])- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('choices')[i].get('message').get('tool_calls')))-- if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- elif response_dict.get('choices')[i].get('message').get('content') is not None:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_response(+ response=response_as_dict(response),+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdef async_chat_rag(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the AI21 SDK.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of AI21 usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""async def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)@@ -491,165 +169,24 @@ def async_chat_rag(version, environment, application_name,with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = await wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message.role- content = message.content-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = general_tokens(prompt)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_AI21)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,- kwargs.get("seed", ""))- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,- kwargs.get("frequency_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,- kwargs.get("max_tokens", -1))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,- kwargs.get("presence_penalty", 0.0))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES,- kwargs.get("stop", []))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,- kwargs.get("temperature", 0.4))- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,- kwargs.get("top_p", 1.0))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,- response_dict.get("id"))- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- span.set_attribute(SemanticConvetion.GEN_AI_RAG_MAX_SEGMENTS,- kwargs.get("max_segments", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_STRATEGY,- kwargs.get("retrieval_strategy", "segments"))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_SIMILARITY_THRESHOLD,- kwargs.get("retrieval_similarity_threshold", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_MAX_NEIGHBORS,- kwargs.get("max_neighbors", -1))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_FILE_IDS,- str(kwargs.get("file_ids", "")))- span.set_attribute(SemanticConvetion.GEN_AI_RAG_DOCUMENTS_PATH,- kwargs.get("path", ""))- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )-- output_tokens = 0- for i in range(kwargs.get('n',1)):- output_tokens += general_tokens(response_dict.get('choices')[i].get('content'))-- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('choices')[i].get('message').get('tool_calls')))-- if isinstance(response_dict.get('choices')[i].get('content'), str):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- elif response_dict.get('choices')[i].get('content') is not None:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_AI21,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_rag_response(+ response=response_as_dict(response),+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/ai21/utils.py b/sdk/python/src/openlit/instrumentation/ai21/utils.pynew file mode 100644index 00000000..35cb9d24--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/ai21/utils.py@@ -0,0 +1,407 @@+"""+AI21 OpenTelemetry instrumentation utility functions+"""++import time++from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import Status, StatusCode++from openlit.__helpers import (+ calculate_ttft,+ response_as_dict,+ calculate_tbt,+ general_tokens,+ extract_and_format_input,+ get_chat_model_cost,+ handle_exception,+ create_metrics_attributes,+ otel_event,+ concatenate_all_contents+)+from openlit.semcov import SemanticConvetion++def setup_common_span_attributes(span, request_model, kwargs, tokens,+ server_port, server_address, environment,+ application_name, extra_attrs):+ """+ Set common span attributes for both chat and RAG operations.+ """++ # Base attributes from SDK and operation settings.+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ span.set_attribute(SemanticConvetion.GEN_AI_OPERATION, SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM, SemanticConvetion.GEN_AI_SYSTEM_AI21)+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL, request_model)+ span.set_attribute(SemanticConvetion.SERVER_PORT, server_port)+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED, kwargs.get("seed", ""))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, kwargs.get("frequency_penalty", 0.0))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, kwargs.get("max_tokens", -1))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY, kwargs.get("presence_penalty", 0.0))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, kwargs.get("stop", []))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, kwargs.get("temperature", 0.4))+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P, kwargs.get("top_p", 1.0))++ # Add token-related attributes if available.+ if "finish_reason" in tokens:+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON, [tokens["finish_reason"]])+ if "response_id" in tokens:+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID, tokens["response_id"])+ if "input_tokens" in tokens:+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS, tokens["input_tokens"])+ if "output_tokens" in tokens:+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS, tokens["output_tokens"])+ if "total_tokens" in tokens:+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS, tokens["total_tokens"])++ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL, request_model)+ span.set_attribute(SemanticConvetion.SERVER_ADDRESS, server_address)+ # Environment and service identifiers.+ span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)+ span.set_attribute(SERVICE_NAME, application_name)+ # Set any extra attributes passed in.+ for key, value in extra_attrs.items():+ span.set_attribute(key, value)++def record_common_metrics(metrics, application_name, environment, request_model,+ server_address, server_port, start_time, end_time,+ input_tokens, output_tokens, cost, include_tbt=False, tbt_value=None):+ """+ Record common metrics for the operation.+ """++ attributes = create_metrics_attributes(+ service_name=application_name,+ deployment_environment=environment,+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,+ system=SemanticConvetion.GEN_AI_SYSTEM_AI21,+ request_model=request_model,+ server_address=server_address,+ server_port=server_port,+ response_model=request_model,+ )+ metrics["genai_client_usage_tokens"].record(input_tokens + output_tokens, attributes)+ metrics["genai_client_operation_duration"].record(end_time - start_time, attributes)+ if include_tbt and tbt_value is not None:+ metrics["genai_server_tbt"].record(tbt_value, attributes)+ metrics["genai_server_ttft"].record(end_time - start_time, attributes)+ metrics["genai_requests"].add(1, attributes)+ metrics["genai_completion_tokens"].add(output_tokens, attributes)+ metrics["genai_prompt_tokens"].add(input_tokens, attributes)+ metrics["genai_cost"].record(cost, attributes)++def emit_common_events(event_provider, choices, finish_reason, llmresponse, formatted_messages,+ capture_message_content, n):+ """+ Emit events common to both chat and chat rag operations.+ """++ if n > 1:+ for choice in choices:+ choice_event_body = {+ "finish_reason": finish_reason,+ "index": choice.get('index', 0),+ "message": {+ **({"content": choice.get('message', {}).get('content', '')} if capture_message_content else {}),+ "role": choice.get('message', {}).get('role', 'assistant')+ }+ }+ # If tool calls exist, emit an event for each tool call.+ tool_calls = choice.get('message', {}).get('tool_calls')+ if tool_calls:+ for tool_call in tool_calls:+ choice_event_body["message"].update({+ "tool_calls": {+ "function": {+ "name": tool_call.get('function', {}).get('name', ''),+ "arguments": tool_call.get('function', {}).get('arguments', '')+ },+ "id": tool_call.get('id', ''),+ "type": tool_call.get('type', 'function')+ }+ })+ event = otel_event(+ name=SemanticConvetion.GEN_AI_CHOICE,+ attributes={SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_AI21},+ body=choice_event_body+ )+ event_provider.emit(event)+ else:+ event = otel_event(+ name=SemanticConvetion.GEN_AI_CHOICE,+ attributes={SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_AI21},+ body=choice_event_body+ )+ event_provider.emit(event)+ else:+ # Single choice case.+ choice_event_body = {+ "finish_reason": finish_reason,+ "index": 0,+ "message": {+ **({"content": llmresponse} if capture_message_content else {}),+ "role": 'assistant'+ }+ }+ event = otel_event(+ name=SemanticConvetion.GEN_AI_CHOICE,+ attributes={SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_AI21},+ body=choice_event_body+ )+ event_provider.emit(event)++ # Emit additional role-based events (if formatted messages are available).+ for role in ['user', 'system', 'assistant', 'tool']:+ msg = formatted_messages.get(role, {})+ if msg.get('content', ''):+ event_body = {+ **({"content": msg.get('content', '')} if capture_message_content else {}),+ "role": msg.get('role', [])+ }+ # For assistant messages, attach tool call details if they exist.+ if role == 'assistant' and choices:+ tool_calls = choices[0].get('message', {}).get('tool_calls', [])+ if tool_calls:+ event_body["tool_calls"] = {+ "function": {+ "name": tool_calls[0].get('function', {}).get('name', ''),+ "arguments": tool_calls[0].get('function', {}).get('arguments', '')+ },+ "id": tool_calls[0].get('id', ''),+ "type": "function"+ }+ if role == 'tool' and choices:+ tool_calls = choices[0].get('message', {}).get('tool_calls', [])+ if tool_calls:+ event_body["id"] = tool_calls[0].get('id', '')+ event = otel_event(+ name=getattr(SemanticConvetion, f'GEN_AI_{role.upper()}_MESSAGE'),+ attributes={SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_AI21},+ body=event_body+ )+ event_provider.emit(event)++def process_chunk(self, chunk):+ """+ Process a chunk of response data and update state.+ """++ end_time = time.time()+ # Record the timestamp for the current chunk.+ self._timestamps.append(end_time)+ if len(self._timestamps) == 1:+ # Calculate time-to-first-chunk (TTFT).+ self._ttft = calculate_ttft(self._timestamps, self._start_time)++ chunked = response_as_dict(chunk)+ if (len(chunked.get('choices')) > 0 and+ 'delta' in chunked.get('choices')[0] and+ 'content' in chunked.get('choices')[0].get('delta')):+ content = chunked.get('choices')[0].get('delta').get('content')+ if content:+ self._llmresponse += content+ if chunked.get('usage'):+ self._input_tokens = chunked.get('usage').get("prompt_tokens")+ self._output_tokens = chunked.get('usage').get("completion_tokens")+ self._response_id = chunked.get('id')+ self._choices += chunked.get('choices')+ self._finish_reason = chunked.get('choices')[0].get('finish_reason')++def common_chat_logic(scope, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream):+ """+ Process chat request and generate Telemetry.+ """++ scope._end_time = time.time()+ if len(scope._timestamps) > 1:+ scope._tbt = calculate_tbt(scope._timestamps)++ # Extract and format input messages.+ formatted_messages = extract_and_format_input(scope._kwargs.get("messages", ""))+ prompt = concatenate_all_contents(formatted_messages)+ request_model = scope._kwargs.get("model", "jamba-1.5-mini")++ # Calculate cost based on token usage.+ cost = get_chat_model_cost(request_model, pricing_info, scope._input_tokens, scope._output_tokens)+ # Prepare tokens dictionary.+ tokens = {+ "finish_reason": scope._finish_reason,+ "response_id": scope._response_id,+ "input_tokens": scope._input_tokens,+ "output_tokens": scope._output_tokens,+ "total_tokens": scope._input_tokens + scope._output_tokens,+ }+ extra_attrs = {+ SemanticConvetion.GEN_AI_REQUEST_IS_STREAM: is_stream,+ SemanticConvetion.GEN_AI_CLIENT_TOKEN_USAGE: scope._input_tokens + scope._output_tokens,+ SemanticConvetion.GEN_AI_USAGE_COST: cost,+ SemanticConvetion.GEN_AI_SERVER_TBT: scope._tbt,+ SemanticConvetion.GEN_AI_SERVER_TTFT: scope._ttft,+ SemanticConvetion.GEN_AI_SDK_VERSION: version,+ SemanticConvetion.GEN_AI_OUTPUT_TYPE: "text" if isinstance(scope._llmresponse, str) else "json"+ }+ # Set span attributes.+ setup_common_span_attributes(scope._span, request_model, scope._kwargs, tokens,+ scope._server_port, scope._server_address, environment,+ application_name, extra_attrs)++ # Optionally add events capturing the prompt and completion.+ if capture_message_content:+ scope._span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt},+ )+ scope._span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={SemanticConvetion.GEN_AI_CONTENT_COMPLETION: scope._llmresponse},+ )++ # Emit events for each choice and message role.+ n = scope._kwargs.get('n', 1)+ emit_common_events(event_provider, scope._choices, scope._finish_reason, scope._llmresponse,+ formatted_messages, capture_message_content, n)++ scope._span.set_status(Status(StatusCode.OK))++ if not disable_metrics:+ record_common_metrics(metrics, application_name, environment, request_model,+ scope._server_address, scope._server_port,+ scope._start_time, scope._end_time,+ scope._input_tokens, scope._output_tokens, cost,+ include_tbt=True, tbt_value=scope._tbt)++def process_streaming_chat_response(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content=False, disable_metrics=False, version=''):+ """+ Process a streaming chat response and generate Telemetry.+ """++ common_chat_logic(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream=True)++def process_chat_response(response, request_model, pricing_info, server_port, server_address,+ environment, application_name, metrics, event_provider, start_time,+ span, capture_message_content=False, disable_metrics=False, version="1.0.0", **kwargs):+ """+ Process a synchronous chat response and generate Telemetry.+ """++ # Create a generic scope object to hold telemetry data.+ self = type('GenericScope', (), {})()++ # pylint: disable = no-member+ self._start_time = start_time+ self._end_time = time.time()++ self._span = span+ # Concatenate content from all choices.+ self._llmresponse = ''.join(+ (choice.get('message', {}).get('content') or '')+ for choice in response.get('choices', [])+ )+ self._response_role = response.get('message', {}).get('role', 'assistant')+ self._input_tokens = response.get('usage', {}).get('prompt_tokens', 0)+ self._output_tokens = response.get('usage', {}).get('completion_tokens', 0)+ self._response_id = response.get('id', '')+ self._response_model = request_model+ self._finish_reason = response.get('choices', [{}])[0].get('finish_reason')+ self._timestamps = []+ self._ttft, self._tbt = self._end_time - self._start_time, 0+ self._server_address, self._server_port = server_address, server_port+ self._kwargs = kwargs+ self._choices = response.get('choices')++ common_chat_logic(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream=False)++ return response++def process_chat_rag_response(response, request_model, pricing_info, server_port, server_address,+ environment, application_name, metrics, event_provider, start_time,+ span, capture_message_content=False, disable_metrics=False, version="1.0.0", **kwargs):+ """+ Process a chat response and generate Telemetry.+ """+ end_time = time.time()+ try:+ # Format input messages into a single prompt string.+ messages_input = kwargs.get("messages", "")+ formatted_messages = extract_and_format_input(messages_input)+ prompt = concatenate_all_contents(formatted_messages)+ input_tokens = general_tokens(prompt)++ # Create tokens dict and RAG-specific extra attributes.+ tokens = {"response_id": response.get("id"), "input_tokens": input_tokens}+ extra_attrs = {+ SemanticConvetion.GEN_AI_REQUEST_IS_STREAM: False,+ SemanticConvetion.GEN_AI_SERVER_TTFT: end_time - start_time,+ SemanticConvetion.GEN_AI_SDK_VERSION: version,+ SemanticConvetion.GEN_AI_RAG_MAX_SEGMENTS: kwargs.get("max_segments", -1),+ SemanticConvetion.GEN_AI_RAG_STRATEGY: kwargs.get("retrieval_strategy", "segments"),+ SemanticConvetion.GEN_AI_RAG_SIMILARITY_THRESHOLD: kwargs.get("retrieval_similarity_threshold", -1),+ SemanticConvetion.GEN_AI_RAG_MAX_NEIGHBORS: kwargs.get("max_neighbors", -1),+ SemanticConvetion.GEN_AI_RAG_FILE_IDS: str(kwargs.get("file_ids", "")),+ SemanticConvetion.GEN_AI_RAG_DOCUMENTS_PATH: kwargs.get("path", "")+ }+ # Set common span attributes.+ setup_common_span_attributes(span, request_model, kwargs, tokens,+ server_port, server_address, environment, application_name,+ extra_attrs)++ # Record the prompt event if requested.+ if capture_message_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt},+ )++ output_tokens = 0+ choices = response.get('choices', [])+ # Instead of adding a separate event per choice, we aggregate all completion content.+ aggregated_completion = []+ for i in range(kwargs.get('n', 1)):+ # Get the response content from each choice and count tokens.+ content = choices[i].get('content', '')+ aggregated_completion.append(content)+ output_tokens += general_tokens(content)+ if kwargs.get('tools'):+ span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,+ str(choices[i].get('message', {}).get('tool_calls')))+ # Set output type based on actual content type.+ if isinstance(content, str):+ span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE, "text")+ elif content is not None:+ span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE, "json")++ # Concatenate completion responses.+ llmresponse = ''.join(aggregated_completion)+ tokens["output_tokens"] = output_tokens+ tokens["total_tokens"] = input_tokens + output_tokens++ cost = get_chat_model_cost(request_model, pricing_info, input_tokens, output_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS, input_tokens + output_tokens)++ span.set_status(Status(StatusCode.OK))+ # Emit a single aggregated completion event.+ if capture_message_content:+ span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse},+ )+ # Emit the rest of the events (choice and role-based events) as before.+ n = kwargs.get('n', 1)+ emit_common_events(event_provider, choices, choices[0].get('finish_reason', ''),+ llmresponse, formatted_messages, capture_message_content, n)++ if not disable_metrics:+ record_common_metrics(metrics, application_name, environment, request_model,+ server_address, server_port, start_time, end_time,+ input_tokens, output_tokens, cost, include_tbt=False)+ return response++ except Exception as e:+ handle_exception(span, e)+ return responsediff --git a/sdk/python/src/openlit/instrumentation/anthropic/__init__.py b/sdk/python/src/openlit/instrumentation/anthropic/__init__.pyindex 4079cba6..dd3b7091 100644--- a/sdk/python/src/openlit/instrumentation/anthropic/__init__.py+++ b/sdk/python/src/openlit/instrumentation/anthropic/__init__.py@@ -25,7 +25,7 @@ class AnthropicInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("anthropic")@@ -34,7 +34,7 @@ class AnthropicInstrumentor(BaseInstrumentor):"anthropic.resources.messages","Messages.create",messages(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)#async@@ -42,7 +42,7 @@ class AnthropicInstrumentor(BaseInstrumentor):"anthropic.resources.messages","AsyncMessages.create",async_messages(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py b/sdk/python/src/openlit/instrumentation/anthropic/anthropic.pyindex 27c0d5ba..ebdfbf1c 100644--- a/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py+++ b/sdk/python/src/openlit/instrumentation/anthropic/anthropic.py@@ -21,7 +21,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def messages(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for messages to collect metrics.@@ -31,7 +31,7 @@ def messages(version, environment, application_name, tracer,application_name: Name of the application using the Anthropic API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Anthropic usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -211,7 +211,7 @@ def messages(version, environment, application_name, tracer,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -386,7 +386,7 @@ def messages(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py b/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.pyindex a9bfb1ec..bc960d69 100644--- a/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py+++ b/sdk/python/src/openlit/instrumentation/anthropic/async_anthropic.py@@ -21,7 +21,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_messages(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for messages to collect metrics.@@ -31,7 +31,7 @@ def async_messages(version, environment, application_name, tracer,application_name: Name of the application using the Anthropic API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Anthropic usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -211,7 +211,7 @@ def async_messages(version, environment, application_name, tracer,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -386,7 +386,7 @@ def async_messages(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py b/sdk/python/src/openlit/instrumentation/assemblyai/__init__.pyindex 2280414f..8f3c25d7 100644--- a/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py@@ -26,7 +26,7 @@ class AssemblyAIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("assemblyai")@@ -35,7 +35,7 @@ class AssemblyAIInstrumentor(BaseInstrumentor):"assemblyai.transcriber","Transcriber.transcribe",transcribe(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py b/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.pyindex 62db15c0..aabcce39 100644--- a/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py+++ b/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def transcribe(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating speech audio to collect metrics.@@ -29,7 +29,7 @@ def transcribe(version, environment, application_name,application_name: Name of the application using the Assembly AI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating speech audio.- trace_content: Flag indicating whether to trace the input text and generated audio.+ capture_message_content: Flag indicating whether to trace the input text and generated audio.Returns:A function that wraps the speech audio creation method to add telemetry.@@ -96,7 +96,7 @@ def transcribe(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/astra/__init__.py b/sdk/python/src/openlit/instrumentation/astra/__init__.pyindex 098eccd8..ccfde74d 100644--- a/sdk/python/src/openlit/instrumentation/astra/__init__.py+++ b/sdk/python/src/openlit/instrumentation/astra/__init__.py@@ -22,7 +22,7 @@ class AstraInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("astrapy")@@ -31,73 +31,73 @@ class AstraInstrumentor(BaseInstrumentor):"astrapy.database","Database.create_collection",general_wrap("astra.create_collection", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.database","Database.drop_collection",general_wrap("astra.drop_collection", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.insert_one",general_wrap("astra.insert_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.insert_many",general_wrap("astra.insert_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.update_one",general_wrap("astra.update_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.update_many",general_wrap("astra.update_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.find_one_and_update",general_wrap("astra.find_one_and_update", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.find",general_wrap("astra.find", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.replace_one",general_wrap("astra.replace_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.find_one_and_delete",general_wrap("astra.find_one_and_delete", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.delete_one",general_wrap("astra.delete_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","Collection.delete_many",general_wrap("astra.delete_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# ASync@@ -105,73 +105,73 @@ class AstraInstrumentor(BaseInstrumentor):"astrapy.database","AsyncDatabase.create_collection",general_wrap("astra.create_collection", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.database","AsyncDatabase.drop_collection",general_wrap("astra.drop_collection", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.insert_one",general_wrap("astra.insert_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.insert_many",general_wrap("astra.insert_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.update_one",general_wrap("astra.update_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.update_many",general_wrap("astra.update_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.find_one_and_update",general_wrap("astra.find_one_and_update", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.find",general_wrap("astra.find", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.replace_one",general_wrap("astra.replace_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.find_one_and_delete",general_wrap("astra.find_one_and_delete", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.delete_one",general_wrap("astra.delete_one", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("astrapy.collection","AsyncCollection.delete_many",general_wrap("astra.delete_many", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/astra/astra.py b/sdk/python/src/openlit/instrumentation/astra/astra.pyindex ca9bf226..25b22560 100644--- a/sdk/python/src/openlit/instrumentation/astra/astra.py+++ b/sdk/python/src/openlit/instrumentation/astra/astra.py@@ -20,7 +20,7 @@ def object_count(obj):return len(obj) if obj else Nonedef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Wraps a AstraDB operation to trace and log its execution metrics.@@ -37,7 +37,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): The name of the application performing the AstraDB operation.- tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.- pricing_info (dict): Information about pricing, not used in current implementation.- - trace_content (bool): A flag indicating whether the content of responses should be traced.+ - capture_message_content (bool): A flag indicating whether the content of responses should be traced.Returns:- function: A decorator function that, when applied, wraps the target function withdiff --git a/sdk/python/src/openlit/instrumentation/astra/async_astra.py b/sdk/python/src/openlit/instrumentation/astra/async_astra.pyindex 464a297f..03896060 100644--- a/sdk/python/src/openlit/instrumentation/astra/async_astra.py+++ b/sdk/python/src/openlit/instrumentation/astra/async_astra.py@@ -20,7 +20,7 @@ def object_count(obj):return len(obj) if obj else Nonedef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Wraps a AstraDB operation to trace and log its execution metrics.@@ -37,7 +37,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): The name of the application performing the AstraDB operation.- tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.- pricing_info (dict): Information about pricing, not used in current implementation.- - trace_content (bool): A flag indicating whether the content of responses should be traced.+ - capture_message_content (bool): A flag indicating whether the content of responses should be traced.Returns:- function: A decorator function that, when applied, wraps the target function withdiff --git a/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py b/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.pyindex cb499bed..165d6f29 100644--- a/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py+++ b/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py@@ -30,7 +30,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("azure-ai-inference")@@ -39,7 +39,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):"azure.ai.inference","ChatCompletionsClient.complete",complete(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync embedding@@ -47,7 +47,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):"azure.ai.inference","EmbeddingsClient.embed",embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async generate@@ -55,7 +55,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):"azure.ai.inference.aio","ChatCompletionsClient.complete",async_complete(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async embedding@@ -63,7 +63,7 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):"azure.ai.inference.aio","EmbeddingsClient.embed",async_embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py b/sdk/python/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.pyindex 7541a711..429473ed 100644--- a/sdk/python/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py+++ b/sdk/python/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py@@ -23,7 +23,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_complete(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -33,7 +33,7 @@ def async_complete(version, environment, application_name,application_name: Name of the application using the Azure AI Inference API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Azure AI Inference usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -217,7 +217,7 @@ def async_complete(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -388,7 +388,7 @@ def async_complete(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -399,7 +399,7 @@ def async_complete(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -459,7 +459,7 @@ def async_complete(version, environment, application_name,return wrapperdef async_embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -469,7 +469,7 @@ def async_embedding(version, environment, application_name,application_name: Name of the application using the Azure Inference API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Azure Inference usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -541,7 +541,7 @@ def async_embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py b/sdk/python/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.pyindex 064c3908..14578044 100644--- a/sdk/python/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py+++ b/sdk/python/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py@@ -23,7 +23,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def complete(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -33,7 +33,7 @@ def complete(version, environment, application_name,application_name: Name of the application using the Azure AI Inference API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Azure AI Inference usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -217,7 +217,7 @@ def complete(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -388,7 +388,7 @@ def complete(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -399,7 +399,7 @@ def complete(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -459,7 +459,7 @@ def complete(version, environment, application_name,return wrapperdef embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -469,7 +469,7 @@ def embedding(version, environment, application_name,application_name: Name of the application using the Azure Inference API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Azure Inference usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -541,7 +541,7 @@ def embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/bedrock/__init__.py b/sdk/python/src/openlit/instrumentation/bedrock/__init__.pyindex 71a1f1b8..d0df6f7f 100644--- a/sdk/python/src/openlit/instrumentation/bedrock/__init__.py+++ b/sdk/python/src/openlit/instrumentation/bedrock/__init__.py@@ -24,7 +24,7 @@ class BedrockInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("boto3")@@ -33,7 +33,7 @@ class BedrockInstrumentor(BaseInstrumentor):"botocore.client","ClientCreator.create_client",converse(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.pyindex 8cda881d..69f488b4 100644--- a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py+++ b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py@@ -53,7 +53,7 @@ class CustomStreamWrapper(StreamingBody):return data_chunkdef converse(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for messages to collect metrics.@@ -64,7 +64,7 @@ def converse(version, environment, application_name, tracer,application_name: Name of the application using the Bedrock API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information for calculating Bedrock usage cost.- trace_content: Whether to trace the actual content.+ capture_message_content: Whether to trace the actual content.metrics: Metrics collector.disable_metrics: Flag to toggle metrics collection.Returns:@@ -194,7 +194,7 @@ def converse(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/chroma/__init__.py b/sdk/python/src/openlit/instrumentation/chroma/__init__.pyindex 320bc861..d18f8b88 100644--- a/sdk/python/src/openlit/instrumentation/chroma/__init__.py+++ b/sdk/python/src/openlit/instrumentation/chroma/__init__.py@@ -21,7 +21,7 @@ class ChromaInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("chromadb")@@ -29,55 +29,55 @@ class ChromaInstrumentor(BaseInstrumentor):"chromadb.db","DB.create_collection",general_wrap("chroma.create_collection", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.add",general_wrap("chroma.add", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.get",general_wrap("chroma.get", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.peek",general_wrap("chroma.peek", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.query",general_wrap("chroma.query", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.update",general_wrap("chroma.update", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.upsert",general_wrap("chroma.upsert", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("chromadb","Collection.delete",general_wrap("chroma.delete", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/chroma/chroma.py b/sdk/python/src/openlit/instrumentation/chroma/chroma.pyindex 3e45600b..714ecd71 100644--- a/sdk/python/src/openlit/instrumentation/chroma/chroma.py+++ b/sdk/python/src/openlit/instrumentation/chroma/chroma.py@@ -25,7 +25,7 @@ def object_count(obj):return cntdef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -39,7 +39,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/cohere/__init__.py b/sdk/python/src/openlit/instrumentation/cohere/__init__.pyindex 89f728de..b83449ea 100644--- a/sdk/python/src/openlit/instrumentation/cohere/__init__.py+++ b/sdk/python/src/openlit/instrumentation/cohere/__init__.py@@ -23,7 +23,7 @@ class CohereInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("cohere")@@ -32,19 +32,19 @@ class CohereInstrumentor(BaseInstrumentor):"cohere.client_v2","ClientV2.chat",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("cohere.client_v2","ClientV2.chat_stream",chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("cohere.client_v2","ClientV2.embed",embed(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Async Client@@ -52,21 +52,21 @@ class CohereInstrumentor(BaseInstrumentor):"cohere.client_v2","AsyncClientV2.chat",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("cohere.client_v2","AsyncClientV2.chat_stream",async_chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("cohere.client_v2","AsyncClientV2.embed",async_embed(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/cohere/async_cohere.py b/sdk/python/src/openlit/instrumentation/cohere/async_cohere.pyindex 45d58b16..0049d75f 100644--- a/sdk/python/src/openlit/instrumentation/cohere/async_cohere.py+++ b/sdk/python/src/openlit/instrumentation/cohere/async_cohere.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_embed(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -32,7 +32,7 @@ def async_embed(version, environment, application_name, tracer,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -105,7 +105,7 @@ def async_embed(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -149,7 +149,7 @@ def async_embed(version, environment, application_name, tracer,return wrapperdef async_chat(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -159,7 +159,7 @@ def async_chat(version, environment, application_name, tracer,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -281,7 +281,7 @@ def async_chat(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -336,7 +336,7 @@ def async_chat(version, environment, application_name, tracer,return wrapperdef async_chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat_stream to collect metrics.@@ -346,7 +346,7 @@ def async_chat_stream(version, environment, application_name,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -547,7 +547,7 @@ def async_chat_stream(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/cohere/cohere.py b/sdk/python/src/openlit/instrumentation/cohere/cohere.pyindex 46c34333..a9db0dd5 100644--- a/sdk/python/src/openlit/instrumentation/cohere/cohere.py+++ b/sdk/python/src/openlit/instrumentation/cohere/cohere.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def embed(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -32,7 +32,7 @@ def embed(version, environment, application_name, tracer,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -105,7 +105,7 @@ def embed(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -149,7 +149,7 @@ def embed(version, environment, application_name, tracer,return wrapperdef chat(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -159,7 +159,7 @@ def chat(version, environment, application_name, tracer,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -281,7 +281,7 @@ def chat(version, environment, application_name, tracer,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -336,7 +336,7 @@ def chat(version, environment, application_name, tracer,return wrapperdef chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat_stream to collect metrics.@@ -346,7 +346,7 @@ def chat_stream(version, environment, application_name,application_name: Name of the application using the Cohere API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Cohere usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -547,7 +547,7 @@ def chat_stream(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/controlflow/__init__.py b/sdk/python/src/openlit/instrumentation/controlflow/__init__.pyindex 49eef1de..a7b97f7c 100644--- a/sdk/python/src/openlit/instrumentation/controlflow/__init__.py+++ b/sdk/python/src/openlit/instrumentation/controlflow/__init__.py@@ -26,7 +26,7 @@ class ControlFlowInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("controlflow")@@ -34,21 +34,21 @@ class ControlFlowInstrumentor(BaseInstrumentor):"controlflow.agents.agent","Agent.__init__",wrap_controlflow("controlflow.create_agent", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("controlflow.tasks.task","Task.__init__",wrap_controlflow("controlflow.create_task", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("controlflow","run",wrap_controlflow("controlflow.run", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py b/sdk/python/src/openlit/instrumentation/controlflow/controlflow.pyindex a6be6ac4..232ca2e8 100644--- a/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py+++ b/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def wrap_controlflow(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def wrap_controlflow(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/crawl4ai/__init__.py b/sdk/python/src/openlit/instrumentation/crawl4ai/__init__.pyindex dc1816c4..13ac1d52 100644--- a/sdk/python/src/openlit/instrumentation/crawl4ai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/crawl4ai/__init__.py@@ -29,7 +29,7 @@ class Crawl4AIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("crawl4ai")@@ -37,14 +37,14 @@ class Crawl4AIInstrumentor(BaseInstrumentor):"crawl4ai.web_crawler","WebCrawler.run",wrap_crawl("crawl4ai.web_crawl", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("crawl4ai.async_webcrawler","AsyncWebCrawler.arun",async_wrap_crawl("crawl4ai.web_crawl", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py b/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.pyindex 2e95f0d6..890e7693 100644--- a/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py+++ b/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_wrap_crawl(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def async_wrap_crawl(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the Crawl4AI Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Crawl4AI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py b/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.pyindex 3307d572..f4fe50b3 100644--- a/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py+++ b/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def wrap_crawl(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def wrap_crawl(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the Crawl4AI Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Crawl4AI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/crewai/__init__.py b/sdk/python/src/openlit/instrumentation/crewai/__init__.pyindex 83b34340..9957a81d 100644--- a/sdk/python/src/openlit/instrumentation/crewai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/crewai/__init__.py@@ -26,7 +26,7 @@ class CrewAIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("crewai")@@ -34,14 +34,14 @@ class CrewAIInstrumentor(BaseInstrumentor):"crewai.agent","Agent.execute_task",crew_wrap("crewai.agent_execute_task", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("crewai.task","Task._execute_core",crew_wrap("crewai.task_execute_core", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/crewai/crewai.py b/sdk/python/src/openlit/instrumentation/crewai/crewai.pyindex f6a1da7d..75f946ae 100644--- a/sdk/python/src/openlit/instrumentation/crewai/crewai.py+++ b/sdk/python/src/openlit/instrumentation/crewai/crewai.py@@ -28,7 +28,7 @@ def _parse_tools(tools):return json.dumps(result)def crew_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -39,7 +39,7 @@ def crew_wrap(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the CrewAI Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of CrewAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/dynamiq/__init__.py b/sdk/python/src/openlit/instrumentation/dynamiq/__init__.pyindex baee93e7..c493e94f 100644--- a/sdk/python/src/openlit/instrumentation/dynamiq/__init__.py+++ b/sdk/python/src/openlit/instrumentation/dynamiq/__init__.py@@ -26,7 +26,7 @@ class DynamiqInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("dynamiq")@@ -34,28 +34,28 @@ class DynamiqInstrumentor(BaseInstrumentor):"dynamiq.nodes.agents.base","Agent.run",dynamiq_wrap("dynamiq.agent_run", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("dynamiq","Workflow.run",dynamiq_wrap("dynamiq.workflow_run", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("dynamiq.memory","Memory.add",dynamiq_wrap("dynamiq.memory_add", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("dynamiq.memory","Memory.search",dynamiq_wrap("dynamiq.memory_search", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.pyindex 1ea74d89..c110e0e9 100644--- a/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py+++ b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the dynamiq Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of dynamiq usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py b/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.pyindex e1b9477e..ba08ed6a 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/__init__.py@@ -29,7 +29,7 @@ class ElevenLabsInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("elevenlabs")@@ -38,7 +38,7 @@ class ElevenLabsInstrumentor(BaseInstrumentor):"elevenlabs.client","ElevenLabs.generate",generate("elevenlabs.generate", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync text_to_speech.convert@@ -46,7 +46,7 @@ class ElevenLabsInstrumentor(BaseInstrumentor):"elevenlabs.text_to_speech.client","TextToSpeechClient.convert",generate("elevenlabs.text_to_speech", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async generate@@ -54,7 +54,7 @@ class ElevenLabsInstrumentor(BaseInstrumentor):"elevenlabs.client","AsyncElevenLabs.generate",async_generate("elevenlabs.generate", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync text_to_speech.convert@@ -62,7 +62,7 @@ class ElevenLabsInstrumentor(BaseInstrumentor):"elevenlabs.text_to_speech.client","AsyncTextToSpeechClient.convert",generate("elevenlabs.text_to_speech", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py b/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.pyindex 2a375d81..564fd9a7 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_generate(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating speech audio to collect metrics.@@ -28,7 +28,7 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the ElevenLabs API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating speech audio.- trace_content: Flag indicating whether to trace the input text and generated audio.+ capture_message_content: Flag indicating whether to trace the input text and generated audio.Returns:A function that wraps the speech audio creation method to add telemetry.@@ -105,7 +105,7 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,cost)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.pyindex 4dc6821a..c46ebd1d 100644--- a/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py+++ b/sdk/python/src/openlit/instrumentation/elevenlabs/elevenlabs.py@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def generate(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating speech audio to collect metrics.@@ -28,7 +28,7 @@ def generate(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the ElevenLabs API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating speech audio.- trace_content: Flag indicating whether to trace the input text and generated audio.+ capture_message_content: Flag indicating whether to trace the input text and generated audio.Returns:A function that wraps the speech audio creation method to add telemetry.@@ -106,7 +106,7 @@ def generate(gen_ai_endpoint, version, environment, application_name,cost)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/embedchain/__init__.py b/sdk/python/src/openlit/instrumentation/embedchain/__init__.pyindex 5177d286..da05f40e 100644--- a/sdk/python/src/openlit/instrumentation/embedchain/__init__.py+++ b/sdk/python/src/openlit/instrumentation/embedchain/__init__.py@@ -35,7 +35,7 @@ class EmbedChainInstrumentor(BaseInstrumentor):environment = kwargs.get("environment")tracer = kwargs.get("tracer")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")version = importlib.metadata.version("embedchain")for wrapped_method in WRAPPED_METHODS:@@ -47,7 +47,7 @@ class EmbedChainInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content),+ tracer, pricing_info, capture_message_content),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py b/sdk/python/src/openlit/instrumentation/embedchain/embedchain.pyindex b6f13530..afa1c3e8 100644--- a/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py+++ b/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def evaluate(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content):+ tracer, pricing_info, capture_message_content):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def evaluate(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the EmbedChain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -91,7 +91,7 @@ def evaluate(gen_ai_endpoint, version, environment, application_name,return wrapperdef get_data_sources(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content):+ tracer, pricing_info, capture_message_content):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -105,7 +105,7 @@ def get_data_sources(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the EmbedChain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/firecrawl/__init__.py b/sdk/python/src/openlit/instrumentation/firecrawl/__init__.pyindex bf6bf4c8..cf22a727 100644--- a/sdk/python/src/openlit/instrumentation/firecrawl/__init__.py+++ b/sdk/python/src/openlit/instrumentation/firecrawl/__init__.py@@ -26,7 +26,7 @@ class FireCrawlInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("firecrawl-py")@@ -34,14 +34,14 @@ class FireCrawlInstrumentor(BaseInstrumentor):"firecrawl.firecrawl","FirecrawlApp.scrape_url",wrap_crawl("firecrawl.scrape_url", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("firecrawl.firecrawl","FirecrawlApp.crawl_url",wrap_crawl("firecrawl.crawl_url", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py b/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.pyindex 4cbfd9c4..957ce856 100644--- a/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py+++ b/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def wrap_crawl(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def wrap_crawl(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the FireCrawl Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of FireCrawl usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/google_ai_studio/__init__.py b/sdk/python/src/openlit/instrumentation/google_ai_studio/__init__.pyindex 2219b009..3e9f8450 100644--- a/sdk/python/src/openlit/instrumentation/google_ai_studio/__init__.py+++ b/sdk/python/src/openlit/instrumentation/google_ai_studio/__init__.py@@ -30,7 +30,7 @@ class GoogleAIStudioInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("google-genai")@@ -39,7 +39,7 @@ class GoogleAIStudioInstrumentor(BaseInstrumentor):"google.genai.models","Models.generate_content",generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async generate@@ -47,7 +47,7 @@ class GoogleAIStudioInstrumentor(BaseInstrumentor):"google.genai.models","AsyncModels.generate_content",async_generate(version, environment,- application_name, tracer, pricing_info, trace_content, metrics,+ application_name, tracer, pricing_info, capture_message_content, metrics,disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py b/sdk/python/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.pyindex bb4721d4..acfe5533 100644--- a/sdk/python/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py+++ b/sdk/python/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -30,7 +30,7 @@ def async_generate(version, environment, application_name,application_name: Name of the application using the Google AI Studio API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Google AI Studio usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -165,7 +165,7 @@ def async_generate(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py b/sdk/python/src/openlit/instrumentation/google_ai_studio/google_ai_studio.pyindex 7a54b4cf..b12974e8 100644--- a/sdk/python/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py+++ b/sdk/python/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -30,7 +30,7 @@ def generate(version, environment, application_name,application_name: Name of the application using the Google AI Studio API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Google AI Studio usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -165,7 +165,7 @@ def generate(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/gpt4all/__init__.py b/sdk/python/src/openlit/instrumentation/gpt4all/__init__.pyindex 4b4ba150..1b3021d6 100644--- a/sdk/python/src/openlit/instrumentation/gpt4all/__init__.py+++ b/sdk/python/src/openlit/instrumentation/gpt4all/__init__.py@@ -26,7 +26,7 @@ class GPT4AllInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("gpt4all")@@ -35,7 +35,7 @@ class GPT4AllInstrumentor(BaseInstrumentor):"gpt4all","GPT4All.generate",generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# embed@@ -43,7 +43,7 @@ class GPT4AllInstrumentor(BaseInstrumentor):"gpt4all","Embed4All.embed",embed(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py b/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.pyindex afb166d6..824aea6f 100644--- a/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py+++ b/sdk/python/src/openlit/instrumentation/gpt4all/gpt4all.py@@ -20,7 +20,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -30,7 +30,7 @@ def generate(version, environment, application_name,application_name: Name of the application using the GPT4All API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating GPT4All usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -168,7 +168,7 @@ def generate(version, environment, application_name,version)self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,0)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -319,7 +319,7 @@ def generate(version, environment, application_name,version)span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,0)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -374,7 +374,7 @@ def generate(version, environment, application_name,return wrapperdef embed(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -384,7 +384,7 @@ def embed(version, environment, application_name,application_name: Name of the application using the GPT4All API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating GPT4All usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -452,7 +452,7 @@ def embed(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,0)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/groq/__init__.py b/sdk/python/src/openlit/instrumentation/groq/__init__.pyindex 091b154f..1605bfed 100644--- a/sdk/python/src/openlit/instrumentation/groq/__init__.py+++ b/sdk/python/src/openlit/instrumentation/groq/__init__.py@@ -25,7 +25,7 @@ class GroqInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("groq")@@ -34,7 +34,7 @@ class GroqInstrumentor(BaseInstrumentor):"groq.resources.chat.completions","Completions.create",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)#async@@ -42,7 +42,7 @@ class GroqInstrumentor(BaseInstrumentor):"groq.resources.chat.completions","AsyncCompletions.create",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/groq/async_groq.py b/sdk/python/src/openlit/instrumentation/groq/async_groq.pyindex e5c86f03..fe2bff90 100644--- a/sdk/python/src/openlit/instrumentation/groq/async_groq.py+++ b/sdk/python/src/openlit/instrumentation/groq/async_groq.py@@ -21,7 +21,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -31,7 +31,7 @@ def async_chat(version, environment, application_name,application_name: Name of the application using the Groq API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Groq usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -221,7 +221,7 @@ def async_chat(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -396,7 +396,7 @@ def async_chat(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -407,7 +407,7 @@ def async_chat(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/groq/groq.py b/sdk/python/src/openlit/instrumentation/groq/groq.pyindex c1e063ea..88f59834 100644--- a/sdk/python/src/openlit/instrumentation/groq/groq.py+++ b/sdk/python/src/openlit/instrumentation/groq/groq.py@@ -21,7 +21,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -31,7 +31,7 @@ def chat(version, environment, application_name,application_name: Name of the application using the Groq API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Groq usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -221,7 +221,7 @@ def chat(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -396,7 +396,7 @@ def chat(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -407,7 +407,7 @@ def chat(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/haystack/__init__.py b/sdk/python/src/openlit/instrumentation/haystack/__init__.pyindex 35dccfbf..3553401e 100644--- a/sdk/python/src/openlit/instrumentation/haystack/__init__.py+++ b/sdk/python/src/openlit/instrumentation/haystack/__init__.py@@ -29,7 +29,7 @@ class HaystackInstrumentor(BaseInstrumentor):environment = kwargs.get("environment")tracer = kwargs.get("tracer")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")version = importlib.metadata.version("haystack-ai")for wrapped_method in WRAPPED_METHODS:@@ -41,7 +41,7 @@ class HaystackInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content),+ tracer, pricing_info, capture_message_content),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/haystack/haystack.py b/sdk/python/src/openlit/instrumentation/haystack/haystack.pyindex b9c9f6fa..6748e656 100644--- a/sdk/python/src/openlit/instrumentation/haystack/haystack.py+++ b/sdk/python/src/openlit/instrumentation/haystack/haystack.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def join_data(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content):+ tracer, pricing_info, capture_message_content):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def join_data(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Haystack application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/julep/__init__.py b/sdk/python/src/openlit/instrumentation/julep/__init__.pyindex 6a581b9b..40d68a80 100644--- a/sdk/python/src/openlit/instrumentation/julep/__init__.py+++ b/sdk/python/src/openlit/instrumentation/julep/__init__.py@@ -30,7 +30,7 @@ class JulepInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("julep")@@ -39,19 +39,19 @@ class JulepInstrumentor(BaseInstrumentor):"julep.resources.agents.agents","AgentsResource.create",wrap_julep("julep.agents_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("julep.resources.tasks","TasksResource.create",wrap_julep("julep.task_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("julep.resources.executions.executions","ExecutionsResource.create",wrap_julep("julep.execution_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async@@ -59,19 +59,19 @@ class JulepInstrumentor(BaseInstrumentor):"julep.resources.agents.agents","AsyncAgentsResource.create",async_wrap_julep("julep.agents_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("julep.resources.tasks","AsyncTasksResource.create",async_wrap_julep("julep.task_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("julep.resources.executions.executions","AsyncExecutionsResource.create",async_wrap_julep("julep.execution_create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/julep/async_julep.py b/sdk/python/src/openlit/instrumentation/julep/async_julep.pyindex bfe98195..29b1e1eb 100644--- a/sdk/python/src/openlit/instrumentation/julep/async_julep.py+++ b/sdk/python/src/openlit/instrumentation/julep/async_julep.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -88,7 +88,7 @@ def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,elif gen_ai_endpoint == "julep.execution_create":span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ID,kwargs.get("task_id", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/julep/julep.py b/sdk/python/src/openlit/instrumentation/julep/julep.pyindex 301bf864..fae7f2de 100644--- a/sdk/python/src/openlit/instrumentation/julep/julep.py+++ b/sdk/python/src/openlit/instrumentation/julep/julep.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def wrap_julep(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def wrap_julep(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -88,7 +88,7 @@ def wrap_julep(gen_ai_endpoint, version, environment, application_name,elif gen_ai_endpoint == "julep.execution_create":span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TASK_ID,kwargs.get("task_id", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/langchain/__init__.py b/sdk/python/src/openlit/instrumentation/langchain/__init__.pyindex f4ecee85..9674f071 100644--- a/sdk/python/src/openlit/instrumentation/langchain/__init__.py+++ b/sdk/python/src/openlit/instrumentation/langchain/__init__.py@@ -96,7 +96,7 @@ class LangChainInstrumentor(BaseInstrumentor):environment = kwargs.get("environment")tracer = kwargs.get("tracer")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")metrics = kwargs.get("metrics_dict")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("langchain")@@ -110,7 +110,7 @@ class LangChainInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py b/sdk/python/src/openlit/instrumentation/langchain/async_langchain.pyindex 24f4a8f5..b40a09ce 100644--- a/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py+++ b/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py@@ -41,7 +41,7 @@ def get_attribute_from_instance_or_kwargs(instance, attribute_name, default=-1):return defaultdef async_general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -55,7 +55,7 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -114,7 +114,7 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,return wrapperdef async_hub(gen_ai_endpoint, version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around Langchain hub operations for tracing and logging.@@ -129,7 +129,7 @@ def async_hub(gen_ai_endpoint, version, environment, application_name, tracer,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer for OpenTelemetry tracing.- pricing_info (dict): Pricing information for the operation (not currently used).- - trace_content (bool): Indicates if the content of the response should be traced.+ - capture_message_content (bool): Indicates if the content of the response should be traced.Returns:- function: A new function that wraps the original hub operation call with added@@ -189,7 +189,7 @@ def async_hub(gen_ai_endpoint, version, environment, application_name, tracer,return wrapperdef async_chat(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -202,7 +202,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -287,6 +287,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,pricing_info, input_tokens, output_tokens)+ try:+ llm_response = response.content+ except AttributeError:+ llm_response = response+# Set base span attribues (OTel Semconv)span.set_attribute(TELEMETRY_SDK_NAME, "openlit")span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,@@ -328,18 +333,17 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,},)- completion_content = getattr(response, 'content', "")span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: completion_content,+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llm_response,},)diff --git a/sdk/python/src/openlit/instrumentation/langchain/langchain.py b/sdk/python/src/openlit/instrumentation/langchain/langchain.pyindex 32535bef..bdece4bb 100644--- a/sdk/python/src/openlit/instrumentation/langchain/langchain.py+++ b/sdk/python/src/openlit/instrumentation/langchain/langchain.py@@ -41,7 +41,7 @@ def get_attribute_from_instance_or_kwargs(instance, attribute_name, default=-1):return defaultdef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -55,7 +55,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -114,7 +114,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,return wrapperdef hub(gen_ai_endpoint, version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around Langchain hub operations for tracing and logging.@@ -129,7 +129,7 @@ def hub(gen_ai_endpoint, version, environment, application_name, tracer,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer for OpenTelemetry tracing.- pricing_info (dict): Pricing information for the operation (not currently used).- - trace_content (bool): Indicates if the content of the response should be traced.+ - capture_message_content (bool): Indicates if the content of the response should be traced.Returns:- function: A new function that wraps the original hub operation call with added@@ -189,7 +189,7 @@ def hub(gen_ai_endpoint, version, environment, application_name, tracer,return wrapperdef chat(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -202,7 +202,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -287,6 +287,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,pricing_info, input_tokens, output_tokens)+ try:+ llm_response = response.content+ except AttributeError:+ llm_response = response+# Set base span attribues (OTel Semconv)span.set_attribute(TELEMETRY_SDK_NAME, "openlit")span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,@@ -328,7 +333,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -338,7 +343,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llm_response,},)diff --git a/sdk/python/src/openlit/instrumentation/letta/__init__.py b/sdk/python/src/openlit/instrumentation/letta/__init__.pyindex bb416a91..47af4145 100644--- a/sdk/python/src/openlit/instrumentation/letta/__init__.py+++ b/sdk/python/src/openlit/instrumentation/letta/__init__.py@@ -26,7 +26,7 @@ class LettaInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("letta")@@ -34,42 +34,42 @@ class LettaInstrumentor(BaseInstrumentor):"letta.client.client","LocalClient.create_agent",create_agent("letta.create_agent", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("letta.client.client","LocalClient.get_agent",create_agent("letta.get_agent", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("letta.client.client","LocalClient.send_message",send_message("letta.send_message", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("letta.client.client","RESTClient.create_agent",create_agent("letta.create_agent", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("letta.client.client","RESTClient.get_agent",create_agent("letta.get_agent", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("letta.client.client","RESTClient.send_message",send_message("letta.send_message", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/letta/letta.py b/sdk/python/src/openlit/instrumentation/letta/letta.pyindex 97573126..d60830aa 100644--- a/sdk/python/src/openlit/instrumentation/letta/letta.py+++ b/sdk/python/src/openlit/instrumentation/letta/letta.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def create_agent(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def create_agent(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the Letta Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Letta usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -94,7 +94,7 @@ def create_agent(gen_ai_endpoint, version, environment, application_name,return wrapperdef send_message(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -105,7 +105,7 @@ def send_message(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the Letta Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Letta usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -158,7 +158,7 @@ def send_message(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,cost)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/litellm/__init__.py b/sdk/python/src/openlit/instrumentation/litellm/__init__.pyindex e85fa54f..47e8f085 100644--- a/sdk/python/src/openlit/instrumentation/litellm/__init__.py+++ b/sdk/python/src/openlit/instrumentation/litellm/__init__.py@@ -29,7 +29,7 @@ class LiteLLMInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("litellm")@@ -38,28 +38,28 @@ class LiteLLMInstrumentor(BaseInstrumentor):"litellm","completion",completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("litellm","acompletion",acompletion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("litellm","embedding",embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("litellm","aembedding",aembedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.pyindex 1db2f733..47328ee47 100644--- a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py+++ b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def acompletion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -32,7 +32,7 @@ def acompletion(version, environment, application_name,application_name: Name of the application using the LiteLLM SDK.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of LiteLLM usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -217,7 +217,7 @@ def acompletion(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -393,7 +393,7 @@ def acompletion(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -404,7 +404,7 @@ def acompletion(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -464,7 +464,7 @@ def acompletion(version, environment, application_name,return wrapperdef aembedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -474,7 +474,7 @@ def aembedding(version, environment, application_name,application_name: Name of the application using the LiteLLM API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of LiteLLM usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -548,7 +548,7 @@ def aembedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/litellm/litellm.py b/sdk/python/src/openlit/instrumentation/litellm/litellm.pyindex ba24d1f8..120eeb41 100644--- a/sdk/python/src/openlit/instrumentation/litellm/litellm.py+++ b/sdk/python/src/openlit/instrumentation/litellm/litellm.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -32,7 +32,7 @@ def completion(version, environment, application_name,application_name: Name of the application using the LiteLLM SDK.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of LiteLLM usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -217,7 +217,7 @@ def completion(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -393,7 +393,7 @@ def completion(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -404,7 +404,7 @@ def completion(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -464,7 +464,7 @@ def completion(version, environment, application_name,return wrapperdef embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -474,7 +474,7 @@ def embedding(version, environment, application_name,application_name: Name of the application using the LiteLLM API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of LiteLLM usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -548,7 +548,7 @@ def embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/llamaindex/__init__.py b/sdk/python/src/openlit/instrumentation/llamaindex/__init__.pyindex 43c66875..d077aca8 100644--- a/sdk/python/src/openlit/instrumentation/llamaindex/__init__.py+++ b/sdk/python/src/openlit/instrumentation/llamaindex/__init__.py@@ -35,7 +35,7 @@ class LlamaIndexInstrumentor(BaseInstrumentor):environment = kwargs.get("environment")tracer = kwargs.get("tracer")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")version = importlib.metadata.version("llama-index")for wrapped_method in WRAPPED_METHODS:@@ -47,7 +47,7 @@ class LlamaIndexInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content),+ tracer, pricing_info, capture_message_content),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py b/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.pyindex 381d56c2..3098a30a 100644--- a/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py+++ b/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def load_data(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content):+ tracer, pricing_info, capture_message_content):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def load_data(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the LlamaIndex application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/mem0/__init__.py b/sdk/python/src/openlit/instrumentation/mem0/__init__.pyindex 1bf87afd..1cb7dfb2 100644--- a/sdk/python/src/openlit/instrumentation/mem0/__init__.py+++ b/sdk/python/src/openlit/instrumentation/mem0/__init__.py@@ -59,7 +59,7 @@ class Mem0Instrumentor(BaseInstrumentor):environment = kwargs.get("environment")tracer = kwargs.get("tracer")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")version = importlib.metadata.version("mem0ai")for wrapped_method in WRAPPED_METHODS:@@ -71,7 +71,7 @@ class Mem0Instrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content),+ tracer, pricing_info, capture_message_content),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/mem0/mem0.py b/sdk/python/src/openlit/instrumentation/mem0/mem0.pyindex 2c1719d3..0c2a26dd 100644--- a/sdk/python/src/openlit/instrumentation/mem0/mem0.py+++ b/sdk/python/src/openlit/instrumentation/mem0/mem0.py@@ -13,7 +13,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def mem0_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content):+ tracer, pricing_info, capture_message_content):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -27,7 +27,7 @@ def mem0_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the mem0 application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/milvus/__init__.py b/sdk/python/src/openlit/instrumentation/milvus/__init__.pyindex c1e40472..66203730 100644--- a/sdk/python/src/openlit/instrumentation/milvus/__init__.py+++ b/sdk/python/src/openlit/instrumentation/milvus/__init__.py@@ -72,7 +72,7 @@ class MilvusInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("pymilvus")@@ -85,7 +85,7 @@ class MilvusInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/milvus/milvus.py b/sdk/python/src/openlit/instrumentation/milvus/milvus.pyindex 1639491e..b0018595 100644--- a/sdk/python/src/openlit/instrumentation/milvus/milvus.py+++ b/sdk/python/src/openlit/instrumentation/milvus/milvus.py@@ -25,7 +25,7 @@ def object_count(obj):return cntdef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -39,7 +39,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/mistral/__init__.py b/sdk/python/src/openlit/instrumentation/mistral/__init__.pyindex 7bc0074d..e9b88b64 100644--- a/sdk/python/src/openlit/instrumentation/mistral/__init__.py+++ b/sdk/python/src/openlit/instrumentation/mistral/__init__.py@@ -23,7 +23,7 @@ class MistralInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("mistralai")@@ -32,7 +32,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.chat","Chat.complete",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync@@ -40,7 +40,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.chat","Chat.stream",chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync@@ -48,7 +48,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.embeddings","Embeddings.create",embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Async@@ -56,7 +56,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.chat","Chat.complete_async",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Async@@ -64,7 +64,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.chat","Chat.stream_async",async_chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)#sync@@ -72,7 +72,7 @@ class MistralInstrumentor(BaseInstrumentor):"mistralai.embeddings","Embeddings.create_async",async_embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.pyindex e92bc284..ff32ab52 100644--- a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py+++ b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_chat(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -32,7 +32,7 @@ def async_chat(version, environment, application_name, tracer,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -144,7 +144,7 @@ def async_chat(version, environment, application_name, tracer,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -155,7 +155,7 @@ def async_chat(version, environment, application_name, tracer,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -215,7 +215,7 @@ def async_chat(version, environment, application_name, tracer,return wrapperdef async_chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat_stream to collect metrics.@@ -225,7 +225,7 @@ def async_chat_stream(version, environment, application_name,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -422,7 +422,7 @@ def async_chat_stream(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -485,7 +485,7 @@ def async_chat_stream(version, environment, application_name,return wrapperdef async_embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -495,7 +495,7 @@ def async_embeddings(version, environment, application_name,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -567,7 +567,7 @@ def async_embeddings(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/mistral/mistral.py b/sdk/python/src/openlit/instrumentation/mistral/mistral.pyindex 3dd363f6..5bbf9041 100644--- a/sdk/python/src/openlit/instrumentation/mistral/mistral.py+++ b/sdk/python/src/openlit/instrumentation/mistral/mistral.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def chat(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -32,7 +32,7 @@ def chat(version, environment, application_name, tracer,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -144,7 +144,7 @@ def chat(version, environment, application_name, tracer,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -155,7 +155,7 @@ def chat(version, environment, application_name, tracer,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -215,7 +215,7 @@ def chat(version, environment, application_name, tracer,return wrapperdef chat_stream(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat_stream to collect metrics.@@ -225,7 +225,7 @@ def chat_stream(version, environment, application_name,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -422,7 +422,7 @@ def chat_stream(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -485,7 +485,7 @@ def chat_stream(version, environment, application_name,return wrapperdef embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -495,7 +495,7 @@ def embeddings(version, environment, application_name,application_name: Name of the application using the Mistral API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Mistral usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -567,7 +567,7 @@ def embeddings(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/multion/__init__.py b/sdk/python/src/openlit/instrumentation/multion/__init__.pyindex 65a4bb65..2487a5f0 100644--- a/sdk/python/src/openlit/instrumentation/multion/__init__.py+++ b/sdk/python/src/openlit/instrumentation/multion/__init__.py@@ -30,7 +30,7 @@ class MultiOnInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("multion")@@ -39,19 +39,19 @@ class MultiOnInstrumentor(BaseInstrumentor):"multion.client","MultiOn.browse",multion_wrap("multion.browse", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("multion.client","MultiOn.retrieve",multion_wrap("multion.retrieve", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("multion.sessions.client","SessionsClient.create",multion_wrap("multion.sessions.create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Asynchronus@@ -59,19 +59,19 @@ class MultiOnInstrumentor(BaseInstrumentor):"multion.client","AsyncMultiOn.browse",async_multion_wrap("multion.browse", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("multion.client","AsyncMultiOn.retrieve",async_multion_wrap("multion.retrieve", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("multion.sessions.client","AsyncSessionsClient.create",async_multion_wrap("multion.sessions.create", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/multion/async_multion.py b/sdk/python/src/openlit/instrumentation/multion/async_multion.pyindex 2153f6b6..cff7bd9d 100644--- a/sdk/python/src/openlit/instrumentation/multion/async_multion.py+++ b/sdk/python/src/openlit/instrumentation/multion/async_multion.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the multion Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of multion usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -75,7 +75,7 @@ def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_RESPONSE_TIME,response.metadata.processing_time)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -92,7 +92,7 @@ def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,kwargs.get("url", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -110,7 +110,7 @@ def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,kwargs.get("url", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/multion/multion.py b/sdk/python/src/openlit/instrumentation/multion/multion.pyindex f6ac6479..d6c34337 100644--- a/sdk/python/src/openlit/instrumentation/multion/multion.py+++ b/sdk/python/src/openlit/instrumentation/multion/multion.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def multion_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the multion Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of multion usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -75,7 +75,7 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_RESPONSE_TIME,response.metadata.processing_time)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -92,7 +92,7 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,kwargs.get("url", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -110,7 +110,7 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,kwargs.get("url", ""))- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/ollama/__init__.py b/sdk/python/src/openlit/instrumentation/ollama/__init__.pyindex d0f68237..85468c8f 100644--- a/sdk/python/src/openlit/instrumentation/ollama/__init__.py+++ b/sdk/python/src/openlit/instrumentation/ollama/__init__.py@@ -1,5 +1,6 @@-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code-"""Initializer of Auto Instrumentation of Ollama Functions"""+"""+Initializer of Auto Instrumentation of Ollama Functions+"""from typing import Collectionimport importlib.metadata@@ -27,9 +28,10 @@ class OllamaInstrumentor(BaseInstrumentor):application_name = kwargs.get("application_name", "default_application")environment = kwargs.get("environment", "default_environment")tracer = kwargs.get("tracer")+ event_provider = kwargs.get("event_provider")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("ollama")@@ -38,13 +40,13 @@ class OllamaInstrumentor(BaseInstrumentor):"ollama","chat",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("ollama","Client.chat",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)# sync embeddings@@ -52,13 +54,13 @@ class OllamaInstrumentor(BaseInstrumentor):"ollama","embeddings",embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("ollama","Client.embeddings",embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)# async chat@@ -66,7 +68,7 @@ class OllamaInstrumentor(BaseInstrumentor):"ollama","AsyncClient.chat",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)# async embeddings@@ -74,7 +76,7 @@ class OllamaInstrumentor(BaseInstrumentor):"ollama","AsyncClient.embeddings",async_embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.pyindex 18c9c1d1..64367746 100644--- a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py+++ b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py@@ -4,56 +4,37 @@ Module for monitoring Ollama API calls.import loggingimport time-from opentelemetry.trace import SpanKind, Status, StatusCode-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import SpanKindfrom openlit.__helpers import (- get_chat_model_cost,- get_embed_model_cost,handle_exception,- response_as_dict,- general_tokens,- calculate_ttft,- calculate_tbt,- create_metrics_attributes,set_server_address_and_port)+from openlit.instrumentation.ollama.utils import (+ process_chunk,+ process_chat_response,+ process_streaming_chat_response,+ process_embedding_response+)from openlit.semcov import SemanticConvetion-# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)def async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the Ollama API.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of Ollama usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""class TracedAsyncStream:"""- Wrapper for streaming responses to collect metrics and trace data.- Wraps the response to collect message IDs and aggregated response.-- This class implements the '__aiter__' and '__anext__' methods that- handle asynchronous streaming responses.-- This class also implements '__aenter__' and '__aexit__' methods that- handle asynchronous context management protocol.+ Wrapper for streaming responses to collect telemetry."""+def __init__(self,wrapped,span,+ span_name,kwargs,server_address,server_port,@@ -61,13 +42,14 @@ def async_chat(version, environment, application_name,):self.__wrapped__ = wrappedself._span = span- # Placeholder for aggregating streaming responseself._llmresponse = ""self._response_model = ""self._finish_reason = ""+ self._tool_calls = []self._input_tokens = 0self._output_tokens = 0-+ self._response_role = ''+ self._span_name = span_nameself._args = argsself._kwargs = kwargsself._start_time = time.time()@@ -95,194 +77,34 @@ def async_chat(version, environment, application_name,async def __anext__(self):try:chunk = await self.__wrapped__.__anext__()- end_time = time.time()- # Record the timestamp for the current chunk- self._timestamps.append(end_time)-- if len(self._timestamps) == 1:- # Calculate time to first chunk- self._ttft = calculate_ttft(self._timestamps, self._start_time)-- chunked = response_as_dict(chunk)- self._llmresponse += chunked.get('message').get('content')-- if chunked.get('eval_count'):- self._input_tokens = chunked.get('prompt_eval_count')- self._output_tokens = chunked.get('eval_count')- self._response_model = chunked.get('model')- self._finish_reason = chunked.get('done_reason')+ process_chunk(self, chunk)return chunkexcept StopAsyncIteration:- # Handling exception ensure observability without disrupting operationtry:- self._end_time = time.time()- if len(self._timestamps) > 1:- self._tbt = calculate_tbt(self._timestamps)-- # Format 'messages' into a single string- message_prompt = self._kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message["role"]- content = message["content"]-- if isinstance(content, list):- content_str_list = []- for item in content:- if item["type"] == "text":- content_str_list.append(f'text: {item["text"]}')- elif (item["type"] == "image_url" and- not item["image_url"]["url"].startswith("data:")):- content_str_list.append(f'image_url: {item["image_url"]["url"]}')- content_str = ", ".join(content_str_list)- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- request_model = self._kwargs.get("model", "gpt-4o")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, self._input_tokens,- self._output_tokens)-- # Set Span attributes (OTel Semconv)- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- self._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.SERVER_PORT,- self._server_port)-- # List of attributes and their config keys- attributes = [- (SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, 'repeat_penalty'),- (SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, 'max_tokens'),- (SemanticConvetion.GEN_AI_REQUEST_SEED, 'seed'),- (SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, 'stop'),- (SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, 'temperature'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_P, 'top_p'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_K, 'top_k'),- ]-- # Safely get the options dictionary from kwargs- options = self._kwargs.get('options', {})-- # Set each attribute if the corresponding value exists and is not None- for attribute, key in attributes:- # Use dictionary `get` to retrieve values from the options dictionary- value = options.get(key)- if value is not None:- self._span.set_attribute(attribute, value)-- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [self._finish_reason])- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- self._response_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- self._input_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- self._output_tokens)- self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- self._server_address)- if isinstance(self._llmresponse, str):- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- else:- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Set Span attributes (Extra)- self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- self._span.set_attribute(SERVICE_NAME,- application_name)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- True)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- self._input_tokens + self._output_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT,- self._tbt)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- self._ttft)- self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,- },- )- self._span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=self._server_address,- server_port=self._server_port,- response_model=self._response_model,- )-- metrics["genai_client_usage_tokens"].record(- self._input_tokens + self._output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- self._end_time - self._start_time, attributes- )- metrics["genai_server_tbt"].record(- self._tbt, attributes+ with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version)- metrics["genai_server_ttft"].record(- self._ttft, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(self._output_tokens, attributes)- metrics["genai_prompt_tokens"].add(self._input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-except Exception as e:handle_exception(self._span, e)logger.error("Error in trace creation: %s", e)- finally:- self._span.end()raiseasync def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""- # Check if streaming is enabled for the API callstreaming = kwargs.get("stream", False)+server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 11434)request_model = kwargs.get("model", "gpt-4o")@@ -290,202 +112,45 @@ def async_chat(version, environment, application_name,# pylint: disable=no-else-returnif streaming:- # Special handling for streaming response to accommodate the nature of data flowawaited_wrapped = await wrapped(*args, **kwargs)span = tracer.start_span(span_name, kind=SpanKind.CLIENT)+ return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)- return TracedAsyncStream(awaited_wrapped, span, kwargs, server_address, server_port)-- # Handling for non-streaming responseselse:with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = await wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message["role"]- content = message["content"]-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = response_dict.get('prompt_eval_count')- output_tokens = response_dict.get('eval_count')-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)-- # List of attributes and their config keys- attributes = [- (SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, 'repeat_penalty'),- (SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, 'max_tokens'),- (SemanticConvetion.GEN_AI_REQUEST_SEED, 'seed'),- (SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, 'stop'),- (SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, 'temperature'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_P, 'top_p'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_K, 'top_k'),- ]-- # Safely get the options dictionary from kwargs- options = kwargs.get('options', {})-- # Set each attribute if the corresponding value exists and is not None- for attribute, key in attributes:- # Use dictionary `get` to retrieve values from the options dictionary- value = options.get(key)- if value is not None:- span.set_attribute(attribute, value)-- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- response_dict.get('model'))- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [response_dict.get('done_reason')])- if kwargs.get('format'):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- 'json')- else:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- 'text')-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_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={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('message').get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('message').get('tool_calls')))-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=response_dict.get('model'),- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_response(+ response=response,+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdef async_embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for embeddings to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the Ollama API.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of Ollama usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the embeddings method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""async def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'embeddings' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'embeddings' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'embeddings' method.- kwargs: Keyword arguments for the 'embeddings' method.-- Returns:- The response from the original 'embeddings' method.+ Wraps the GenAI function call."""server_address, server_port = set_server_address_and_port(instance, '127.0.0.1', 11434)@@ -496,83 +161,24 @@ def async_embeddings(version, environment, application_name,with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = await wrapped(*args, **kwargs)- end_time = time.time()-- try:- input_tokens = general_tokens(str(kwargs.get('prompt')))-- # Calculate cost of the operation- cost = get_embed_model_cost(request_model,- pricing_info, input_tokens)-- # Set Span attributes (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)-- # Set Span attributes (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)-- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get('prompt', '')),- },- )-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )- metrics['genai_client_usage_tokens'].record(- input_tokens, attributes- )- metrics['genai_client_operation_duration'].record(- end_time - start_time, attributes- )- metrics['genai_requests'].add(1, attributes)- metrics['genai_prompt_tokens'].add(input_tokens, attributes)- metrics['genai_cost'].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error('Error in trace creation: %s', e)-- # Return original response- return response+ response = process_embedding_response(+ response=response,+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/ollama/ollama.py b/sdk/python/src/openlit/instrumentation/ollama/ollama.pyindex 05f3b74a..4bfcbe4b 100644--- a/sdk/python/src/openlit/instrumentation/ollama/ollama.py+++ b/sdk/python/src/openlit/instrumentation/ollama/ollama.py@@ -4,56 +4,37 @@ Module for monitoring Ollama API calls.import loggingimport time-from opentelemetry.trace import SpanKind, Status, StatusCode-from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import SpanKindfrom openlit.__helpers import (- get_chat_model_cost,- get_embed_model_cost,handle_exception,- response_as_dict,- general_tokens,- calculate_ttft,- calculate_tbt,- create_metrics_attributes,set_server_address_and_port)+from openlit.instrumentation.ollama.utils import (+ process_chunk,+ process_chat_response,+ process_streaming_chat_response,+ process_embedding_response+)from openlit.semcov import SemanticConvetion-# Initialize logger for logging potential issues and operationslogger = logging.getLogger(__name__)def chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for chat completions to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the Ollama API.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of Ollama usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the chat completions method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""class TracedSyncStream:"""- Wrapper for streaming responses to collect metrics and trace data.- Wraps the response to collect message IDs and aggregated response.-- This class implements the '__aiter__' and '__anext__' methods that- handle asynchronous streaming responses.-- This class also implements '__aenter__' and '__aexit__' methods that- handle asynchronous context management protocol.+ Wrapper for streaming responses to collect telemetry."""+def __init__(self,wrapped,span,+ span_name,kwargs,server_address,server_port,@@ -61,13 +42,14 @@ def chat(version, environment, application_name,):self.__wrapped__ = wrappedself._span = span- # Placeholder for aggregating streaming responseself._llmresponse = ""self._response_model = ""self._finish_reason = ""+ self._tool_calls = []self._input_tokens = 0self._output_tokens = 0-+ self._response_role = ''+ self._span_name = span_nameself._args = argsself._kwargs = kwargsself._start_time = time.time()@@ -95,194 +77,34 @@ def chat(version, environment, application_name,def __next__(self):try:chunk = self.__wrapped__.__next__()- end_time = time.time()- # Record the timestamp for the current chunk- self._timestamps.append(end_time)-- if len(self._timestamps) == 1:- # Calculate time to first chunk- self._ttft = calculate_ttft(self._timestamps, self._start_time)-- chunked = response_as_dict(chunk)- self._llmresponse += chunked.get('message').get('content')-- if chunked.get('eval_count'):- self._input_tokens = chunked.get('prompt_eval_count')- self._output_tokens = chunked.get('eval_count')- self._response_model = chunked.get('model')- self._finish_reason = chunked.get('done_reason')+ process_chunk(self, chunk)return chunkexcept StopIteration:- # Handling exception ensure observability without disrupting operationtry:- self._end_time = time.time()- if len(self._timestamps) > 1:- self._tbt = calculate_tbt(self._timestamps)-- # Format 'messages' into a single string- message_prompt = self._kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message["role"]- content = message["content"]-- if isinstance(content, list):- content_str_list = []- for item in content:- if item["type"] == "text":- content_str_list.append(f'text: {item["text"]}')- elif (item["type"] == "image_url" and- not item["image_url"]["url"].startswith("data:")):- content_str_list.append(f'image_url: {item["image_url"]["url"]}')- content_str = ", ".join(content_str_list)- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- request_model = self._kwargs.get("model", "gpt-4o")-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, self._input_tokens,- self._output_tokens)-- # Set Span attributes (OTel Semconv)- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- self._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- self._span.set_attribute(SemanticConvetion.SERVER_PORT,- self._server_port)-- # List of attributes and their config keys- attributes = [- (SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, 'repeat_penalty'),- (SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, 'max_tokens'),- (SemanticConvetion.GEN_AI_REQUEST_SEED, 'seed'),- (SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, 'stop'),- (SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, 'temperature'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_P, 'top_p'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_K, 'top_k'),- ]-- # Safely get the options dictionary from kwargs- options = self._kwargs.get('options', {})-- # Set each attribute if the corresponding value exists and is not None- for attribute, key in attributes:- # Use dictionary `get` to retrieve values from the options dictionary- value = options.get(key)- if value is not None:- self._span.set_attribute(attribute, value)-- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [self._finish_reason])- self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- self._response_model)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- self._input_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- self._output_tokens)- self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- self._server_address)- if isinstance(self._llmresponse, str):- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "text")- else:- self._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- "json")-- # Set Span attributes (Extra)- self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- self._span.set_attribute(SERVICE_NAME,- application_name)- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- True)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- self._input_tokens + self._output_tokens)- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT,- self._tbt)- self._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- self._ttft)- self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_content:- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,- },- )- self._span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,- },- )- self._span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=self._server_address,- server_port=self._server_port,- response_model=self._response_model,- )-- metrics["genai_client_usage_tokens"].record(- self._input_tokens + self._output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- self._end_time - self._start_time, attributes- )- metrics["genai_server_tbt"].record(- self._tbt, attributes+ with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version)- metrics["genai_server_ttft"].record(- self._ttft, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(self._output_tokens, attributes)- metrics["genai_prompt_tokens"].add(self._input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-except Exception as e:handle_exception(self._span, e)logger.error("Error in trace creation: %s", e)- finally:- self._span.end()raisedef wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'chat.completions' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'chat.completions' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'chat.completions' method.- kwargs: Keyword arguments for the 'chat.completions' method.-- Returns:- The response from the original 'chat.completions' method.+ Wraps the GenAI function call."""- # Check if streaming is enabled for the API callstreaming = kwargs.get("stream", False)+server_address, server_port = set_server_address_and_port(instance, "127.0.0.1", 11434)request_model = kwargs.get("model", "gpt-4o")@@ -290,202 +112,45 @@ def chat(version, environment, application_name,# pylint: disable=no-else-returnif streaming:- # Special handling for streaming response to accommodate the nature of data flowawaited_wrapped = wrapped(*args, **kwargs)span = tracer.start_span(span_name, kind=SpanKind.CLIENT)+ return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)- return TracedSyncStream(awaited_wrapped, span, kwargs, server_address, server_port)-- # Handling for non-streaming responseselse:with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = wrapped(*args, **kwargs)- end_time = time.time()-- response_dict = response_as_dict(response)-- try:- # Format 'messages' into a single string- message_prompt = kwargs.get("messages", "")- formatted_messages = []- for message in message_prompt:- role = message["role"]- content = message["content"]-- if isinstance(content, list):- content_str = ", ".join(- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'- if "type" in item else f'text: {item["text"]}'- for item in content- )- formatted_messages.append(f"{role}: {content_str}")- else:- formatted_messages.append(f"{role}: {content}")- prompt = "\n".join(formatted_messages)-- input_tokens = response_dict.get('prompt_eval_count')- output_tokens = response_dict.get('eval_count')-- # Calculate cost of the operation- cost = get_chat_model_cost(request_model,- pricing_info, input_tokens,- output_tokens)-- # Set base span attribues (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)-- # List of attributes and their config keys- attributes = [- (SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, 'repeat_penalty'),- (SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, 'max_tokens'),- (SemanticConvetion.GEN_AI_REQUEST_SEED, 'seed'),- (SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, 'stop'),- (SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, 'temperature'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_P, 'top_p'),- (SemanticConvetion.GEN_AI_REQUEST_TOP_K, 'top_k'),- ]-- # Safely get the options dictionary from kwargs- options = kwargs.get('options', {})-- # Set each attribute if the corresponding value exists and is not None- for attribute, key in attributes:- # Use dictionary `get` to retrieve values from the options dictionary- value = options.get(key)- if value is not None:- span.set_attribute(attribute, value)-- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- response_dict.get('model'))- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,- output_tokens)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,- [response_dict.get('done_reason')])- if kwargs.get('format'):- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- 'json')- else:- span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,- 'text')-- # Set base span attribues (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,- False)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens + output_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT,- end_time - start_time)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)- if trace_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={- # pylint: disable=line-too-long- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('message').get('content')),- },- )- if kwargs.get('tools'):- span.set_attribute(SemanticConvetion.GEN_AI_TOOL_CALLS,- str(response_dict.get('message').get('tool_calls')))-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=response_dict.get('model'),- )-- metrics["genai_client_usage_tokens"].record(- input_tokens + output_tokens, attributes- )- metrics["genai_client_operation_duration"].record(- end_time - start_time, attributes- )- metrics["genai_server_ttft"].record(- end_time - start_time, attributes- )- metrics["genai_requests"].add(1, attributes)- metrics["genai_completion_tokens"].add(output_tokens, attributes)- metrics["genai_prompt_tokens"].add(input_tokens, attributes)- metrics["genai_cost"].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error("Error in trace creation: %s", e)-- # Return original response- return response+ response = process_chat_response(+ response=response,+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdef embeddings(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):"""- Generates a telemetry wrapper for embeddings to collect metrics.-- Args:- version: Version of the monitoring package.- environment: Deployment environment (e.g., production, staging).- application_name: Name of the application using the Ollama API.- tracer: OpenTelemetry tracer for creating spans.- pricing_info: Information used for calculating the cost of Ollama usage.- trace_content: Flag indicating whether to trace the actual content.-- Returns:- A function that wraps the embeddings method to add telemetry.+ Generates a telemetry wrapper for GenAI function call"""def wrapper(wrapped, instance, args, kwargs):"""- Wraps the 'embeddings' API call to add telemetry.-- This collects metrics such as execution time, cost, and token usage, and handles errors- gracefully, adding details to the trace for observability.-- Args:- wrapped: The original 'embeddings' method to be wrapped.- instance: The instance of the class where the original method is defined.- args: Positional arguments for the 'embeddings' method.- kwargs: Keyword arguments for the 'embeddings' method.-- Returns:- The response from the original 'embeddings' method.+ Wraps the GenAI function call."""server_address, server_port = set_server_address_and_port(instance, '127.0.0.1', 11434)@@ -496,83 +161,24 @@ def embeddings(version, environment, application_name,with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:start_time = time.time()response = wrapped(*args, **kwargs)- end_time = time.time()-- try:- input_tokens = general_tokens(str(kwargs.get('prompt')))-- # Calculate cost of the operation- cost = get_embed_model_cost(request_model,- pricing_info, input_tokens)-- # Set Span attributes (OTel Semconv)- span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,- SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,- SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,- request_model)- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,- request_model)- span.set_attribute(SemanticConvetion.SERVER_ADDRESS,- server_address)- span.set_attribute(SemanticConvetion.SERVER_PORT,- server_port)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,- input_tokens)-- # Set Span attributes (Extras)- span.set_attribute(DEPLOYMENT_ENVIRONMENT,- environment)- span.set_attribute(SERVICE_NAME,- application_name)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,- input_tokens)- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,- cost)- span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,- version)-- if trace_content:- span.add_event(- name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,- attributes={- SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get('prompt', '')),- },- )-- span.set_status(Status(StatusCode.OK))-- if disable_metrics is False:- attributes = create_metrics_attributes(- service_name=application_name,- deployment_environment=environment,- operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,- system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,- request_model=request_model,- server_address=server_address,- server_port=server_port,- response_model=request_model,- )- metrics['genai_client_usage_tokens'].record(- input_tokens, attributes- )- metrics['genai_client_operation_duration'].record(- end_time - start_time, attributes- )- metrics['genai_requests'].add(1, attributes)- metrics['genai_prompt_tokens'].add(input_tokens, attributes)- metrics['genai_cost'].record(cost, attributes)-- # Return original response- return response-- except Exception as e:- handle_exception(span, e)- logger.error('Error in trace creation: %s', e)-- # Return original response- return response+ response = process_embedding_response(+ response=response,+ request_model=request_model,+ pricing_info=pricing_info,+ server_port=server_port,+ server_address=server_address,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ event_provider=event_provider,+ start_time=start_time,+ span=span,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ **kwargs+ )++ return responsereturn wrapperdiff --git a/sdk/python/src/openlit/instrumentation/ollama/utils.py b/sdk/python/src/openlit/instrumentation/ollama/utils.pynew file mode 100644index 00000000..4fdb617a--- /dev/null+++ b/sdk/python/src/openlit/instrumentation/ollama/utils.py@@ -0,0 +1,333 @@+"""+Ollama OpenTelemetry instrumentation utility functions+"""+import time++from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.trace import Status, StatusCode++from openlit.__helpers import (+ calculate_ttft,+ response_as_dict,+ calculate_tbt,+ general_tokens,+ extract_and_format_input,+ get_chat_model_cost,+ get_embed_model_cost,+ handle_exception,+ create_metrics_attributes,+ otel_event,+ concatenate_all_contents+)+from openlit.semcov import SemanticConvetion++def process_chunk(self, chunk):+ """+ Process a chunk of response data and update state.+ """++ end_time = time.time()+ # Record the timestamp for the current chunk+ self._timestamps.append(end_time)++ if len(self._timestamps) == 1:+ # Calculate time to first chunk+ self._ttft = calculate_ttft(self._timestamps, self._start_time)++ chunked = response_as_dict(chunk)+ self._llmresponse += chunked.get('message', {}).get('content', '')++ if chunked.get('message', {}).get('tool_calls'):+ self._tool_calls = chunked['message']['tool_calls']++ if chunked.get('eval_count'):+ self._response_role = chunked.get('message', {}).get('role', '')+ self._input_tokens = chunked.get('prompt_eval_count', 0)+ self._output_tokens = chunked.get('eval_count', 0)+ self._response_model = chunked.get('model', '')+ self._finish_reason = chunked.get('done_reason', '')++def common_chat_logic(scope, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream):+ """+ Process chat request and generate Telemetry+ """++ scope._end_time = time.time()+ if len(scope._timestamps) > 1:+ scope._tbt = calculate_tbt(scope._timestamps)++ formatted_messages = extract_and_format_input(scope._kwargs.get("messages", ""))+ request_model = scope._kwargs.get("model", "gpt-4o")++ cost = get_chat_model_cost(request_model, pricing_info, scope._input_tokens, scope._output_tokens)++ # Set Span attributes (OTel Semconv)+ scope._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")+ scope._span.set_attribute(SemanticConvetion.GEN_AI_OPERATION, SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM, SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL, request_model)+ scope._span.set_attribute(SemanticConvetion.SERVER_PORT, scope._server_port)++ options = scope._kwargs.get('options', {})+ attributes = [+ (SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY, 'repeat_penalty'),+ (SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS, 'max_tokens'),+ (SemanticConvetion.GEN_AI_REQUEST_SEED, 'seed'),+ (SemanticConvetion.GEN_AI_REQUEST_STOP_SEQUENCES, 'stop'),+ (SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE, 'temperature'),+ (SemanticConvetion.GEN_AI_REQUEST_TOP_P, 'top_p'),+ (SemanticConvetion.GEN_AI_REQUEST_TOP_K, 'top_k'),+ ]++ for attribute, key in attributes:+ value = options.get(key)+ if value is not None:+ scope._span.set_attribute(attribute, value)++ scope._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason])+ scope._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL, scope._response_model)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens)+ scope._span.set_attribute(SemanticConvetion.SERVER_ADDRESS, scope._server_address)++ scope._span.set_attribute(SemanticConvetion.GEN_AI_OUTPUT_TYPE,+ "text" if isinstance(scope._llmresponse, str) else "json")++ scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)+ scope._span.set_attribute(SERVICE_NAME, application_name)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM, is_stream)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_CLIENT_TOKEN_USAGE, scope._input_tokens + scope._output_tokens)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TBT, scope._tbt)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SERVER_TTFT, scope._ttft)+ scope._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION, version)++ # To be removed one the change to log events (from span events) is complete+ prompt = concatenate_all_contents(formatted_messages)+ if capture_message_content:+ scope._span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,+ },+ )+ scope._span.add_event(+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,+ attributes={+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: scope._llmresponse,+ },+ )++ choice_event_body = {+ "finish_reason": scope._finish_reason,+ "index": 0,+ "message": {+ **({"content": scope._llmresponse} if capture_message_content else {}),+ "role": scope._response_role+ }+ }++ if scope._tool_calls:+ print(scope._tool_calls)+ function_call = scope._tool_calls[0]+ choice_event_body["message"].update({+ "tool_calls": {+ "function": {+ "name": function_call.get('function', {}).get('name', ''),+ "arguments": function_call.get('function', {}).get('arguments', '')+ },+ "id": function_call.get('id', ''),+ "type": "function"+ }+ })++ # Emit events+ for role in ['user', 'system', 'assistant', 'tool']:+ if formatted_messages.get(role, {}).get('content', ''):+ event = otel_event(+ name=getattr(SemanticConvetion, f'GEN_AI_{role.upper()}_MESSAGE'),+ attributes={+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_OLLAMA+ },+ body = {+ # pylint: disable=line-too-long+ **({"content": formatted_messages.get(role, {}).get('content', '')} if capture_message_content else {}),+ "role": formatted_messages.get(role, {}).get('role', []),+ **({+ "tool_calls": {+ "function": {+ # pylint: disable=line-too-long+ "name": (scope._tool_calls[0].get('function', {}).get('name', '') if scope._tool_calls else ''),+ "arguments": (scope._tool_calls[0].get('function', {}).get('arguments', '') if scope._tool_calls else '')+ },+ "id": (scope._tool_calls[0].get('id', '') if scope._tool_calls else ''),+ "type": "function"+ }+ } if role == 'assistant' else {}),+ **({+ "id": (scope._tool_calls[0].get('id', '') if scope._tool_calls else '')+ } if role == 'tool' else {})+ }+ )+ event_provider.emit(event)++ choice_event = otel_event(+ name=SemanticConvetion.GEN_AI_CHOICE,+ attributes={+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_OLLAMA+ },+ body=choice_event_body+ )+ event_provider.emit(choice_event)++ scope._span.set_status(Status(StatusCode.OK))++ if not disable_metrics:+ metrics_attributes = create_metrics_attributes(+ service_name=application_name,+ deployment_environment=environment,+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,+ system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,+ request_model=request_model,+ server_address=scope._server_address,+ server_port=scope._server_port,+ response_model=scope._response_model,+ )++ metrics["genai_client_usage_tokens"].record(scope._input_tokens + scope._output_tokens, metrics_attributes)+ metrics["genai_client_operation_duration"].record(scope._end_time - scope._start_time, metrics_attributes)+ metrics["genai_server_tbt"].record(scope._tbt, metrics_attributes)+ metrics["genai_server_ttft"].record(scope._ttft, metrics_attributes)+ metrics["genai_requests"].add(1, metrics_attributes)+ metrics["genai_completion_tokens"].add(scope._output_tokens, metrics_attributes)+ metrics["genai_prompt_tokens"].add(scope._input_tokens, metrics_attributes)+ metrics["genai_cost"].record(cost, metrics_attributes)++def process_streaming_chat_response(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content=False, disable_metrics=False, version=''):+ """+ Process chat request and generate Telemetry+ """++ common_chat_logic(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream=True)++def process_chat_response(response, request_model, pricing_info, server_port, server_address,+ environment, application_name, metrics, event_provider, start_time,+ span, capture_message_content=False, disable_metrics=False, version="1.0.0", **kwargs):+ """+ Process chat request and generate Telemetry+ """++ self = type('GenericScope', (), {})()++ # pylint: disable = no-member+ self._start_time = start_time+ self._end_time = time.time()+ self._span = span+ self._llmresponse = response.get('message', {}).get('content', '')+ self._response_role = response.get('message', {}).get('role', 'assistant')+ self._input_tokens = response.get('prompt_eval_count')+ self._output_tokens = response.get('eval_count')+ self._response_model = response.get('model', '')+ self._finish_reason = response.get('done_reason', '')+ self._timestamps = []+ self._ttft, self._tbt = self._end_time - self._start_time, 0+ self._server_address, self._server_port = server_address, server_port+ self._kwargs = kwargs+ self._tool_calls = response.get('message', {}).get('tool_calls', [])++ common_chat_logic(self, pricing_info, environment, application_name, metrics,+ event_provider, capture_message_content, disable_metrics, version, is_stream=False)++ return response++def process_embedding_response(response, request_model, pricing_info, server_port, server_address,+ environment, application_name, metrics, event_provider,+ start_time, span, capture_message_content=False, disable_metrics=False, version="1.0.0", **kwargs):+ """+ Process embedding request and generate Telemetry+ """++ end_time = time.time()++ try:+ input_tokens = general_tokens(str(kwargs.get('prompt')))++ # Calculate cost of the operation+ cost = get_embed_model_cost(request_model,+ pricing_info, input_tokens)++ # Set Span attributes (OTel Semconv)+ span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')+ span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,+ SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,+ SemanticConvetion.GEN_AI_SYSTEM_OLLAMA)+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,+ request_model)+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,+ request_model)+ span.set_attribute(SemanticConvetion.SERVER_ADDRESS,+ server_address)+ span.set_attribute(SemanticConvetion.SERVER_PORT,+ server_port)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,+ input_tokens)++ # Set Span attributes (Extras)+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,+ environment)+ span.set_attribute(SERVICE_NAME,+ application_name)+ span.set_attribute(SemanticConvetion.GEN_AI_CLIENT_TOKEN_USAGE,+ input_tokens)+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,+ cost)+ span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,+ version)++ prompt_event = otel_event(+ name=SemanticConvetion.GEN_AI_USER_MESSAGE,+ attributes={+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_OLLAMA+ },+ body={+ **({"content": kwargs.get('prompt', '')} if capture_message_content else {}),+ "role": 'user'+ }+ )+ event_provider.emit(prompt_event)++ span.set_status(Status(StatusCode.OK))++ if disable_metrics is False:+ attributes = create_metrics_attributes(+ service_name=application_name,+ deployment_environment=environment,+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,+ system=SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,+ request_model=request_model,+ server_address=server_address,+ server_port=server_port,+ response_model=request_model,+ )+ metrics['genai_client_usage_tokens'].record(+ input_tokens, attributes+ )+ metrics['genai_client_operation_duration'].record(+ end_time - start_time, attributes+ )+ metrics['genai_requests'].add(1, attributes)+ metrics['genai_prompt_tokens'].add(input_tokens, attributes)+ metrics['genai_cost'].record(cost, attributes)++ # Return original response+ return response++ except Exception as e:+ handle_exception(span, e)++ # Return original response+ return responsediff --git a/sdk/python/src/openlit/instrumentation/openai/__init__.py b/sdk/python/src/openlit/instrumentation/openai/__init__.pyindex 112675d6..51df68fd 100644--- a/sdk/python/src/openlit/instrumentation/openai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/openai/__init__.py@@ -25,7 +25,7 @@ class OpenAIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("openai")@@ -33,7 +33,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.chat.completions","Completions.create",chat_completions(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -41,7 +41,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.chat.completions","AsyncCompletions.create",async_chat_completions(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -49,7 +49,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.images","Images.generate",image_generate(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -57,7 +57,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.images","AsyncImages.generate",async_image_generate(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -65,7 +65,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.embeddings","Embeddings.create",embedding(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -73,7 +73,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.embeddings","AsyncEmbeddings.create",async_embedding(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -82,7 +82,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"Images.create_variation",image_variatons(version,environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -91,7 +91,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"AsyncImages.create_variation",async_image_variatons(version,environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -99,7 +99,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.audio.speech","Speech.create",audio_create(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)@@ -107,7 +107,7 @@ class OpenAIInstrumentor(BaseInstrumentor):"openai.resources.audio.speech","AsyncSpeech.create",async_audio_create(version, environment, application_name,- tracer, pricing_info, trace_content,+ tracer, pricing_info, capture_message_content,metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/openai/async_openai.py b/sdk/python/src/openlit/instrumentation/openai/async_openai.pyindex 8ec408b0..8ddb7846 100644--- a/sdk/python/src/openlit/instrumentation/openai/async_openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/async_openai.py@@ -25,7 +25,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_chat_completions(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -35,7 +35,7 @@ def async_chat_completions(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -229,7 +229,7 @@ def async_chat_completions(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -387,7 +387,7 @@ def async_chat_completions(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SERVICE_TIER,response_dict.get('service_tier'))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,- response_dict.get('system_fingerprint'))+ response_dict.get('system_fingerprint', ''))# Set base span attribues (Extras)span.set_attribute(DEPLOYMENT_ENVIRONMENT,@@ -406,7 +406,7 @@ def async_chat_completions(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -417,7 +417,7 @@ def async_chat_completions(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -477,7 +477,7 @@ def async_chat_completions(version, environment, application_name,return wrapperdef async_embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -487,7 +487,7 @@ def async_embedding(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -561,7 +561,7 @@ def async_embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -605,7 +605,7 @@ def async_embedding(version, environment, application_name,return wrapperdef async_image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for image generation to collect metrics.@@ -615,7 +615,7 @@ def async_image_generate(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI image generation.- trace_content: Flag indicating whether to trace the input prompt and generated images.+ capture_message_content: Flag indicating whether to trace the input prompt and generated images.Returns:A function that wraps the image generation method to add telemetry.@@ -700,7 +700,7 @@ def async_image_generate(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -752,7 +752,7 @@ def async_image_generate(version, environment, application_name,return wrapperdef async_image_variatons(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating image variations to collect metrics.@@ -762,7 +762,7 @@ def async_image_variatons(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating image variations.- trace_content: Flag indicating whether to trace the input image and generated variations.+ capture_message_content: Flag indicating whether to trace the input image and generated variations.Returns:A function that wraps the image variations creation method to add telemetry.@@ -842,7 +842,7 @@ def async_image_variatons(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:attribute_name = f"{SemanticConvetion.GEN_AI_RESPONSE_IMAGE}.{images_count}"span.add_event(name=attribute_name,@@ -888,7 +888,7 @@ def async_image_variatons(version, environment, application_name,return wrapperdef async_audio_create(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating speech audio to collect metrics.@@ -898,7 +898,7 @@ def async_audio_create(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating speech audio.- trace_content: Flag indicating whether to trace the input text and generated audio.+ capture_message_content: Flag indicating whether to trace the input text and generated audio.Returns:A function that wraps the speech audio creation method to add telemetry.@@ -967,7 +967,7 @@ def async_audio_create(version, environment, application_name,cost)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/openai/openai.py b/sdk/python/src/openlit/instrumentation/openai/openai.pyindex 8c6378c4..3251b053 100644--- a/sdk/python/src/openlit/instrumentation/openai/openai.py+++ b/sdk/python/src/openlit/instrumentation/openai/openai.py@@ -25,7 +25,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def chat_completions(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -35,7 +35,7 @@ def chat_completions(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -229,7 +229,7 @@ def chat_completions(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -387,7 +387,7 @@ def chat_completions(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SERVICE_TIER,response_dict.get('service_tier'))span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,- response_dict.get('system_fingerprint'))+ str(response_dict.get('system_fingerprint', '')))# Set base span attribues (Extras)span.set_attribute(DEPLOYMENT_ENVIRONMENT,@@ -406,7 +406,7 @@ def chat_completions(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -417,7 +417,7 @@ def chat_completions(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[response_dict.get('choices')[i].get('finish_reason')])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -477,7 +477,7 @@ def chat_completions(version, environment, application_name,return wrapperdef embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -487,7 +487,7 @@ def embedding(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -561,7 +561,7 @@ def embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -605,7 +605,7 @@ def embedding(version, environment, application_name,return wrapperdef image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for image generation to collect metrics.@@ -615,7 +615,7 @@ def image_generate(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of OpenAI image generation.- trace_content: Flag indicating whether to trace the input prompt and generated images.+ capture_message_content: Flag indicating whether to trace the input prompt and generated images.Returns:A function that wraps the image generation method to add telemetry.@@ -700,7 +700,7 @@ def image_generate(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -752,7 +752,7 @@ def image_generate(version, environment, application_name,return wrapperdef image_variatons(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating image variations to collect metrics.@@ -762,7 +762,7 @@ def image_variatons(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating image variations.- trace_content: Flag indicating whether to trace the input image and generated variations.+ capture_message_content: Flag indicating whether to trace the input image and generated variations.Returns:A function that wraps the image variations creation method to add telemetry.@@ -842,7 +842,7 @@ def image_variatons(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:attribute_name = f"{SemanticConvetion.GEN_AI_RESPONSE_IMAGE}.{images_count}"span.add_event(name=attribute_name,@@ -888,7 +888,7 @@ def image_variatons(version, environment, application_name,return wrapperdef audio_create(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for creating speech audio to collect metrics.@@ -898,7 +898,7 @@ def audio_create(version, environment, application_name,application_name: Name of the application using the OpenAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of generating speech audio.- trace_content: Flag indicating whether to trace the input text and generated audio.+ capture_message_content: Flag indicating whether to trace the input text and generated audio.Returns:A function that wraps the speech audio creation method to add telemetry.@@ -967,7 +967,7 @@ def audio_create(version, environment, application_name,cost)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/phidata/__init__.py b/sdk/python/src/openlit/instrumentation/phidata/__init__.pyindex 03ee5657..ea6c433f 100644--- a/sdk/python/src/openlit/instrumentation/phidata/__init__.py+++ b/sdk/python/src/openlit/instrumentation/phidata/__init__.py@@ -26,7 +26,7 @@ class PhidataInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("phidata")@@ -34,7 +34,7 @@ class PhidataInstrumentor(BaseInstrumentor):"phi.agent","Agent.print_response",phidata_wrap("phidata.print_response", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/phidata/phidata.py b/sdk/python/src/openlit/instrumentation/phidata/phidata.pyindex f18dd444..17443a22 100644--- a/sdk/python/src/openlit/instrumentation/phidata/phidata.py+++ b/sdk/python/src/openlit/instrumentation/phidata/phidata.py@@ -15,7 +15,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def phidata_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -26,7 +26,7 @@ def phidata_wrap(gen_ai_endpoint, version, environment, application_name,application_name: Name of the application using the Phidata Agent.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Phidata usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.diff --git a/sdk/python/src/openlit/instrumentation/pinecone/__init__.py b/sdk/python/src/openlit/instrumentation/pinecone/__init__.pyindex 5b9741d1..2575bf85 100644--- a/sdk/python/src/openlit/instrumentation/pinecone/__init__.py+++ b/sdk/python/src/openlit/instrumentation/pinecone/__init__.py@@ -21,7 +21,7 @@ class PineconeInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("pinecone-client")@@ -29,35 +29,35 @@ class PineconeInstrumentor(BaseInstrumentor):"pinecone.control.pinecone","Pinecone.create_index",general_wrap("pinecone.create_index", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("pinecone.data.index","Index.upsert",general_wrap("pinecone.upsert", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("pinecone.data.index","Index.query",general_wrap("pinecone.query", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("pinecone.data.index","Index.update",general_wrap("pinecone.update", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("pinecone.data.index","Index.delete",general_wrap("pinecone.delete", version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.pyindex 6f44dc2b..212e59fb 100644--- a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py+++ b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py@@ -23,7 +23,7 @@ def object_count(obj):return Nonedef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Wraps a Pinecone operation to trace and log its execution metrics.@@ -40,7 +40,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): The name of the application performing the Pinecone operation.- tracer (opentelemetry.trace.Tracer): An object used for OpenTelemetry tracing.- pricing_info (dict): Information about pricing, not used in current implementation.- - trace_content (bool): A flag indicating whether the content of responses should be traced.+ - capture_message_content (bool): A flag indicating whether the content of responses should be traced.Returns:- function: A decorator function that, when applied, wraps the target function withdiff --git a/sdk/python/src/openlit/instrumentation/premai/__init__.py b/sdk/python/src/openlit/instrumentation/premai/__init__.pyindex ca1218db..bd22aea1 100644--- a/sdk/python/src/openlit/instrumentation/premai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/premai/__init__.py@@ -26,7 +26,7 @@ class PremAIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("premai")@@ -35,7 +35,7 @@ class PremAIInstrumentor(BaseInstrumentor):"premai.api","ChatCompletionsModule.create",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# sync embedding@@ -43,7 +43,7 @@ class PremAIInstrumentor(BaseInstrumentor):"premai.api","EmbeddingsModule.create",embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/premai/premai.py b/sdk/python/src/openlit/instrumentation/premai/premai.pyindex 20469b98..955532a7 100644--- a/sdk/python/src/openlit/instrumentation/premai/premai.py+++ b/sdk/python/src/openlit/instrumentation/premai/premai.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -32,7 +32,7 @@ def chat(version, environment, application_name,application_name: Name of the application using the PremAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of PremAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -199,7 +199,7 @@ def chat(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -363,7 +363,7 @@ def chat(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -429,7 +429,7 @@ def chat(version, environment, application_name,return wrapperdef embedding(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for embeddings to collect metrics.@@ -439,7 +439,7 @@ def embedding(version, environment, application_name,application_name: Name of the application using the PremAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of PremAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the embeddings method to add telemetry.@@ -512,7 +512,7 @@ def embedding(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/qdrant/__init__.py b/sdk/python/src/openlit/instrumentation/qdrant/__init__.pyindex 90a58f0c..8cff3cd4 100644--- a/sdk/python/src/openlit/instrumentation/qdrant/__init__.py+++ b/sdk/python/src/openlit/instrumentation/qdrant/__init__.py@@ -273,7 +273,7 @@ class QdrantInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("qdrant-client")@@ -286,7 +286,7 @@ class QdrantInstrumentor(BaseInstrumentor):wrap_package,wrap_object,wrapper(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)diff --git a/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py b/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.pyindex e0abf62c..24d213ee 100644--- a/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py+++ b/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py@@ -25,7 +25,7 @@ def object_count(obj):return cntdef async_general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -39,7 +39,7 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.pyindex efe99962..4a07a51d 100644--- a/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py+++ b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py@@ -25,7 +25,7 @@ def object_count(obj):return cntdef general_wrap(gen_ai_endpoint, version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -39,7 +39,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returnsdiff --git a/sdk/python/src/openlit/instrumentation/reka/__init__.py b/sdk/python/src/openlit/instrumentation/reka/__init__.pyindex ef6f36eb..ff1a6495 100644--- a/sdk/python/src/openlit/instrumentation/reka/__init__.py+++ b/sdk/python/src/openlit/instrumentation/reka/__init__.py@@ -29,7 +29,7 @@ class RekaInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("reka-api")@@ -38,7 +38,7 @@ class RekaInstrumentor(BaseInstrumentor):"reka.chat.client","ChatClient.create",chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# async chat@@ -46,7 +46,7 @@ class RekaInstrumentor(BaseInstrumentor):"reka.chat.client","AsyncChatClient.create",async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/reka/async_reka.py b/sdk/python/src/openlit/instrumentation/reka/async_reka.pyindex 791ebcd0..e35fc077 100644--- a/sdk/python/src/openlit/instrumentation/reka/async_reka.py+++ b/sdk/python/src/openlit/instrumentation/reka/async_reka.py@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -28,7 +28,7 @@ def async_chat(version, environment, application_name,application_name: Name of the application using the Reka API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Reka usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -142,7 +142,7 @@ def async_chat(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/reka/reka.py b/sdk/python/src/openlit/instrumentation/reka/reka.pyindex dd93e376..755f799c 100644--- a/sdk/python/src/openlit/instrumentation/reka/reka.py+++ b/sdk/python/src/openlit/instrumentation/reka/reka.py@@ -18,7 +18,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def chat(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat to collect metrics.@@ -28,7 +28,7 @@ def chat(version, environment, application_name,application_name: Name of the application using the Reka API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Reka usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -142,7 +142,7 @@ def chat(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/together/__init__.py b/sdk/python/src/openlit/instrumentation/together/__init__.pyindex 67f9398f..a60c5af9 100644--- a/sdk/python/src/openlit/instrumentation/together/__init__.py+++ b/sdk/python/src/openlit/instrumentation/together/__init__.py@@ -29,7 +29,7 @@ class TogetherInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("together")@@ -38,7 +38,7 @@ class TogetherInstrumentor(BaseInstrumentor):"together.resources.chat.completions","ChatCompletions.create",completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Image generate@@ -46,7 +46,7 @@ class TogetherInstrumentor(BaseInstrumentor):"together.resources.images","Images.generate",image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Chat completions@@ -54,7 +54,7 @@ class TogetherInstrumentor(BaseInstrumentor):"together.resources.chat.completions","AsyncChatCompletions.create",async_completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)# Image generate@@ -62,7 +62,7 @@ class TogetherInstrumentor(BaseInstrumentor):"together.resources.images","AsyncImages.generate",async_image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/together/async_together.py b/sdk/python/src/openlit/instrumentation/together/async_together.pyindex 7c1905ff..8fd20a03 100644--- a/sdk/python/src/openlit/instrumentation/together/async_together.py+++ b/sdk/python/src/openlit/instrumentation/together/async_together.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -32,7 +32,7 @@ def async_completion(version, environment, application_name,application_name: Name of the application using the Together AI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Together AI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -218,7 +218,7 @@ def async_completion(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -388,7 +388,7 @@ def async_completion(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -399,7 +399,7 @@ def async_completion(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[str(response_dict.get('choices')[i].get('finish_reason'))])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -459,7 +459,7 @@ def async_completion(version, environment, application_name,return wrapperdef async_image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for image generation to collect metrics.@@ -469,7 +469,7 @@ def async_image_generate(version, environment, application_name,application_name: Name of the application using the Together AI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Together AI image generation.- trace_content: Flag indicating whether to trace the input prompt and generated images.+ capture_message_content: Flag indicating whether to trace the input prompt and generated images.Returns:A function that wraps the image generation method to add telemetry.@@ -548,7 +548,7 @@ def async_image_generate(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/together/together.py b/sdk/python/src/openlit/instrumentation/together/together.pyindex a19ebe8e..cd775962 100644--- a/sdk/python/src/openlit/instrumentation/together/together.py+++ b/sdk/python/src/openlit/instrumentation/together/together.py@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def completion(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for chat completions to collect metrics.@@ -32,7 +32,7 @@ def completion(version, environment, application_name,application_name: Name of the application using the Together AI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Together AI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat completions method to add telemetry.@@ -218,7 +218,7 @@ def completion(version, environment, application_name,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -388,7 +388,7 @@ def completion(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -399,7 +399,7 @@ def completion(version, environment, application_name,for i in range(kwargs.get('n',1)):span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,[str(response_dict.get('choices')[i].get('finish_reason'))])- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,attributes={@@ -459,7 +459,7 @@ def completion(version, environment, application_name,return wrapperdef image_generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for image generation to collect metrics.@@ -469,7 +469,7 @@ def image_generate(version, environment, application_name,application_name: Name of the application using the Together AI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of Together AI image generation.- trace_content: Flag indicating whether to trace the input prompt and generated images.+ capture_message_content: Flag indicating whether to trace the input prompt and generated images.Returns:A function that wraps the image generation method to add telemetry.@@ -548,7 +548,7 @@ def image_generate(version, environment, application_name,span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/transformers/__init__.py b/sdk/python/src/openlit/instrumentation/transformers/__init__.pyindex 6ad105fb..d38d8f47 100644--- a/sdk/python/src/openlit/instrumentation/transformers/__init__.py+++ b/sdk/python/src/openlit/instrumentation/transformers/__init__.py@@ -21,7 +21,7 @@ class TransformersInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info")- trace_content = kwargs.get("trace_content")+ capture_message_content = kwargs.get("capture_message_content")disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("transformers")@@ -29,7 +29,7 @@ class TransformersInstrumentor(BaseInstrumentor):"transformers","TextGenerationPipeline.__call__",text_wrap(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)@staticmethoddiff --git a/sdk/python/src/openlit/instrumentation/transformers/transformers.py b/sdk/python/src/openlit/instrumentation/transformers/transformers.pyindex 9d9dd739..8a1550c8 100644--- a/sdk/python/src/openlit/instrumentation/transformers/transformers.py+++ b/sdk/python/src/openlit/instrumentation/transformers/transformers.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def text_wrap(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Creates a wrapper around a function call to trace and log its execution metrics.@@ -32,7 +32,7 @@ def text_wrap(version, environment, application_name,- application_name (str): Name of the Langchain application.- tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.- pricing_info (dict): Information about the pricing for internal metrics (currently not used).- - trace_content (bool): Flag indicating whether to trace the content of the response.+ - capture_message_content (bool): Flag indicating whether to trace the content of the response.Returns:- function: A higher-order function that takes a function 'wrapped' and returns@@ -113,7 +113,7 @@ def text_wrap(version, environment, application_name,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -128,7 +128,7 @@ def text_wrap(version, environment, application_name,attribute_name = f"gen_ai.content.completion.{i}"else:attribute_name = SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT- if trace_content:+ if capture_message_content:# pylint: disable=bare-excepttry:llm_response = completion.get('generated_text', '')diff --git a/sdk/python/src/openlit/instrumentation/vertexai/__init__.py b/sdk/python/src/openlit/instrumentation/vertexai/__init__.pyindex 24901f68..a7ba0b94 100644--- a/sdk/python/src/openlit/instrumentation/vertexai/__init__.py+++ b/sdk/python/src/openlit/instrumentation/vertexai/__init__.py@@ -30,7 +30,7 @@ class VertexAIInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("google-cloud-aiplatform")@@ -39,28 +39,28 @@ class VertexAIInstrumentor(BaseInstrumentor):"vertexai.generative_models","GenerativeModel.generate_content",send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.generative_models","ChatSession.send_message",send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.language_models","ChatSession.send_message",send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.language_models","ChatSession.send_message_streaming",send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)#async@@ -68,28 +68,28 @@ class VertexAIInstrumentor(BaseInstrumentor):"vertexai.generative_models","GenerativeModel.generate_content_async",async_send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.generative_models","ChatSession.send_message_async",async_send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.language_models","ChatSession.send_message_async",async_send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)wrap_function_wrapper("vertexai.language_models","ChatSession.send_message_streaming_async",async_send_message(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.pyindex e9900578..aa232ae4 100644--- a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py+++ b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def async_send_message(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for messages to collect metrics.@@ -29,7 +29,7 @@ def async_send_message(version, environment, application_name, tracer,application_name: Name of the application using the VertexAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of VertexAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -200,7 +200,7 @@ def async_send_message(version, environment, application_name, tracer,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -397,7 +397,7 @@ def async_send_message(version, environment, application_name, tracer,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.pyindex 9ba2fc89..12ca4c51 100644--- a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py+++ b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def send_message(version, environment, application_name, tracer,- pricing_info, trace_content, metrics, disable_metrics):+ pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for messages to collect metrics.@@ -29,7 +29,7 @@ def send_message(version, environment, application_name, tracer,application_name: Name of the application using the VertexAI API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of VertexAI usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the chat method to add telemetry.@@ -200,7 +200,7 @@ def send_message(version, environment, application_name, tracer,self._ttft)self._span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:self._span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={@@ -397,7 +397,7 @@ def send_message(version, environment, application_name, tracer,end_time - start_time)span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,version)- if trace_content:+ if capture_message_content:span.add_event(name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,attributes={diff --git a/sdk/python/src/openlit/instrumentation/vllm/__init__.py b/sdk/python/src/openlit/instrumentation/vllm/__init__.pyindex 337a79a6..acd3b083 100644--- a/sdk/python/src/openlit/instrumentation/vllm/__init__.py+++ b/sdk/python/src/openlit/instrumentation/vllm/__init__.py@@ -26,7 +26,7 @@ class VLLMInstrumentor(BaseInstrumentor):tracer = kwargs.get("tracer")metrics = kwargs.get("metrics_dict")pricing_info = kwargs.get("pricing_info", {})- trace_content = kwargs.get("trace_content", False)+ capture_message_content = kwargs.get("capture_message_content", False)disable_metrics = kwargs.get("disable_metrics")version = importlib.metadata.version("vllm")@@ -35,7 +35,7 @@ class VLLMInstrumentor(BaseInstrumentor):"vllm","LLM.generate",generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics),+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),)def _uninstrument(self, **kwargs):diff --git a/sdk/python/src/openlit/instrumentation/vllm/vllm.py b/sdk/python/src/openlit/instrumentation/vllm/vllm.pyindex 7e6facc7..5d884c76 100644--- a/sdk/python/src/openlit/instrumentation/vllm/vllm.py+++ b/sdk/python/src/openlit/instrumentation/vllm/vllm.py@@ -19,7 +19,7 @@ from openlit.semcov import SemanticConvetionlogger = logging.getLogger(__name__)def generate(version, environment, application_name,- tracer, pricing_info, trace_content, metrics, disable_metrics):+ tracer, pricing_info, capture_message_content, metrics, disable_metrics):"""Generates a telemetry wrapper for generate to collect metrics.@@ -29,7 +29,7 @@ def generate(version, environment, application_name,application_name: Name of the application using the vLLM API.tracer: OpenTelemetry tracer for creating spans.pricing_info: Information used for calculating the cost of vLLM usage.- trace_content: Flag indicating whether to trace the actual content.+ capture_message_content: Flag indicating whether to trace the actual content.Returns:A function that wraps the generate method to add telemetry.@@ -97,7 +97,7 @@ def generate(version, environment, application_name,output_tokens = 0cost = 0- if trace_content:+ if capture_message_content:prompt_attributes = {}completion_attributes = {}diff --git a/sdk/python/src/openlit/otel/events.py b/sdk/python/src/openlit/otel/events.pynew file mode 100644index 00000000..1eb782b2--- /dev/null+++ b/sdk/python/src/openlit/otel/events.py@@ -0,0 +1,85 @@+"""+Setups up OpenTelemetry events emitter+"""++import os+from opentelemetry import _events, _logs+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT+from opentelemetry.sdk.resources import Resource+from opentelemetry.sdk._events import EventLoggerProvider+from opentelemetry.sdk._logs.export import BatchLogRecordProcessor, SimpleLogRecordProcessor+from opentelemetry.sdk._logs import LoggerProvider+from opentelemetry.sdk._logs.export import ConsoleLogExporter++if os.environ.get("OTEL_EXPORTER_OTLP_PROTOCOL") == "grpc":+ from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter+else:+ from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter++# Global flag to check if the events provider initialization is complete.+EVENTS_SET = False++def setup_events(application_name, environment, event_logger, otlp_endpoint, otlp_headers, disable_batch):+ """Setup OpenTelemetry events with the given configuration.++ Args:+ application_name: Name of the application+ environment: Deployment environment+ event_logger: Optional pre-configured event logger provider+ otlp_endpoint: Optional OTLP endpoint for exporter+ otlp_headers: Optional headers for OTLP exporter++ Returns:+ EventLoggerProvider: The configured event logger provider+ """+ # If an external events_logger is provided, return it immediately.+ if event_logger:+ return event_logger++ # Proceed with setting up a new events or configuration only if EVENTS_SET is False.+ global EVENTS_SET++ try:+ if not EVENTS_SET:+ # Create resource with service and environment information+ resource = Resource.create(attributes={+ SERVICE_NAME: application_name,+ DEPLOYMENT_ENVIRONMENT: environment,+ TELEMETRY_SDK_NAME: "openlit"}+ )++ # Initialize the LoggerProvider with the created resource.+ logger_provider = LoggerProvider(resource=resource)++ # Only set environment variables if you have a non-None value.+ if otlp_endpoint is not None:+ os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = otlp_endpoint++ if otlp_headers is not None:+ if isinstance(otlp_headers, dict):+ headers_str = ','.join(f"{key}={value}" for key, value in otlp_headers.items())+ else:+ headers_str = otlp_headers++ os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = headers_str++ # Configure the span exporter and processor based on whether the endpoint is effectively set.+ if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):+ event_exporter = OTLPLogExporter()+ # pylint: disable=line-too-long+ logger_provider.add_log_record_processor(SimpleLogRecordProcessor(event_exporter)) if disable_batch else logger_provider.add_log_record_processor(BatchLogRecordProcessor(event_exporter))+ else:+ event_exporter = ConsoleLogExporter()+ logger_provider.add_log_record_processor(SimpleLogRecordProcessor(event_exporter))++ _logs.set_logger_provider(logger_provider)+ event_provider = EventLoggerProvider()+ _events.set_event_logger_provider(event_provider)++ EVENTS_SET = True++ return _events.get_event_logger(__name__)++ # pylint: disable=bare-except+ except:+ return Nonediff --git a/sdk/python/src/openlit/otel/tracing.py b/sdk/python/src/openlit/otel/tracing.pyindex d49017e8..a2aa9345 100644--- a/sdk/python/src/openlit/otel/tracing.py+++ b/sdk/python/src/openlit/otel/tracing.py@@ -1,4 +1,3 @@-# pylint: disable=duplicate-code, line-too-long, ungrouped-imports"""Setups up OpenTelemetry tracer"""@@ -21,17 +20,8 @@ TRACER_SET = Falsedef setup_tracing(application_name, environment, tracer, otlp_endpoint, otlp_headers, disable_batch):"""- Sets up tracing with OpenTelemetry. Initializes the tracer provider and configures the span processor and exporter.-- Params:- application_name (str): The name of the application to be used in traces.- tracer (Tracer): Optional custom tracer. If provided, it is immediately returned and no setup is performed.- otlp_endpoint (str): The OTLP exporter endpoint. Falls back to the OTEL_EXPORTER_OTLP_ENDPOINT environment variable if not specified.- otlp_headers (dict): Headers for the OTLP request. Falls back to the OTEL_EXPORTER_OTLP_HEADERS environment variable if not specified.- disable_batch (bool): Flag to disable the batch span processor in favor of a simpler processor for exporting.-- Returns:- The provided custom tracer if not None; otherwise, a tracer instance configured according to the given parameters or environment variables.+ Sets up tracing with OpenTelemetry.+ Initializes the tracer provider and configures the span processor and exporter."""# If an external tracer is provided, return it immediately.@@ -72,7 +62,7 @@ def setup_tracing(application_name, environment, tracer, otlp_endpoint, otlp_hea# Configure the span exporter and processor based on whether the endpoint is effectively set.if os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):span_exporter = OTLPSpanExporter()-+ # pylint: disable=line-too-longspan_processor = BatchSpanProcessor(span_exporter) if not disable_batch else SimpleSpanProcessor(span_exporter)else:span_exporter = ConsoleSpanExporter()diff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.pyindex 84abc899..0d4300e5 100644--- a/sdk/python/src/openlit/semcov/__init__.py+++ b/sdk/python/src/openlit/semcov/__init__.py@@ -28,6 +28,13 @@ class SemanticConvetion:GEN_AI_SERVER_TBT = "gen_ai.server.time_per_output_token"GEN_AI_SERVER_TTFT = "gen_ai.server.time_to_first_token"+ # GenAI Event Names (OTel Semconv)+ GEN_AI_USER_MESSAGE = "gen_ai.user.message"+ GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message"+ GEN_AI_ASSISTANT_MESSAGE = "gen_ai.assistant.message"+ GEN_AI_TOOL_MESSAGE = "gen_ai.tools.message"+ GEN_AI_CHOICE = "gen_ai.choice"+# GenAI Request Attributes (OTel Semconv)GEN_AI_OPERATION = "gen_ai.operation.name"GEN_AI_SYSTEM = "gen_ai.system"@@ -64,6 +71,7 @@ class SemanticConvetion:GEN_AI_OPERATION_TYPE_FRAMEWORK = "framework"GEN_AI_OPERATION_TYPE_AGENT = "agent"GEN_AI_OPERATION_TYPE_CREATE_AGENT = "create_agent"+ GEN_AI_OPERATION_TYPE_EXECUTE_AGENT_TASK = "execute_task"# GenAI Output Types (OTel Semconv)GEN_AI_OUTPUT_TYPE_IMAGE = "image"@@ -221,8 +229,12 @@ class SemanticConvetion:DB_SYSTEM_MILVUS = "milvus"DB_SYSTEM_ASTRA = "astra"- # Agents+ # GenAI Request Attributes (OTel Semconv)GEN_AI_AGENT_ID = "gen_ai.agent.id"+ GEN_AI_AGENT_NAME = "gen_ai.agent.name"+ GEN_AI_AGENT_DESCRIPTION = "gen_ai.agent.description"++GEN_AI_AGENT_TYPE = "gen_ai.agent.type"GEN_AI_AGENT_TASK_ID = "gen_ai.agent.task.id"GEN_AI_AGENT_ROLE = "gen_ai.agent.role"diff --git a/sdk/python/tests/test_ai21.py b/sdk/python/tests/test_ai21.pyindex 32f76071..70fc1b60 100644--- a/sdk/python/tests/test_ai21.py+++ b/sdk/python/tests/test_ai21.py@@ -43,7 +43,7 @@ def test_sync_ai21_chat():model="jamba-1.5-mini",max_tokens=1,)- assert isinstance(response.id, str)+ assert isinstance(response['id'], str)def test_sync_ai21_chat_stream():"""@@ -80,7 +80,7 @@ def test_sync_ai21_chat_rag():max_neighbors=1,max_tokens=1,)- assert isinstance(response.id, str)+ assert isinstance(response['id'], str)@pytest.mark.asyncioasync def test_async_ai21_test():@@ -96,7 +96,7 @@ async def test_async_ai21_test():model="jamba-1.5-mini",max_tokens=1,)- assert isinstance(response.id, str)+ assert isinstance(response['id'], str)responses = await async_client.chat.completions.create(messages=MESSAGES,@@ -117,4 +117,4 @@ async def test_async_ai21_test():max_neighbors=1,max_tokens=1,)- assert isinstance(response.id, str)+ assert isinstance(response['id'], str)