Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Feat]: Use Events API for Assembly Instrumentations (#647)

Patcher5a2a283f42d8
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 803f1884..90e44dd7 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.33.13"
+version = "1.33.14"
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/instrumentation/assemblyai/__init__.py b/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py
index 8f3c25d7..d17a01b2 100644
--- a/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/assemblyai/__init__.py
@@ -1,4 +1,3 @@
-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
"""Initializer of Auto Instrumentation of AssemblyAI Functions"""
from typing import Collection
@@ -10,7 +9,7 @@ from openlit.instrumentation.assemblyai.assemblyai import (
transcribe
)
-_instruments = ("assemblyai >= 0.35.1",)
+_instruments = ('assemblyai >= 0.35.1',)
class AssemblyAIInstrumentor(BaseInstrumentor):
"""
@@ -21,21 +20,22 @@ class AssemblyAIInstrumentor(BaseInstrumentor):
return _instruments
def _instrument(self, **kwargs):
- application_name = kwargs.get("application_name", "default")
- environment = kwargs.get("environment", "default")
- tracer = kwargs.get("tracer")
- metrics = kwargs.get("metrics_dict")
- pricing_info = kwargs.get("pricing_info", {})
- capture_message_content = kwargs.get("capture_message_content", False)
- disable_metrics = kwargs.get("disable_metrics")
- version = importlib.metadata.version("assemblyai")
+ application_name = kwargs.get('application_name', 'default')
+ environment = kwargs.get('environment', 'default')
+ tracer = kwargs.get('tracer')
+ event_provider = kwargs.get('event_provider')
+ metrics = kwargs.get('metrics_dict')
+ pricing_info = kwargs.get('pricing_info', {})
+ capture_message_content = kwargs.get('capture_message_content', False)
+ disable_metrics = kwargs.get('disable_metrics')
+ version = importlib.metadata.version('assemblyai')
# sync transcribe
wrap_function_wrapper(
- "assemblyai.transcriber",
- "Transcriber.transcribe",
+ 'assemblyai.transcriber',
+ 'Transcriber.transcribe',
transcribe(version, environment, application_name,
- tracer, pricing_info, capture_message_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/assemblyai/assemblyai.py b/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py
index aabcce39..e3409f7a 100644
--- a/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py
+++ b/sdk/python/src/openlit/instrumentation/assemblyai/assemblyai.py
@@ -10,7 +10,8 @@ from openlit.__helpers import (
get_audio_model_cost,
handle_exception,
create_metrics_attributes,
- set_server_address_and_port
+ set_server_address_and_port,
+ otel_event
)
from openlit.semcov import SemanticConvetion
@@ -18,38 +19,15 @@ from openlit.semcov import SemanticConvetion
logger = logging.getLogger(__name__)
def transcribe(version, environment, application_name,
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
+ tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):
"""
- Generates a telemetry wrapper for creating speech audio to collect metrics.
-
- Args:
- gen_ai_endpoint: Endpoint identifier for logging and tracing.
- version: Version of the monitoring package.
- environment: Deployment environment (e.g., production, staging).
- 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.
- 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.
+ Generates a telemetry wrapper for GenAI function call
"""
+
def wrapper(wrapped, instance, args, kwargs):
"""
- Wraps the 'generate' API call to add telemetry.
-
- This collects metrics such as execution time, cost, and handles errors
- gracefully, adding details to the trace for observability.
-
- Args:
- wrapped: The original 'generate' method to be wrapped.
- instance: The instance of the class where the original method is defined.
- args: Positional arguments for the 'generate' method.
- kwargs: Keyword arguments for the 'generate' method.
-
- Returns:
- The response from the original 'transcribe' method.
+ Wraps the GenAI function call.
"""
server_address, server_port = set_server_address_and_port(instance, 'api.assemblyai.com', 443)
@@ -96,6 +74,7 @@ def transcribe(version, environment, application_name,
span.set_attribute(SemanticConvetion.GEN_AI_SDK_VERSION,
version)
+ # To be removed one the change to log events (from span events) is complete
if capture_message_content:
span.add_event(
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
@@ -110,6 +89,34 @@ def transcribe(version, environment, application_name,
},
)
+ input_event = otel_event(
+ name=SemanticConvetion.GEN_AI_USER_MESSAGE,
+ attributes={
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI
+ },
+ body={
+ **({'content': response.audio_url} if capture_message_content else {}),
+ 'role': 'user'
+ }
+ )
+ event_provider.emit(input_event)
+
+ output_event = otel_event(
+ name=SemanticConvetion.GEN_AI_CHOICE,
+ attributes={
+ SemanticConvetion.GEN_AI_SYSTEM: SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI
+ },
+ body={
+ 'finish_reason': 'stop',
+ 'index': 0,
+ 'message': {
+ **({'content': response.text} if capture_message_content else {}),
+ 'role': 'assistant'
+ }
+ }
+ )
+ event_provider.emit(output_event)
+
span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
diff --git a/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py b/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py
index 165d6f29..d946b80d 100644
--- a/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/azure_ai_inference/__init__.py
@@ -1,4 +1,3 @@
-# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
"""Initializer of Auto Instrumentation of Azure AI Inference Functions"""
from typing import Collection
@@ -14,7 +13,7 @@ from openlit.instrumentation.azure_ai_inference.async_azure_ai_inference import
async_complete, async_embedding
)
-_instruments = ("azure-ai-inference >= 1.0.0b4",)
+_instruments = ('azure-ai-inference >= 1.0.0b4',)
class AzureAIInferenceInstrumentor(BaseInstrumentor):
"""
@@ -25,43 +24,43 @@ class AzureAIInferenceInstrumentor(BaseInstrumentor):
return _instruments
def _instrument(self, **kwargs):
- application_name = kwargs.get("application_name", "default_application")
- environment = kwargs.get("environment", "default_environment")
- tracer = kwargs.get("tracer")
- metrics = kwargs.get("metrics_dict")
- pricing_info = kwargs.get("pricing_info", {})
- capture_message_content = kwargs.get("capture_message_content", False)
- disable_metrics = kwargs.get("disable_metrics")
- version = importlib.metadata.version("azure-ai-inference")
+ application_name = kwargs.get('application_name', 'default')
+ environment = kwargs.get('environment', 'default')
+ tracer = kwargs.get('tracer')
+ metrics = kwargs.get('metrics_dict')
+ pricing_info = kwargs.get('pricing_info', {})
+ capture_message_content = kwargs.get('capture_message_content', False)
+ disable_metrics = kwargs.get('disable_metrics')
+ version = importlib.metadata.version('azure-ai-inference')
# sync generate
wrap_function_wrapper(
- "azure.ai.inference",
- "ChatCompletionsClient.complete",
+ 'azure.ai.inference',
+ 'ChatCompletionsClient.complete',
complete(version, environment, application_name,
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
# sync embedding
wrap_function_wrapper(
- "azure.ai.inference",
- "EmbeddingsClient.embed",
+ 'azure.ai.inference',
+ 'EmbeddingsClient.embed',
embedding(version, environment, application_name,
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
# async generate
wrap_function_wrapper(
- "azure.ai.inference.aio",
- "ChatCompletionsClient.complete",
+ 'azure.ai.inference.aio',
+ 'ChatCompletionsClient.complete',
async_complete(version, environment, application_name,
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)
# async embedding
wrap_function_wrapper(
- "azure.ai.inference.aio",
- "EmbeddingsClient.embed",
+ 'azure.ai.inference.aio',
+ 'EmbeddingsClient.embed',
async_embedding(version, environment, application_name,
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
)