Skip to content

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

fix: Dependency issues for opentelemetry semcov library (#1006)

Ishan Jain6866099e0987
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 2595e2b0..ddf0f6ff 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.36.9"
+version = "1.37.0"
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"
@@ -24,7 +24,7 @@ botocore = "^1.34.0"
opentelemetry-api = "^1.30.0"
opentelemetry-sdk = "^1.30.0"
opentelemetry-exporter-otlp = "^1.30.0"
-opentelemetry-semconv = "^0.50b0"
+opentelemetry-semantic-conventions = "^0.60b1"
opentelemetry-instrumentation = ">=0.52b0,<1.0.0"
# Official OpenTelemetry HTTP Framework instrumentations
opentelemetry-instrumentation-asgi = ">=0.52b0,<1.0.0"
diff --git a/sdk/python/src/openlit/semcov/__init__.py b/sdk/python/src/openlit/semcov/__init__.py
index bb6cc132..2664ffe3 100644
--- a/sdk/python/src/openlit/semcov/__init__.py
+++ b/sdk/python/src/openlit/semcov/__init__.py
@@ -49,7 +49,7 @@ try:
HAS_OFFICIAL_OTEL_SEMCONV = True
except ImportError:
- # Fallback if opentelemetry-semconv is not installed
+ # Fallback if opentelemetry-semantic-conventions is not installed
pass
diff --git a/sdk/python/tests/test_groq_trace_comparison.py b/sdk/python/tests/test_groq_trace_comparison.py
deleted file mode 100644
index d82a35ba..00000000
--- a/sdk/python/tests/test_groq_trace_comparison.py
+++ /dev/null
@@ -1,77 +0,0 @@
-# pylint: disable=duplicate-code
-"""
-Cross-Language Trace Comparison Test for Groq
-
-This test generates a trace using Python OpenLIT and exports it for comparison
-with TypeScript traces.
-"""
-
-import os
-import pytest
-from groq import Groq
-from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
-from opentelemetry.sdk.trace import TracerProvider
-import openlit
-
-
-# Initialize OpenLIT with in-memory exporter for testing
-tracer_provider = TracerProvider()
-console_exporter = ConsoleSpanExporter()
-tracer_provider.add_span_processor(SimpleSpanProcessor(console_exporter))
-
-openlit.init(
- environment="openlit-python-testing",
- application_name="openlit-python-groq-test",
- tracer=tracer_provider.get_tracer(__name__),
-)
-
-client = Groq(api_key=os.getenv("GROQ_API_TOKEN"))
-
-
-def test_groq_trace_structure():
- """
- Test that Groq generates traces with expected structure for comparison.
- """
- if not os.getenv("GROQ_API_TOKEN"):
- pytest.skip("GROQ_API_TOKEN not set")
-
- messages = [
- {
- "role": "user",
- "content": "What is LLM Observability?",
- }
- ]
-
- response = client.chat.completions.create(
- messages=messages,
- model="llama-3.1-8b-instant",
- max_tokens=10,
- stream=False,
- )
-
- assert response.object == "chat.completion"
-
-
-def test_groq_trace_metrics():
- """
- Test that Groq trace contains correct metrics.
- """
- if not os.getenv("GROQ_API_TOKEN"):
- pytest.skip("GROQ_API_TOKEN not set")
-
- messages = [{"role": "user", "content": "Test"}]
-
- response = client.chat.completions.create(
- messages=messages,
- model="llama-3.1-8b-instant",
- max_tokens=5,
- stream=False,
- )
-
- # Verify response has usage data
- assert hasattr(response, 'usage')
- assert hasattr(response.usage, 'prompt_tokens')
- assert hasattr(response.usage, 'completion_tokens')
- assert hasattr(response.usage, 'total_tokens')
-
- assert response.object == "chat.completion"
diff --git a/sdk/python/tests/test_mistral_trace_comparison.py b/sdk/python/tests/test_mistral_trace_comparison.py
deleted file mode 100644
index f003c3c3..00000000
--- a/sdk/python/tests/test_mistral_trace_comparison.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# pylint: disable=duplicate-code
-"""
-Cross-Language Trace Comparison Test for Mistral
-
-This test generates a trace using Python OpenLIT and exports it for comparison
-with TypeScript traces.
-"""
-
-import os
-import pytest
-from mistralai import Mistral
-from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
-from opentelemetry.sdk.trace import TracerProvider
-import openlit
-
-
-# Initialize OpenLIT with in-memory exporter for testing
-tracer_provider = TracerProvider()
-console_exporter = ConsoleSpanExporter()
-tracer_provider.add_span_processor(SimpleSpanProcessor(console_exporter))
-
-openlit.init(
- environment="openlit-python-testing",
- application_name="openlit-python-mistral-test",
- tracer=tracer_provider.get_tracer(__name__),
-)
-
-client = Mistral(api_key=os.getenv("MISTRAL_API_KEY"))
-
-
-def test_mistral_trace_structure():
- """
- Test that Mistral generates traces with expected structure for comparison.
- """
- if not os.getenv("MISTRAL_API_KEY"):
- pytest.skip("MISTRAL_API_KEY not set")
-
- messages = [
- {
- "role": "user",
- "content": "What is Mistral AI?",
- }
- ]
-
- response = client.chat.complete(
- model="open-mistral-7b",
- messages=messages,
- max_tokens=10,
- )
-
- # Verify response structure
- assert hasattr(response, 'id')
- assert hasattr(response, 'model')
- assert hasattr(response, 'choices')
- assert hasattr(response, 'usage')
-
-
-def test_mistral_embedding_trace_structure():
- """
- Test that Mistral embeddings generate traces with expected structure.
- """
- if not os.getenv("MISTRAL_API_KEY"):
- pytest.skip("MISTRAL_API_KEY not set")
-
- response = client.embeddings.create(
- model="mistral-embed",
- inputs="Test embedding",
- )
-
- # Verify response structure
- assert hasattr(response, 'model')
- assert hasattr(response, 'data')
- assert hasattr(response, 'usage')
diff --git a/sdk/python/tests/trace_comparison_utils.py b/sdk/python/tests/trace_comparison_utils.py
deleted file mode 100644
index 14b73d6a..00000000
--- a/sdk/python/tests/trace_comparison_utils.py
+++ /dev/null
@@ -1,178 +0,0 @@
-"""
-Python Trace Export Utility for Cross-Language Comparison
-
-This module provides utilities to export Python OpenLIT traces in a format
-that can be compared with TypeScript traces.
-"""
-
-import json
-from typing import Dict, Any
-from opentelemetry.sdk.trace import ReadableSpan
-from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
-
-
-def normalize_python_span(span: ReadableSpan) -> Dict[str, Any]:
- """
- Normalize a Python OpenTelemetry span to a comparable format.
-
- Args:
- span: OpenTelemetry ReadableSpan from Python SDK
-
- Returns:
- Normalized trace dictionary matching TypeScript format
- """
- attributes = {}
- for key, value in span.attributes.items():
- # Normalize arrays
- if isinstance(value, (list, tuple)):
- attributes[key] = sorted(list(value))
- # Normalize numbers (round to 3 decimal places)
- elif isinstance(value, float):
- attributes[key] = round(value * 1000) / 1000
- elif isinstance(value, int):
- attributes[key] = value
- # Normalize strings
- elif isinstance(value, str):
- attributes[key] = value.strip()
- else:
- attributes[key] = value
-
- events = []
- for event in span.events:
- event_attrs = {}
- for key, value in event.attributes.items():
- if isinstance(value, (list, tuple)):
- event_attrs[key] = sorted(list(value))
- elif isinstance(value, float):
- event_attrs[key] = round(value * 1000) / 1000
- elif isinstance(value, int):
- event_attrs[key] = value
- elif isinstance(value, str):
- event_attrs[key] = value.strip()
- else:
- event_attrs[key] = value
-
- events.append({
- 'name': event.name,
- 'attributes': event_attrs,
- })
-
- # Normalize status
- from opentelemetry.trace import StatusCode # pylint: disable=import-outside-toplevel
- status_code = 'UNSET'
- if span.status.status_code == StatusCode.OK:
- status_code = 'OK'
- elif span.status.status_code == StatusCode.ERROR:
- status_code = 'ERROR'
-
- return {
- 'spanName': span.name,
- 'spanKind': str(span.kind),
- 'attributes': attributes,
- 'events': events,
- 'status': {
- 'code': status_code,
- 'message': span.status.description,
- },
- 'duration': span.end_time - span.start_time if span.end_time and span.start_time else None,
- }
-
-
-def export_trace_to_json(span: ReadableSpan, filepath: str) -> None:
- """
- Export a normalized trace to JSON file for comparison.
-
- Args:
- span: OpenTelemetry ReadableSpan
- filepath: Path to save JSON file
- """
- normalized = normalize_python_span(span)
- with open(filepath, 'w', encoding='utf-8') as f:
- json.dump(normalized, f, indent=2, default=str)
-
-
-def compare_with_typescript(
- python_span: ReadableSpan,
- typescript_trace_path: str
-) -> Dict[str, Any]:
- """
- Compare Python trace with TypeScript trace from JSON file.
-
- Args:
- python_span: Python OpenTelemetry span
- typescript_trace_path: Path to TypeScript trace JSON file
-
- Returns:
- Comparison result dictionary
- """
- python_normalized = normalize_python_span(python_span)
-
- with open(typescript_trace_path, 'r', encoding='utf-8') as f:
- typescript_normalized = json.load(f)
-
- differences = []
-
- # Compare critical attributes
- critical_attrs = [
- 'gen_ai.system',
- 'gen_ai.operation.name',
- 'gen_ai.request.model',
- 'gen_ai.response.model',
- 'gen_ai.usage.input_tokens',
- 'gen_ai.usage.output_tokens',
- 'gen_ai.usage.total_tokens',
- ]
-
- for attr in critical_attrs:
- python_val = python_normalized['attributes'].get(attr)
- typescript_val = typescript_normalized['attributes'].get(attr)
-
- if python_val != typescript_val:
- differences.append(
- f"Attribute '{attr}': Python={python_val}, TypeScript={typescript_val}"
- )
-
- return {
- 'match': len(differences) == 0,
- 'differences': differences,
- 'pythonTrace': python_normalized,
- 'typescriptTrace': typescript_normalized,
- }
-
-
-def get_finished_spans(exporter: InMemorySpanExporter) -> list:
- """
- Get finished spans from an InMemorySpanExporter.
-
- Args:
- exporter: InMemorySpanExporter instance
-
- Returns:
- List of finished ReadableSpan objects
- """
- return list(exporter.get_finished_spans())
-
-
-def extract_key_metrics(span: ReadableSpan) -> Dict[str, Any]:
- """
- Extract key metrics from a span for comparison.
-
- Args:
- span: OpenTelemetry ReadableSpan
-
- Returns:
- Dictionary with key metrics
- """
- attrs = span.attributes
-
- return {
- 'tokens': {
- 'input': attrs.get('gen_ai.usage.input_tokens', 0),
- 'output': attrs.get('gen_ai.usage.output_tokens', 0),
- 'total': attrs.get('gen_ai.usage.total_tokens', 0),
- },
- 'cost': attrs.get('gen_ai.usage.cost', 0),
- 'model': attrs.get('gen_ai.request.model') or attrs.get('gen_ai.response.model', ''),
- 'operation': attrs.get('gen_ai.operation.name', ''),
- 'system': attrs.get('gen_ai.system', ''),
- }