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]: Improve Langchain and LiteLLM instrumentation acc to OTel Semantic Conventions (#627)

Patcher3cc12760e965
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index eea7ee41..dde0383f 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.9"
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/__init__.py b/sdk/python/src/openlit/__init__.py
index 8bba065f..4a8850e2 100644
--- a/sdk/python/src/openlit/__init__.py
+++ b/sdk/python/src/openlit/__init__.py
@@ -17,6 +17,7 @@ import requests
# Import internal modules for setting up tracing and fetching pricing info.
from opentelemetry import trace as t
from opentelemetry.trace import SpanKind, Status, StatusCode, Span
+from opentelemetry.sdk.resources import SERVICE_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.semcov import SemanticConvetion
from openlit.otel.tracing import setup_tracing
from openlit.otel.metrics import setup_meter
@@ -555,11 +556,11 @@ def trace(wrapped):
span.set_attribute("function.args", str(args))
span.set_attribute("function.kwargs", str(kwargs))
span.set_attribute(
- SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ SERVICE_NAME,
OpenlitConfig.application_name,
)
span.set_attribute(
- SemanticConvetion.GEN_AI_ENVIRONMENT, OpenlitConfig.environment
+ DEPLOYMENT_ENVIRONMENT, OpenlitConfig.environment
)
except Exception as meta_exception:
logging.error(
diff --git a/sdk/python/src/openlit/instrumentation/ag2/ag2.py b/sdk/python/src/openlit/instrumentation/ag2/ag2.py
index 69e42385..343807a6 100644
--- a/sdk/python/src/openlit/instrumentation/ag2/ag2.py
+++ b/sdk/python/src/openlit/instrumentation/ag2/ag2.py
@@ -5,7 +5,7 @@ Module for monitoring AG2.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -70,9 +70,9 @@ def wrap_ag2(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
SemanticConvetion.GEN_AI_SYSTEM_AG2)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
diff --git a/sdk/python/src/openlit/instrumentation/astra/astra.py b/sdk/python/src/openlit/instrumentation/astra/astra.py
index a125b03c..ca9bf226 100644
--- a/sdk/python/src/openlit/instrumentation/astra/astra.py
+++ b/sdk/python/src/openlit/instrumentation/astra/astra.py
@@ -5,7 +5,7 @@ Module for monitoring AstraDB.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -69,9 +69,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -199,11 +199,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_ASTRA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/astra/async_astra.py b/sdk/python/src/openlit/instrumentation/astra/async_astra.py
index 71da0c87..464a297f 100644
--- a/sdk/python/src/openlit/instrumentation/astra/async_astra.py
+++ b/sdk/python/src/openlit/instrumentation/astra/async_astra.py
@@ -5,7 +5,7 @@ Module for monitoring AstraDB.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -69,9 +69,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -199,11 +199,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_ASTRA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/chroma/chroma.py b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
index a853a218..3e45600b 100644
--- a/sdk/python/src/openlit/instrumentation/chroma/chroma.py
+++ b/sdk/python/src/openlit/instrumentation/chroma/chroma.py
@@ -5,7 +5,7 @@ Module for monitoring ChromaDB.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -73,9 +73,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -173,11 +173,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_CHROMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/cohere/cohere.py b/sdk/python/src/openlit/instrumentation/cohere/cohere.py
index 4bd4e132..e175d451 100644
--- a/sdk/python/src/openlit/instrumentation/cohere/cohere.py
+++ b/sdk/python/src/openlit/instrumentation/cohere/cohere.py
@@ -222,7 +222,7 @@ def chat(version, environment, application_name, tracer,
llm_response = response_dict.get('message').get('content')[0].get('text')
- # Set base span attribues (OTel Semconv)
+ # 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)
diff --git a/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py b/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py
index 8848586b..a6be6ac4 100644
--- a/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py
+++ b/sdk/python/src/openlit/instrumentation/controlflow/controlflow.py
@@ -5,7 +5,7 @@ Module for monitoring controlflow.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -64,9 +64,9 @@ def wrap_controlflow(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
SemanticConvetion.GEN_AI_SYSTEM_CONTROLFLOW)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
diff --git a/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py b/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py
index b2aa4fbb..2e95f0d6 100644
--- a/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py
+++ b/sdk/python/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py
@@ -5,7 +5,7 @@ Module for monitoring Crawl4AI calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,9 +62,9 @@ def async_wrap_crawl(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TYPE,
SemanticConvetion.GEN_AI_AGENT_TYPE_BROWSER)
diff --git a/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py b/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py
index 97ecc04d..3307d572 100644
--- a/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py
+++ b/sdk/python/src/openlit/instrumentation/crawl4ai/crawl4ai.py
@@ -5,7 +5,7 @@ Module for monitoring Crawl4AI calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,9 +62,9 @@ def wrap_crawl(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TYPE,
SemanticConvetion.GEN_AI_AGENT_TYPE_BROWSER)
diff --git a/sdk/python/src/openlit/instrumentation/crewai/crewai.py b/sdk/python/src/openlit/instrumentation/crewai/crewai.py
index b6e88288..f6a1da7d 100644
--- a/sdk/python/src/openlit/instrumentation/crewai/crewai.py
+++ b/sdk/python/src/openlit/instrumentation/crewai/crewai.py
@@ -6,7 +6,7 @@ Module for monitoring LiteLLM calls.
import logging
import json
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -75,8 +75,10 @@ def crew_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
instance_class = instance.__class__.__name__
diff --git a/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py
index 3de1a637..1ea74d89 100644
--- a/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py
+++ b/sdk/python/src/openlit/instrumentation/dynamiq/dynamiq.py
@@ -5,7 +5,7 @@ Module for monitoring Dynamiq calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,9 +62,9 @@ def dynamiq_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
if gen_ai_endpoint == "dynamiq.agent_run":
diff --git a/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py b/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py
index 95765a00..b6f13530 100644
--- a/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py
+++ b/sdk/python/src/openlit/instrumentation/embedchain/embedchain.py
@@ -5,7 +5,7 @@ Module for monitoring EmbedChain applications.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -63,11 +63,11 @@ def evaluate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_EMBEDCHAIN)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_EVAL_CONTEXT_RELEVANCY,
response["context_relevancy"])
@@ -141,11 +141,11 @@ def get_data_sources(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_EMBEDCHAIN)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
len(response))
diff --git a/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py b/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py
index 53f137a6..4cbfd9c4 100644
--- a/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py
+++ b/sdk/python/src/openlit/instrumentation/firecrawl/firecrawl.py
@@ -5,7 +5,7 @@ Module for monitoring FireCrawl calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,9 +62,9 @@ def wrap_crawl(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TYPE,
SemanticConvetion.GEN_AI_AGENT_TYPE_BROWSER)
diff --git a/sdk/python/src/openlit/instrumentation/gpu/__init__.py b/sdk/python/src/openlit/instrumentation/gpu/__init__.py
index 1d20f8f9..a7fdaffb 100644
--- a/sdk/python/src/openlit/instrumentation/gpu/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/gpu/__init__.py
@@ -5,7 +5,7 @@ from typing import Collection, Iterable
import logging
from functools import partial
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from opentelemetry.metrics import get_meter, CallbackOptions, Observation
from openlit.semcov import SemanticConvetion
@@ -139,8 +139,8 @@ class GPUInstrumentor(BaseInstrumentor):
attributes = {
TELEMETRY_SDK_NAME: "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME: application_name,
- SemanticConvetion.GEN_AI_ENVIRONMENT: environment,
+ SERVICE_NAME: application_name,
+ DEPLOYMENT_ENVIRONMENT: environment,
SemanticConvetion.GPU_INDEX: str(gpu_index),
SemanticConvetion.GPU_UUID: safe_decode(pynvml.nvmlDeviceGetUUID(handle)),
SemanticConvetion.GPU_NAME: safe_decode(pynvml.nvmlDeviceGetName(handle))
@@ -199,8 +199,8 @@ class GPUInstrumentor(BaseInstrumentor):
attributes = {
TELEMETRY_SDK_NAME: "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME: application_name,
- SemanticConvetion.GEN_AI_ENVIRONMENT: environment,
+ SERVICE_NAME: application_name,
+ DEPLOYMENT_ENVIRONMENT: environment,
# pylint: disable=line-too-long
SemanticConvetion.GPU_INDEX: amdsmi.amdsmi_get_xgmi_info(device_handle)['index'],
# pylint: disable=line-too-long
diff --git a/sdk/python/src/openlit/instrumentation/haystack/haystack.py b/sdk/python/src/openlit/instrumentation/haystack/haystack.py
index 56154fc9..b9c9f6fa 100644
--- a/sdk/python/src/openlit/instrumentation/haystack/haystack.py
+++ b/sdk/python/src/openlit/instrumentation/haystack/haystack.py
@@ -5,7 +5,7 @@ Module for monitoring Haystack applications.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -63,11 +63,11 @@ def join_data(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_HAYSTACK)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_status(Status(StatusCode.OK))
diff --git a/sdk/python/src/openlit/instrumentation/julep/async_julep.py b/sdk/python/src/openlit/instrumentation/julep/async_julep.py
index 54de6ab4..bfe98195 100644
--- a/sdk/python/src/openlit/instrumentation/julep/async_julep.py
+++ b/sdk/python/src/openlit/instrumentation/julep/async_julep.py
@@ -5,7 +5,7 @@ Module for monitoring Julep.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -64,9 +64,9 @@ def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
SemanticConvetion.GEN_AI_SYSTEM_JULEP)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
diff --git a/sdk/python/src/openlit/instrumentation/julep/julep.py b/sdk/python/src/openlit/instrumentation/julep/julep.py
index cb02b2e4..301bf864 100644
--- a/sdk/python/src/openlit/instrumentation/julep/julep.py
+++ b/sdk/python/src/openlit/instrumentation/julep/julep.py
@@ -5,7 +5,7 @@ Module for monitoring Julep.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -64,9 +64,9 @@ def wrap_julep(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
SemanticConvetion.GEN_AI_SYSTEM_JULEP)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
diff --git a/sdk/python/src/openlit/instrumentation/langchain/__init__.py b/sdk/python/src/openlit/instrumentation/langchain/__init__.py
index d501275f..f4ecee85 100644
--- a/sdk/python/src/openlit/instrumentation/langchain/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/langchain/__init__.py
@@ -8,10 +8,10 @@ from wrapt import wrap_function_wrapper
from openlit.instrumentation.langchain.langchain import (
general_wrap,
hub,
- llm,
- allm,
- chat,
- achat
+ chat
+)
+from openlit.instrumentation.langchain.async_langchain import (
+ async_chat
)
_instruments = ("langchain >= 0.1.20",)
@@ -51,13 +51,13 @@ WRAPPED_METHODS = [
"package": "langchain_core.language_models.llms",
"object": "BaseLLM.invoke",
"endpoint": "langchain.llm",
- "wrapper": llm,
+ "wrapper": chat,
},
{
"package": "langchain_core.language_models.llms",
"object": "BaseLLM.ainvoke",
"endpoint": "langchain.llm",
- "wrapper": allm,
+ "wrapper": async_chat,
},
{
"package": "langchain_core.language_models.chat_models",
@@ -69,13 +69,19 @@ WRAPPED_METHODS = [
"package": "langchain_core.language_models.chat_models",
"object": "BaseChatModel.ainvoke",
"endpoint": "langchain.chat_models",
- "wrapper": achat,
+ "wrapper": async_chat,
},
{
"package": "langchain.chains.base",
"object": "Chain.invoke",
"endpoint": "langchain.chain.invoke",
"wrapper": chat,
+ },
+ {
+ "package": "langchain.chains.base",
+ "object": "Chain.invoke",
+ "endpoint": "langchain.chain.invoke",
+ "wrapper": async_chat,
}
]
diff --git a/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py b/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py
new file mode 100644
index 00000000..24f4a8f5
--- /dev/null
+++ b/sdk/python/src/openlit/instrumentation/langchain/async_langchain.py
@@ -0,0 +1,384 @@
+# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, unused-import, too-many-function-args
+"""
+Module for monitoring Langchain applications.
+"""
+
+import logging
+import time
+from opentelemetry.trace import SpanKind, Status, StatusCode
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
+from openlit.__helpers import (
+ get_chat_model_cost,
+ handle_exception,
+ general_tokens,
+ calculate_ttft,
+ calculate_tbt,
+ create_metrics_attributes,
+)
+from openlit.semcov import SemanticConvetion
+
+# Initialize logger for logging potential issues and operations
+logger = logging.getLogger(__name__)
+
+def get_attribute_from_instance_or_kwargs(instance, attribute_name, default=-1):
+ """Return attribute from instance or kwargs"""
+ # Attempt to retrieve model_kwargs from the instance
+ model_kwargs = getattr(instance, 'model_kwargs', None)
+
+ # Check for attribute in model_kwargs if it exists
+ if model_kwargs and attribute_name in model_kwargs:
+ return model_kwargs[attribute_name]
+
+ # Attempt to get the attribute directly from the instance
+ try:
+ return getattr(instance, attribute_name)
+ except AttributeError:
+ # Special handling for 'model' attribute to consider 'model_id'
+ if attribute_name == 'model':
+ return getattr(instance, 'model_id', 'default_model_id')
+
+ # Default if the attribute isn't found in model_kwargs or the instance
+ return default
+
+def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ 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.
+ """
+
+ async 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 = await wrapped(*args, **kwargs)
+
+ try:
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
+ SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
+ span.set_attribute(SERVICE_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_RETRIEVAL_SOURCE,
+ response[0].metadata["source"])
+ span.set_status(Status(StatusCode.OK))
+
+ # 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
+
+ return wrapper
+
+def async_hub(gen_ai_endpoint, version, environment, application_name, tracer,
+ pricing_info, trace_content, metrics, disable_metrics):
+ """
+ Creates a wrapper around Langchain hub operations for tracing and logging.
+
+ Similar to `general_wrap`, this function focuses on wrapping functions involved
+ in interacting with the Langchain hub, adding specific metadata relevant to
+ hub operations to the span attributes.
+
+ Parameters:
+ - gen_ai_endpoint (str): A descriptor or name for the Langchain hub endpoint.
+ - version (str): The version of the Langchain application.
+ - environment (str): The deployment environment, such as 'production' or 'development'.
+ - 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.
+
+ Returns:
+ - function: A new function that wraps the original hub operation call with added
+ logging, tracing, and metric calculation functionalities.
+ """
+
+ async def wrapper(wrapped, instance, args, kwargs):
+ """
+ An inner wrapper specifically designed for Langchain hub operations,
+ providing tracing, logging, and execution metrics.
+
+ Parameters:
+ - wrapped (Callable): The original hub operation function to be executed.
+ - instance (object): The instance of the class where the hub operation
+ method is defined. May be None for static or class methods.
+ - args (tuple): Positional arguments to pass to the hub operation function.
+ - kwargs (dict): Keyword arguments to pass to the hub operation function.
+
+ Returns:
+ - The result of executing the hub operation function.
+
+ This wrapper captures additional metadata relevant to Langchain hub operations,
+ creating spans with specific attributes and metrics that reflect the nature of
+ each hub call.
+ """
+
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ response = await wrapped(*args, **kwargs)
+
+ try:
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
+ gen_ai_endpoint)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
+ span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
+ SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
+ span.set_attribute(SERVICE_NAME,
+ application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_HUB_OWNER,
+ response.metadata["lc_hub_owner"])
+ span.set_attribute(SemanticConvetion.GEN_AI_HUB_REPO,
+ response.metadata["lc_hub_repo"])
+ span.set_status(Status(StatusCode.OK))
+
+ return response
+
+ except Exception as e:
+ handle_exception(span, e)
+ logger.error("Error in trace creation: %s", e)
+
+ # Return original response
+ return response
+
+ return wrapper
+
+def async_chat(gen_ai_endpoint, version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
+ """
+ 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:
+ - 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.
+ """
+
+ async 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.
+ """
+
+ server_address, server_port = "NOT_FOUND", "NOT_FOUND"
+
+ if hasattr(instance, "model_id"):
+ request_model = instance.model_id
+ elif hasattr(instance, "model"):
+ request_model = instance.model
+ elif hasattr(instance, "model_name"):
+ request_model = instance.model_name
+ else:
+ request_model = "NOT_FOUND"
+
+ span_name = f"{SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
+
+ 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:
+ # Format 'messages' into a single string
+ message_prompt = kwargs.get("messages", "") or args[0]
+ formatted_messages = []
+
+ for message in message_prompt:
+ # Handle the case where message is a tuple
+ if isinstance(message, tuple) and len(message) == 2:
+ role, content = message
+ # Handle the case where message is a dictionary
+ elif isinstance(message, dict):
+ role = message["role"]
+ content = message["content"]
+ else:
+ continue
+
+ # Check if the content is a list
+ 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}")
+
+ # Join all formatted messages with newline
+ prompt = "\n".join(formatted_messages)
+
+ input_tokens = general_tokens(str(prompt))
+ output_tokens = general_tokens(str(response))
+
+ # 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_LANGCHAIN)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
+ request_model)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ request_model)
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
+ str(getattr(instance, 'temperature', 1)))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
+ str(getattr(instance, 'top_k', 1)))
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
+ str(getattr(instance, 'top_p', 1)))
+ 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.SERVER_PORT,
+ server_port)
+
+ # 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,
+ },
+ )
+ completion_content = getattr(response, 'content', "")
+ span.add_event(
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
+ attributes={
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: completion_content,
+ },
+ )
+
+ 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_LANGCHAIN,
+ 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
+
+ return wrapper
diff --git a/sdk/python/src/openlit/instrumentation/langchain/langchain.py b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
index c6356e31..32535bef 100644
--- a/sdk/python/src/openlit/instrumentation/langchain/langchain.py
+++ b/sdk/python/src/openlit/instrumentation/langchain/langchain.py
@@ -4,9 +4,17 @@ Module for monitoring Langchain applications.
"""
import logging
+import time
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
-from openlit.__helpers import handle_exception, get_chat_model_cost, general_tokens
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
+from openlit.__helpers import (
+ get_chat_model_cost,
+ handle_exception,
+ general_tokens,
+ calculate_ttft,
+ calculate_tbt,
+ create_metrics_attributes,
+)
from openlit.semcov import SemanticConvetion
# Initialize logger for logging potential issues and operations
@@ -83,11 +91,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_RETRIEVAL_SOURCE,
response[0].metadata["source"])
@@ -157,11 +165,11 @@ def hub(gen_ai_endpoint, version, environment, application_name, tracer,
SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_HUB_OWNER,
response.metadata["lc_hub_owner"])
@@ -180,148 +188,7 @@ def hub(gen_ai_endpoint, version, environment, application_name, tracer,
return wrapper
-
-def allm(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, trace_content, metrics, disable_metrics):
- """
- 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.
- """
-
- async 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 = await wrapped(*args, **kwargs)
-
- try:
- if args:
- prompt = str(args[0]) if args[0] is not None else ""
- else:
- prompt = ""
- input_tokens = general_tokens(prompt)
- output_tokens = general_tokens(response)
-
- # Calculate cost of the operation
- cost = get_chat_model_cost(
- str(get_attribute_from_instance_or_kwargs(instance, 'model')),
- pricing_info, input_tokens, output_tokens
- )
-
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
- SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
- application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- str(get_attribute_from_instance_or_kwargs(instance, 'model')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
- str(get_attribute_from_instance_or_kwargs(instance, 'temperature')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
- str(get_attribute_from_instance_or_kwargs(instance, 'top_k')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- str(get_attribute_from_instance_or_kwargs(instance, 'top_p')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
- False)
- 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_USAGE_TOTAL_TOKENS,
- input_tokens + output_tokens)
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
- 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={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,
- },
- )
-
- span.set_status(Status(StatusCode.OK))
-
- if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- str(get_attribute_from_instance_or_kwargs(instance, 'model'))
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- input_tokens + output_tokens, 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
-
- return wrapper
-
-def llm(gen_ai_endpoint, version, environment, application_name,
+def chat(gen_ai_endpoint, version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics):
"""
Creates a wrapper around a function call to trace and log its execution metrics.
@@ -330,7 +197,6 @@ def llm(gen_ai_endpoint, version, environment, application_name,
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.
@@ -363,365 +229,105 @@ def llm(gen_ai_endpoint, version, environment, application_name,
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)
- try:
- if args:
- prompt = str(args[0]) if args[0] is not None else ""
- else:
- prompt = ""
- input_tokens = general_tokens(prompt)
- output_tokens = general_tokens(response)
+ server_address, server_port = "NOT_FOUND", "NOT_FOUND"
- # Calculate cost of the operation
- cost = get_chat_model_cost(
- str(get_attribute_from_instance_or_kwargs(instance, 'model')),
- pricing_info, input_tokens, output_tokens
- )
+ if hasattr(instance, "model_id"):
+ request_model = instance.model_id
+ elif hasattr(instance, "model"):
+ request_model = instance.model
+ elif hasattr(instance, "model_name"):
+ request_model = instance.model_name
+ else:
+ request_model = "NOT_FOUND"
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
- SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
- application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- str(get_attribute_from_instance_or_kwargs(instance, 'model')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
- str(get_attribute_from_instance_or_kwargs(instance, 'temperature')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
- str(get_attribute_from_instance_or_kwargs(instance, 'top_k')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- str(get_attribute_from_instance_or_kwargs(instance, 'top_p')))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
- False)
- 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_USAGE_TOTAL_TOKENS,
- input_tokens + output_tokens)
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
- 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={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,
- },
- )
-
- span.set_status(Status(StatusCode.OK))
-
- if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- str(get_attribute_from_instance_or_kwargs(instance, 'model'))
- }
+ span_name = f"{SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- input_tokens + output_tokens, 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
-
- return wrapper
-
-def chat(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, trace_content, metrics, disable_metrics):
- """
- 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.
- """
-
- 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:
+ 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:
- prompt = ""
- if hasattr(response, 'usage_metadata') and response.usage_metadata:
- token_usage = response.usage_metadata
- input_tokens = token_usage.get("input_tokens", 0)
- output_tokens = token_usage.get("output_tokens", 0)
- if hasattr(instance, "model_id"):
- model = instance.model_id
+ # Format 'messages' into a single string
+ message_prompt = kwargs.get("messages", "") or args[0]
+ formatted_messages = []
+
+ for message in message_prompt:
+ # Handle the case where message is a tuple
+ if isinstance(message, tuple) and len(message) == 2:
+ role, content = message
+ # Handle the case where message is a dictionary
+ elif isinstance(message, dict):
+ role = message["role"]
+ content = message["content"]
else:
- model = instance.model_name
- prompt = "" if isinstance(args[0], list) else args[0]
- else:
- if not isinstance(response, dict) or "output_text" not in response:
- return response
- # Fallback: Calculate tokens manually if response_metadata is missing
- model = "gpt-4o-mini" # Fallback model
- input_texts = [
- doc.page_content for doc in response.get("input_documents", [])
- if isinstance(doc.page_content, str)
- ]
- input_tokens = sum(general_tokens(text) for text in input_texts)
- output_text = response.get("output_text", "")
- output_tokens = general_tokens(output_text)
+ continue
+
+ # Check if the content is a list
+ 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}")
+
+ # Join all formatted messages with newline
+ prompt = "\n".join(formatted_messages)
+
+ input_tokens = general_tokens(str(prompt))
+ output_tokens = general_tokens(str(response))
# Calculate cost of the operation
cost = get_chat_model_cost(
- model,
+ 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_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
- application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- model)
+ request_model)
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ request_model)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
str(getattr(instance, 'temperature', 1)))
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
str(getattr(instance, 'top_k', 1)))
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
str(getattr(instance, 'top_p', 1)))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
- False)
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_USAGE_TOTAL_TOKENS,
- input_tokens + output_tokens)
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
- if trace_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,
- },
- )
-
- span.set_status(Status(StatusCode.OK))
-
- if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- model
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- input_tokens + output_tokens, 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
-
- return wrapper
-
-def achat(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, trace_content, metrics, disable_metrics):
- """
- 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.
- """
-
- async 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 = await wrapped(*args, **kwargs)
-
- try:
- prompt = ""
- if hasattr(response, 'usage_metadata') and response.usage_metadata:
- token_usage = response.usage_metadata
- input_tokens = token_usage.get("input_tokens", 0)
- output_tokens = token_usage.get("output_tokens", 0)
- if hasattr(instance, "model_id"):
- model = instance.model_id
- else:
- model = instance.model_name
- prompt = "" if isinstance(args[0], list) else args[0]
- else:
- if not isinstance(response, dict) or "output_text" not in response:
- return response
- # Fallback: Calculate tokens manually if response_metadata is missing
- model = "gpt-4o-mini" # Fallback model
- input_texts = [
- doc.page_content for doc in response.get("input_documents", [])
- if isinstance(doc.page_content, str)
- ]
- input_tokens = sum(general_tokens(text) for text in input_texts)
- output_text = response.get("output_text", "")
- output_tokens = general_tokens(output_text)
-
- # Calculate cost of the operation
- cost = get_chat_model_cost(
- model,
- pricing_info, input_tokens, output_tokens
- )
-
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
- span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SemanticConvetion.SERVER_ADDRESS,
+ server_address)
+ span.set_attribute(SemanticConvetion.SERVER_PORT,
+ server_port)
+
+ # 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_MODEL,
- model)
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
- str(getattr(instance, 'temperature',1)))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
- str(getattr(instance, 'top_k',1)))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- str(getattr(instance, 'top_p',1)))
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
False)
- 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_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,
@@ -732,32 +338,34 @@ def achat(gen_ai_endpoint, version, environment, application_name,
span.add_event(
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.content,
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,
},
)
span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- model
- }
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN,
+ request_model=request_model,
+ server_address=server_address,
+ server_port=server_port,
+ response_model=request_model,
+ )
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
+ 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)
diff --git a/sdk/python/src/openlit/instrumentation/letta/letta.py b/sdk/python/src/openlit/instrumentation/letta/letta.py
index e0058afa..97573126 100644
--- a/sdk/python/src/openlit/instrumentation/letta/letta.py
+++ b/sdk/python/src/openlit/instrumentation/letta/letta.py
@@ -5,7 +5,7 @@ Module for monitoring Letta calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception, get_chat_model_cost
)
@@ -62,8 +62,10 @@ def create_agent(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
response.id)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
@@ -143,7 +145,7 @@ def send_message(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_STEP_COUNT,
response.usage.step_count)
diff --git a/sdk/python/src/openlit/instrumentation/litellm/__init__.py b/sdk/python/src/openlit/instrumentation/litellm/__init__.py
index 5f3d9eda..e85fa54f 100644
--- a/sdk/python/src/openlit/instrumentation/litellm/__init__.py
+++ b/sdk/python/src/openlit/instrumentation/litellm/__init__.py
@@ -37,32 +37,31 @@ class LiteLLMInstrumentor(BaseInstrumentor):
wrap_function_wrapper(
"litellm",
"completion",
- completion("litellm.completion", version, environment, application_name,
+ completion(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics),
)
wrap_function_wrapper(
"litellm",
"acompletion",
- acompletion("litellm.completion", version, environment, application_name,
+ acompletion(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics),
)
wrap_function_wrapper(
"litellm",
"embedding",
- embedding("litellm.embedding", version, environment, application_name,
+ embedding(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics),
)
wrap_function_wrapper(
"litellm",
"aembedding",
- aembedding("litellm.embedding", version, environment, application_name,
+ aembedding(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics),
)
-
def _uninstrument(self, **kwargs):
# Proper uninstrumentation logic to revert patched methods
pass
diff --git a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py
index 646e9318..1db2f733 100644
--- a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py
+++ b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py
@@ -1,30 +1,32 @@
-# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, too-many-branches
"""
Module for monitoring LiteLLM calls.
"""
import logging
+import time
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
get_chat_model_cost,
get_embed_model_cost,
- openai_tokens,
+ general_tokens,
handle_exception,
response_as_dict,
+ calculate_ttft,
+ calculate_tbt,
+ create_metrics_attributes,
)
from openlit.semcov import SemanticConvetion
# Initialize logger for logging potential issues and operations
logger = logging.getLogger(__name__)
-def acompletion(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, trace_content, metrics, disable_metrics):
+def acompletion(version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
"""
Generates a telemetry wrapper for chat completions 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 LiteLLM SDK.
@@ -51,16 +53,27 @@ def acompletion(gen_ai_endpoint, version, environment, application_name,
wrapped,
span,
kwargs,
+ server_address,
+ server_port,
**args,
):
self.__wrapped__ = wrapped
self._span = span
- # Placeholder for aggregating streaming response
- self._llmresponse = ""
- self._response_id = ""
+ self._llmresponse = ''
+ self._response_id = ''
+ self._response_model = ''
+ self._finish_reason = ''
+ self._response_service_tier = ''
self._args = args
self._kwargs = kwargs
+ self._start_time = time.time()
+ self._end_time = None
+ self._timestamps = []
+ self._ttft = 0
+ self._tbt = 0
+ self._server_address = server_address
+ self._server_port = server_port
async def __aenter__(self):
await self.__wrapped__.__aenter__()
@@ -79,6 +92,14 @@ def acompletion(gen_ai_endpoint, 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)
# Collect message IDs and aggregated response from events
if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and
@@ -88,80 +109,114 @@ def acompletion(gen_ai_endpoint, version, environment, application_name,
if content:
self._llmresponse += content
self._response_id = chunked.get('id')
+ self._response_model = chunked.get('model')
+ self._finish_reason = chunked.get('choices')[0].get('finish_reason')
+ self._response_service_tier = str(chunked.get('system_fingerprint'))
return chunk
except StopAsyncIteration:
# Handling exception ensure observability without disrupting operation
try:
+ 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", "")
+ message_prompt = self._kwargs.get('messages', '')
formatted_messages = []
for message in message_prompt:
- role = message["role"]
- content = message["content"]
+ role = message['role']
+ content = message['content']
if isinstance(content, list):
content_str = ", ".join(
- # pylint: disable=line-too-long
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}")
+ formatted_messages.append(f'{role}: {content_str}')
else:
- formatted_messages.append(f"{role}: {content}")
- prompt = "\n".join(formatted_messages)
+ formatted_messages.append(f'{role}: {content}')
+ prompt = '\n'.join(formatted_messages)
+
+ request_model = self._kwargs.get('model', 'openai/gpt-4o')
# Calculate tokens using input prompt and aggregated response
- prompt_tokens = openai_tokens(prompt,
- self._kwargs.get("model", "gpt-3.5-turbo"))
- completion_tokens = openai_tokens(self._llmresponse,
- self._kwargs.get("model", "gpt-3.5-turbo"))
+ input_tokens = general_tokens(prompt)
+ output_tokens = general_tokens(self._llmresponse)
# Calculate cost of the operation
- cost = get_chat_model_cost(self._kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, prompt_tokens,
- completion_tokens)
+ cost = get_chat_model_cost(request_model,
+ pricing_info, input_tokens,
+ output_tokens)
- # Set Span attributes
- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ # 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_ENDPOINT,
- gen_ai_endpoint)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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', 1.0))
+ 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_ENVIRONMENT,
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ self._response_model)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
+ input_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
+ output_tokens)
+ self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,
+ self._server_address)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SERVICE_TIER,
+ self._kwargs.get('service_tier', 'auto'))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SERVICE_TIER,
+ self._response_service_tier)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
+ self._response_service_tier)
+ 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(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ self._span.set_attribute(SERVICE_NAME,
application_name)
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- self._kwargs.get("model", "gpt-3.5-turbo"))
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- self._kwargs.get("user", ""))
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- self._kwargs.get("top_p", 1.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_TEMPERATURE,
- self._kwargs.get("temperature", 1.0))
- 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_FREQUENCY_PENALTY,
- self._kwargs.get("frequency_penalty", 0.0))
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
- self._kwargs.get("seed", ""))
+ self._kwargs.get('user', ''))
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
True)
- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- prompt_tokens)
- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- completion_tokens)
self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- prompt_tokens + completion_tokens)
+ input_tokens + 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,
@@ -175,36 +230,40 @@ def acompletion(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
},
)
-
self._span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- self._kwargs.get("model", "gpt-3.5-turbo")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- prompt_tokens + completion_tokens, attributes
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ request_model=request_model,
+ server_address=self._server_address,
+ server_port=self._server_port,
+ response_model=self._response_model,
)
- metrics["genai_completion_tokens"].add(completion_tokens, attributes)
- metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
- metrics["genai_cost"].record(cost, attributes)
+
+ metrics['genai_client_usage_tokens'].record(
+ input_tokens + 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(output_tokens, attributes)
+ metrics['genai_prompt_tokens'].add(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)
+ logger.error('Error in trace creation: %s', e)
finally:
self._span.end()
raise
@@ -227,76 +286,113 @@ def acompletion(gen_ai_endpoint, version, environment, application_name,
"""
# Check if streaming is enabled for the API call
- streaming = kwargs.get("stream", False)
+ streaming = kwargs.get('stream', False)
+ server_address, server_port = 'NOT_FOUND', 'NOT_FOUND'
+ request_model = kwargs.get('model', 'openai/gpt-4o')
+
+ span_name = f'{SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT} {request_model}'
# pylint: disable=no-else-return
if streaming:
# Special handling for streaming response to accommodate the nature of data flow
awaited_wrapped = await wrapped(*args, **kwargs)
- span = tracer.start_span(gen_ai_endpoint, kind=SpanKind.CLIENT)
+ span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
- return TracedAsyncStream(awaited_wrapped, span, kwargs)
+ return TracedAsyncStream(awaited_wrapped, span, kwargs, server_address, server_port)
+ # Handling for non-streaming responses
# Handling for non-streaming responses
else:
- # pylint: disable=line-too-long
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ 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", "")
+ message_prompt = kwargs.get('messages', '')
formatted_messages = []
for message in message_prompt:
- role = message["role"]
- content = message["content"]
+ role = message['role']
+ content = message['content']
if isinstance(content, list):
content_str = ", ".join(
- # pylint: disable=line-too-long
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}")
+ formatted_messages.append(f'{role}: {content_str}')
else:
- formatted_messages.append(f"{role}: {content}")
- prompt = "\n".join(formatted_messages)
+ formatted_messages.append(f'{role}: {content}')
+ prompt = '\n'.join(formatted_messages)
- # Set base span attribues
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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_ENDPOINT,
- gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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', 1.0))
+ 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_ENVIRONMENT,
+ response_dict.get('id'))
+ 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_REQUEST_SERVICE_TIER,
+ kwargs.get('service_tier', 'auto'))
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
+ str(response_dict.get('system_fingerprint')))
+
+ # Set base span attribues (Extras)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- kwargs.get("model", "gpt-3.5-turbo"))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- kwargs.get("top_p", 1.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
- kwargs.get("max_tokens", -1))
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- kwargs.get("user", ""))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
- kwargs.get("temperature", 1.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
- kwargs.get("presence_penalty", 0.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
- kwargs.get("frequency_penalty", 0.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
- kwargs.get("seed", ""))
+ kwargs.get('user', ''))
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,
@@ -305,121 +401,81 @@ def acompletion(gen_ai_endpoint, version, environment, application_name,
},
)
- # Set span attributes when tools is not passed to the function call
- if "tools" not in kwargs:
- # Calculate cost of the operation
- cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, response_dict.get('usage', {}).get('prompt_tokens', None),
- response_dict.get('usage', {}).get('completion_tokens', None))
-
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- response_dict.get('usage', {}).get('prompt_tokens', None))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- response_dict.get('usage', {}).get('completion_tokens', None))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage', {}).get('total_tokens', None))
+ for i in range(kwargs.get('n',1)):
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
- [response_dict.get('choices', [])[0].get('finish_reason', None)])
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
-
- # Set span attributes for when n = 1 (default)
- if "n" not in kwargs or kwargs["n"] == 1:
- if trace_content:
- span.add_event(
- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices', [])[0].get("message").get("content"),
- },
- )
-
- # Set span attributes for when n > 0
- else:
- i = 0
- while i < kwargs["n"] and trace_content is True:
- attribute_name = f"gen_ai.content.completion.{i}"
- span.add_event(
- name=attribute_name,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices')[i].get("message").get("content"),
- },
- )
- i += 1
-
- # Return original response
- return response
-
- # Set span attributes when tools is passed to the function call
- elif "tools" in kwargs:
- # Calculate cost of the operation
- cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, response_dict.get('usage').get('prompt_tokens'),
- response_dict.get('usage').get('completion_tokens'))
- span.add_event(
- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
- },
- )
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- response_dict.get('usage').get('prompt_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- response_dict.get('usage').get('completion_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage').get('total_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
+ [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 = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- kwargs.get("model", "gpt-3.5-turbo")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(response_dict.get('usage').get('total_tokens'), attributes)
- metrics["genai_completion_tokens"].add(response_dict.get('usage').get('completion_tokens'), attributes)
- metrics["genai_prompt_tokens"].add(response_dict.get('usage').get('prompt_tokens'), attributes)
- metrics["genai_cost"].record(cost, attributes)
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ 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)
+ logger.error('Error in trace creation: %s', e)
# Return original response
return response
return wrapper
-def aembedding(gen_ai_endpoint, version, environment, application_name,
- tracer, pricing_info, trace_content, metrics, disable_metrics):
+def aembedding(version, environment, application_name,
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
"""
Generates a telemetry wrapper for embeddings 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 OpenAI API.
+ 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 OpenAI usage.
+ pricing_info: Information used for calculating the cost of LiteLLM usage.
trace_content: Flag indicating whether to trace the actual content.
-
+
Returns:
A function that wraps the embeddings method to add telemetry.
"""
@@ -441,79 +497,94 @@ def aembedding(gen_ai_endpoint, version, environment, application_name,
The response from the original 'embeddings' method.
"""
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ server_address, server_port = 'NOT_FOUND', 'NOT_FOUND'
+ request_model = kwargs.get('model', 'text-embedding-ada-002')
+
+ span_name = f'{SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}'
+
+ 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:
+ input_tokens = response_dict.get('usage').get('prompt_tokens')
+
# Calculate cost of the operation
- cost = get_embed_model_cost(kwargs.get("model", "text-embedding-ada-002"),
- pricing_info, response_dict.get('usage').get('prompt_tokens'))
+ cost = get_embed_model_cost(request_model,
+ pricing_info, input_tokens)
- # Set Span attributes
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_OPENAI)
+ # 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_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
- application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- kwargs.get("model", "text-embedding-ada-002"))
+ request_model)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_ENCODING_FORMATS,
- kwargs.get("encoding_format", "float"))
- # span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_EMBEDDING_DIMENSION,
- # kwargs.get("dimensions", "null"))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- kwargs.get("user", ""))
+ [kwargs.get('encoding_format', 'float')])
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ response_dict.get('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,
- response_dict.get('usage').get('prompt_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_REQUEST_USER,
+ kwargs.get('user', ''))
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage').get('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: kwargs.get("input", ""),
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get('input', '')),
},
)
span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_OPENAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- kwargs.get("model", "text-embedding-ada-002")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- response_dict.get('usage').get('total_tokens'), attributes)
- metrics["genai_prompt_tokens"].add(
- response_dict.get('usage').get('prompt_tokens'), attributes)
- metrics["genai_cost"].record(cost, attributes)
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ 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, 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)
+ logger.error('Error in trace creation: %s', e)
# Return original response
return response
diff --git a/sdk/python/src/openlit/instrumentation/litellm/litellm.py b/sdk/python/src/openlit/instrumentation/litellm/litellm.py
index 1f233a66..ba24d1f8 100644
--- a/sdk/python/src/openlit/instrumentation/litellm/litellm.py
+++ b/sdk/python/src/openlit/instrumentation/litellm/litellm.py
@@ -1,30 +1,32 @@
-# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, too-many-branches
"""
Module for monitoring LiteLLM calls.
"""
import logging
+import time
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
get_chat_model_cost,
get_embed_model_cost,
- openai_tokens,
+ general_tokens,
handle_exception,
response_as_dict,
+ calculate_ttft,
+ calculate_tbt,
+ create_metrics_attributes,
)
from openlit.semcov import SemanticConvetion
# Initialize logger for logging potential issues and operations
logger = logging.getLogger(__name__)
-def completion(gen_ai_endpoint, version, environment, application_name,
+def completion(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics):
"""
Generates a telemetry wrapper for chat completions 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 LiteLLM SDK.
@@ -51,16 +53,27 @@ def completion(gen_ai_endpoint, version, environment, application_name,
wrapped,
span,
kwargs,
+ server_address,
+ server_port,
**args,
):
self.__wrapped__ = wrapped
self._span = span
- # Placeholder for aggregating streaming response
- self._llmresponse = ""
- self._response_id = ""
+ self._llmresponse = ''
+ self._response_id = ''
+ self._response_model = ''
+ self._finish_reason = ''
+ self._response_service_tier = ''
self._args = args
self._kwargs = kwargs
+ self._start_time = time.time()
+ self._end_time = None
+ self._timestamps = []
+ self._ttft = 0
+ self._tbt = 0
+ self._server_address = server_address
+ self._server_port = server_port
def __enter__(self):
self.__wrapped__.__enter__()
@@ -79,6 +92,14 @@ def completion(gen_ai_endpoint, 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)
# Collect message IDs and aggregated response from events
if (len(chunked.get('choices')) > 0 and ('delta' in chunked.get('choices')[0] and
@@ -88,80 +109,114 @@ def completion(gen_ai_endpoint, version, environment, application_name,
if content:
self._llmresponse += content
self._response_id = chunked.get('id')
+ self._response_model = chunked.get('model')
+ self._finish_reason = chunked.get('choices')[0].get('finish_reason')
+ self._response_service_tier = str(chunked.get('system_fingerprint'))
return chunk
except StopIteration:
# Handling exception ensure observability without disrupting operation
try:
+ 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", "")
+ message_prompt = self._kwargs.get('messages', '')
formatted_messages = []
for message in message_prompt:
- role = message["role"]
- content = message["content"]
+ role = message['role']
+ content = message['content']
if isinstance(content, list):
content_str = ", ".join(
- # pylint: disable=line-too-long
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}")
+ formatted_messages.append(f'{role}: {content_str}')
else:
- formatted_messages.append(f"{role}: {content}")
- prompt = "\n".join(formatted_messages)
+ formatted_messages.append(f'{role}: {content}')
+ prompt = '\n'.join(formatted_messages)
+
+ request_model = self._kwargs.get('model', 'openai/gpt-4o')
# Calculate tokens using input prompt and aggregated response
- prompt_tokens = openai_tokens(prompt,
- self._kwargs.get("model", "gpt-3.5-turbo"))
- completion_tokens = openai_tokens(self._llmresponse,
- self._kwargs.get("model", "gpt-3.5-turbo"))
+ input_tokens = general_tokens(prompt)
+ output_tokens = general_tokens(self._llmresponse)
# Calculate cost of the operation
- cost = get_chat_model_cost(self._kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, prompt_tokens,
- completion_tokens)
+ cost = get_chat_model_cost(request_model,
+ pricing_info, input_tokens,
+ output_tokens)
- # Set Span attributes
- self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ # 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_ENDPOINT,
- gen_ai_endpoint)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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', 1.0))
+ 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_ENVIRONMENT,
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ self._response_model)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
+ input_tokens)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
+ output_tokens)
+ self._span.set_attribute(SemanticConvetion.SERVER_ADDRESS,
+ self._server_address)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SERVICE_TIER,
+ self._kwargs.get('service_tier', 'auto'))
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SERVICE_TIER,
+ self._response_service_tier)
+ self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
+ self._response_service_tier)
+ 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(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ self._span.set_attribute(SERVICE_NAME,
application_name)
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- self._kwargs.get("model", "gpt-3.5-turbo"))
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- self._kwargs.get("user", ""))
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- self._kwargs.get("top_p", 1.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_TEMPERATURE,
- self._kwargs.get("temperature", 1.0))
- 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_FREQUENCY_PENALTY,
- self._kwargs.get("frequency_penalty", 0.0))
- self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
- self._kwargs.get("seed", ""))
+ self._kwargs.get('user', ''))
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
True)
- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- prompt_tokens)
- self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- completion_tokens)
self._span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- prompt_tokens + completion_tokens)
+ input_tokens + 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,
@@ -175,36 +230,40 @@ def completion(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
},
)
-
self._span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- self._kwargs.get("model", "gpt-3.5-turbo")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- prompt_tokens + completion_tokens, attributes
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ request_model=request_model,
+ server_address=self._server_address,
+ server_port=self._server_port,
+ response_model=self._response_model,
)
- metrics["genai_completion_tokens"].add(completion_tokens, attributes)
- metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
- metrics["genai_cost"].record(cost, attributes)
+
+ metrics['genai_client_usage_tokens'].record(
+ input_tokens + 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(output_tokens, attributes)
+ metrics['genai_prompt_tokens'].add(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)
+ logger.error('Error in trace creation: %s', e)
finally:
self._span.end()
raise
@@ -227,76 +286,113 @@ def completion(gen_ai_endpoint, version, environment, application_name,
"""
# Check if streaming is enabled for the API call
- streaming = kwargs.get("stream", False)
+ streaming = kwargs.get('stream', False)
+ server_address, server_port = 'NOT_FOUND', 'NOT_FOUND'
+ request_model = kwargs.get('model', 'openai/gpt-4o')
+
+ span_name = f'{SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT} {request_model}'
# pylint: disable=no-else-return
if streaming:
# Special handling for streaming response to accommodate the nature of data flow
awaited_wrapped = wrapped(*args, **kwargs)
- span = tracer.start_span(gen_ai_endpoint, kind=SpanKind.CLIENT)
+ span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
- return TracedSyncStream(awaited_wrapped, span, kwargs)
+ return TracedSyncStream(awaited_wrapped, span, kwargs, server_address, server_port)
+ # Handling for non-streaming responses
# Handling for non-streaming responses
else:
- # pylint: disable=line-too-long
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ 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", "")
+ message_prompt = kwargs.get('messages', '')
formatted_messages = []
for message in message_prompt:
- role = message["role"]
- content = message["content"]
+ role = message['role']
+ content = message['content']
if isinstance(content, list):
content_str = ", ".join(
- # pylint: disable=line-too-long
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}")
+ formatted_messages.append(f'{role}: {content_str}')
else:
- formatted_messages.append(f"{role}: {content}")
- prompt = "\n".join(formatted_messages)
+ formatted_messages.append(f'{role}: {content}')
+ prompt = '\n'.join(formatted_messages)
- # Set base span attribues
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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_ENDPOINT,
- gen_ai_endpoint)
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
+ 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', 1.0))
+ 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_ENVIRONMENT,
+ response_dict.get('id'))
+ 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_REQUEST_SERVICE_TIER,
+ kwargs.get('service_tier', 'auto'))
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
+ str(response_dict.get('system_fingerprint')))
+
+ # Set base span attribues (Extras)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- kwargs.get("model", "gpt-3.5-turbo"))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
- kwargs.get("top_p", 1.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
- kwargs.get("max_tokens", -1))
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- kwargs.get("user", ""))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
- kwargs.get("temperature", 1.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
- kwargs.get("presence_penalty", 0.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
- kwargs.get("frequency_penalty", 0.0))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
- kwargs.get("seed", ""))
+ kwargs.get('user', ''))
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,
@@ -305,119 +401,79 @@ def completion(gen_ai_endpoint, version, environment, application_name,
},
)
- # Set span attributes when tools is not passed to the function call
- if "tools" not in kwargs:
- # Calculate cost of the operation
- cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, response_dict.get('usage', {}).get('prompt_tokens', None),
- response_dict.get('usage', {}).get('completion_tokens', None))
-
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- response_dict.get('usage', {}).get('prompt_tokens', None))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- response_dict.get('usage', {}).get('completion_tokens', None))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage', {}).get('total_tokens', None))
+ for i in range(kwargs.get('n',1)):
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
- [response_dict.get('choices', [])[0].get('finish_reason', None)])
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
-
- # Set span attributes for when n = 1 (default)
- if "n" not in kwargs or kwargs["n"] == 1:
- if trace_content:
- span.add_event(
- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices', [])[0].get("message").get("content"),
- },
- )
-
- # Set span attributes for when n > 0
- else:
- i = 0
- while i < kwargs["n"] and trace_content is True:
- attribute_name = f"gen_ai.content.completion.{i}"
- span.add_event(
- name=attribute_name,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response_dict.get('choices')[i].get("message").get("content"),
- },
- )
- i += 1
-
- # Return original response
- return response
-
- # Set span attributes when tools is passed to the function call
- elif "tools" in kwargs:
- # Calculate cost of the operation
- cost = get_chat_model_cost(kwargs.get("model", "gpt-3.5-turbo"),
- pricing_info, response_dict.get('usage').get('prompt_tokens'),
- response_dict.get('usage').get('completion_tokens'))
- span.add_event(
- name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
- attributes={
- SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
- },
- )
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_INPUT_TOKENS,
- response_dict.get('usage').get('prompt_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_OUTPUT_TOKENS,
- response_dict.get('usage').get('completion_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage').get('total_tokens'))
- span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
- cost)
+ [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 = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- kwargs.get("model", "gpt-3.5-turbo")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(response_dict.get('usage').get('total_tokens'), attributes)
- metrics["genai_completion_tokens"].add(response_dict.get('usage').get('completion_tokens'), attributes)
- metrics["genai_prompt_tokens"].add(response_dict.get('usage').get('prompt_tokens'), attributes)
- metrics["genai_cost"].record(cost, attributes)
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ 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)
+ logger.error('Error in trace creation: %s', e)
# Return original response
return response
return wrapper
-def embedding(gen_ai_endpoint, version, environment, application_name,
+def embedding(version, environment, application_name,
tracer, pricing_info, trace_content, metrics, disable_metrics):
"""
Generates a telemetry wrapper for embeddings 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 OpenAI API.
+ 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 OpenAI usage.
+ pricing_info: Information used for calculating the cost of LiteLLM usage.
trace_content: Flag indicating whether to trace the actual content.
Returns:
@@ -441,79 +497,94 @@ def embedding(gen_ai_endpoint, version, environment, application_name,
The response from the original 'embeddings' method.
"""
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
+ server_address, server_port = 'NOT_FOUND', 'NOT_FOUND'
+ request_model = kwargs.get('model', 'text-embedding-ada-002')
+
+ span_name = f'{SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}'
+
+ 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:
+ input_tokens = response_dict.get('usage').get('prompt_tokens')
+
# Calculate cost of the operation
- cost = get_embed_model_cost(kwargs.get("model", "text-embedding-ada-002"),
- pricing_info, response_dict.get('usage').get('prompt_tokens'))
+ cost = get_embed_model_cost(request_model,
+ pricing_info, input_tokens)
- # Set Span attributes
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
- SemanticConvetion.GEN_AI_SYSTEM_OPENAI)
+ # 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_ENDPOINT,
- gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
- environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
- application_name)
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
+ SemanticConvetion.GEN_AI_SYSTEM_LITELLM)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
- kwargs.get("model", "text-embedding-ada-002"))
+ request_model)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_ENCODING_FORMATS,
- kwargs.get("encoding_format", "float"))
- # span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_EMBEDDING_DIMENSION,
- # kwargs.get("dimensions", "null"))
- span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
- kwargs.get("user", ""))
+ [kwargs.get('encoding_format', 'float')])
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_MODEL,
+ response_dict.get('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,
- response_dict.get('usage').get('prompt_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_REQUEST_USER,
+ kwargs.get('user', ''))
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
- response_dict.get('usage').get('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: kwargs.get("input", ""),
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get('input', '')),
},
)
span.set_status(Status(StatusCode.OK))
if disable_metrics is False:
- attributes = {
- TELEMETRY_SDK_NAME:
- "openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
- application_name,
- SemanticConvetion.GEN_AI_SYSTEM:
- SemanticConvetion.GEN_AI_SYSTEM_OPENAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
- environment,
- SemanticConvetion.GEN_AI_OPERATION:
- SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
- SemanticConvetion.GEN_AI_REQUEST_MODEL:
- kwargs.get("model", "text-embedding-ada-002")
- }
-
- metrics["genai_requests"].add(1, attributes)
- metrics["genai_total_tokens"].add(
- response_dict.get('usage').get('total_tokens'), attributes)
- metrics["genai_prompt_tokens"].add(
- response_dict.get('usage').get('prompt_tokens'), attributes)
- metrics["genai_cost"].record(cost, attributes)
+ attributes = create_metrics_attributes(
+ service_name=application_name,
+ deployment_environment=environment,
+ operation=SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
+ system=SemanticConvetion.GEN_AI_SYSTEM_LITELLM,
+ 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, 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)
+ logger.error('Error in trace creation: %s', e)
# Return original response
return response
diff --git a/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py b/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py
index 0468172f..381d56c2 100644
--- a/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py
+++ b/sdk/python/src/openlit/instrumentation/llamaindex/llamaindex.py
@@ -5,7 +5,7 @@ Module for monitoring LlamaIndex applications.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -63,11 +63,11 @@ def load_data(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_LLAMAINDEX)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_RETRIEVAL_SOURCE,
response[0].metadata["file_path"])
diff --git a/sdk/python/src/openlit/instrumentation/mem0/mem0.py b/sdk/python/src/openlit/instrumentation/mem0/mem0.py
index 82b101cf..2c1719d3 100644
--- a/sdk/python/src/openlit/instrumentation/mem0/mem0.py
+++ b/sdk/python/src/openlit/instrumentation/mem0/mem0.py
@@ -5,7 +5,7 @@ Module for monitoring mem0 applications.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -63,11 +63,11 @@ def mem0_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_SYSTEM_MEM0)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_FRAMEWORK)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
if gen_ai_endpoint == "mem0.memory_add":
diff --git a/sdk/python/src/openlit/instrumentation/milvus/milvus.py b/sdk/python/src/openlit/instrumentation/milvus/milvus.py
index c26b6591..1639491e 100644
--- a/sdk/python/src/openlit/instrumentation/milvus/milvus.py
+++ b/sdk/python/src/openlit/instrumentation/milvus/milvus.py
@@ -5,7 +5,7 @@ Module for monitoring Milvus.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -73,9 +73,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -153,11 +153,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_MILVUS,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py
index a8254d94..8eb8f635 100644
--- a/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py
+++ b/sdk/python/src/openlit/instrumentation/mistral/async_mistral.py
@@ -5,7 +5,7 @@ Module for monitoring Mistral API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import get_chat_model_cost, get_embed_model_cost, handle_exception
from openlit.semcov import SemanticConvetion
@@ -86,9 +86,9 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response.id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "mistral-small-latest"))
@@ -133,11 +133,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -252,9 +252,9 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response_id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "mistral-small-latest"))
@@ -298,11 +298,11 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -378,9 +378,9 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get('model', "mistral-embed"))
@@ -408,11 +408,11 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/mistral/mistral.py b/sdk/python/src/openlit/instrumentation/mistral/mistral.py
index dfd48023..5b2b6583 100644
--- a/sdk/python/src/openlit/instrumentation/mistral/mistral.py
+++ b/sdk/python/src/openlit/instrumentation/mistral/mistral.py
@@ -5,7 +5,7 @@ Module for monitoring Mistral API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import get_chat_model_cost, get_embed_model_cost, handle_exception
from openlit.semcov import SemanticConvetion
@@ -85,9 +85,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response.id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "mistral-small-latest"))
@@ -132,11 +132,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -251,9 +251,9 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response_id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "mistral-small-latest"))
@@ -297,11 +297,11 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -377,9 +377,9 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get('model', "mistral-embed"))
@@ -407,11 +407,11 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_MISTRAL,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/multion/async_multion.py b/sdk/python/src/openlit/instrumentation/multion/async_multion.py
index 5d7f2f62..2153f6b6 100644
--- a/sdk/python/src/openlit/instrumentation/multion/async_multion.py
+++ b/sdk/python/src/openlit/instrumentation/multion/async_multion.py
@@ -5,7 +5,7 @@ Module for monitoring multion calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,8 +62,10 @@ def async_multion_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
if gen_ai_endpoint == "multion.browse":
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,
diff --git a/sdk/python/src/openlit/instrumentation/multion/multion.py b/sdk/python/src/openlit/instrumentation/multion/multion.py
index 57c3823b..f6ac6479 100644
--- a/sdk/python/src/openlit/instrumentation/multion/multion.py
+++ b/sdk/python/src/openlit/instrumentation/multion/multion.py
@@ -5,7 +5,7 @@ Module for monitoring multion calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,8 +62,10 @@ def multion_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
if gen_ai_endpoint == "multion.browse":
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_BROWSE_URL,
diff --git a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py
index df07ad51..493284f7 100644
--- a/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py
+++ b/sdk/python/src/openlit/instrumentation/ollama/async_ollama.py
@@ -5,7 +5,7 @@ Module for monitoring Ollama API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
general_tokens,
@@ -108,9 +108,9 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -144,11 +144,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -202,9 +202,9 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -248,11 +248,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -351,9 +351,9 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -388,11 +388,11 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -427,9 +427,9 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -473,11 +473,11 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -554,9 +554,9 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get('model', "llama3"))
@@ -580,11 +580,11 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/ollama/ollama.py b/sdk/python/src/openlit/instrumentation/ollama/ollama.py
index 80b0150b..ae5707bf 100644
--- a/sdk/python/src/openlit/instrumentation/ollama/ollama.py
+++ b/sdk/python/src/openlit/instrumentation/ollama/ollama.py
@@ -5,7 +5,7 @@ Module for monitoring Ollama API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
general_tokens,
@@ -109,9 +109,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -145,11 +145,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -203,9 +203,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -249,11 +249,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -352,9 +352,9 @@ def generate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -389,11 +389,11 @@ def generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -428,9 +428,9 @@ def generate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "llama3"))
@@ -474,11 +474,11 @@ def generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -555,9 +555,9 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get('model', "llama3"))
@@ -581,11 +581,11 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_OLLAMA,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/phidata/phidata.py b/sdk/python/src/openlit/instrumentation/phidata/phidata.py
index 2f97ccde..f18dd444 100644
--- a/sdk/python/src/openlit/instrumentation/phidata/phidata.py
+++ b/sdk/python/src/openlit/instrumentation/phidata/phidata.py
@@ -5,7 +5,7 @@ Module for monitoring Phidata calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
)
@@ -62,8 +62,10 @@ def phidata_wrap(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_AGENT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
+ environment)
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ID,
getattr(instance, 'agent_id', '') or '')
span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
diff --git a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
index 763cd53b..6f44dc2b 100644
--- a/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
+++ b/sdk/python/src/openlit/instrumentation/pinecone/pinecone.py
@@ -5,7 +5,7 @@ Module for monitoring Pinecone.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -72,9 +72,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -146,11 +146,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_PINECONE,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/premai/premai.py b/sdk/python/src/openlit/instrumentation/premai/premai.py
index 33805b5b..2af15c8d 100644
--- a/sdk/python/src/openlit/instrumentation/premai/premai.py
+++ b/sdk/python/src/openlit/instrumentation/premai/premai.py
@@ -5,7 +5,7 @@ Module for monitoring Prem AI API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
general_tokens,
@@ -119,9 +119,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
self._response_id)
- self._span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- self._span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ self._span.set_attribute(SERVICE_NAME,
application_name)
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
self._kwargs.get("model", "gpt-4o-mini"))
@@ -169,11 +169,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_PREMAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -261,9 +261,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response_dict.additional_properties["id"])
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "gpt-3.5-turbo"))
@@ -362,11 +362,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_PREMAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -443,9 +443,9 @@ def embedding(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "text-embedding-3-large"))
@@ -475,11 +475,11 @@ def embedding(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_PREMAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py b/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py
index a4bd99eb..e0abf62c 100644
--- a/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py
+++ b/sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py
@@ -5,7 +5,7 @@ Module for monitoring Qdrant.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -73,9 +73,9 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -241,11 +241,11 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_QDRANT,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py
index 5dbb08bc..efe99962 100644
--- a/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py
+++ b/sdk/python/src/openlit/instrumentation/qdrant/qdrant.py
@@ -5,7 +5,7 @@ Module for monitoring Qdrant.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception
from openlit.semcov import SemanticConvetion
@@ -73,9 +73,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB)
@@ -248,11 +248,11 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.DB_SYSTEM:
SemanticConvetion.DB_SYSTEM_QDRANT,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_VECTORDB,
diff --git a/sdk/python/src/openlit/instrumentation/reka/async_reka.py b/sdk/python/src/openlit/instrumentation/reka/async_reka.py
index e9215110..46a210d6 100644
--- a/sdk/python/src/openlit/instrumentation/reka/async_reka.py
+++ b/sdk/python/src/openlit/instrumentation/reka/async_reka.py
@@ -5,7 +5,7 @@ Module for monitoring Reka API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
get_chat_model_cost,
@@ -81,9 +81,9 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "reka-core"))
@@ -128,11 +128,11 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_REKAAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
diff --git a/sdk/python/src/openlit/instrumentation/reka/reka.py b/sdk/python/src/openlit/instrumentation/reka/reka.py
index f530a79f..14287e37 100644
--- a/sdk/python/src/openlit/instrumentation/reka/reka.py
+++ b/sdk/python/src/openlit/instrumentation/reka/reka.py
@@ -5,7 +5,7 @@ Module for monitoring Reka API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
handle_exception,
get_chat_model_cost,
@@ -81,9 +81,9 @@ def chat(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "reka-core"))
@@ -128,11 +128,11 @@ def chat(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_REKAAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
diff --git a/sdk/python/src/openlit/instrumentation/together/async_together.py b/sdk/python/src/openlit/instrumentation/together/async_together.py
index a7eeb9bc..0b646d07 100644
--- a/sdk/python/src/openlit/instrumentation/together/async_together.py
+++ b/sdk/python/src/openlit/instrumentation/together/async_together.py
@@ -5,7 +5,7 @@ Module for monitoring Together calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
get_chat_model_cost,
get_image_model_cost,
@@ -135,9 +135,9 @@ def async_completion(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
self._response_id)
- self._span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- self._span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ self._span.set_attribute(SERVICE_NAME,
application_name)
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
self._kwargs.get(
@@ -188,11 +188,11 @@ def async_completion(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -286,9 +286,9 @@ def async_completion(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response_dict.get("id"))
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model",
@@ -395,11 +395,11 @@ def async_completion(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -495,9 +495,9 @@ def async_image_generate(gen_ai_endpoint, version, environment, application_name
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response.id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "black-forest-labs/FLUX.1-dev"))
@@ -530,11 +530,11 @@ def async_image_generate(gen_ai_endpoint, version, environment, application_name
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_IMAGE,
diff --git a/sdk/python/src/openlit/instrumentation/together/together.py b/sdk/python/src/openlit/instrumentation/together/together.py
index 08ebf9d3..27ca0032 100644
--- a/sdk/python/src/openlit/instrumentation/together/together.py
+++ b/sdk/python/src/openlit/instrumentation/together/together.py
@@ -5,7 +5,7 @@ Module for monitoring Together calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import (
get_chat_model_cost,
get_image_model_cost,
@@ -135,9 +135,9 @@ def completion(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
self._span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
self._response_id)
- self._span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ self._span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- self._span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ self._span.set_attribute(SERVICE_NAME,
application_name)
self._span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
self._kwargs.get(
@@ -188,11 +188,11 @@ def completion(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -286,9 +286,9 @@ def completion(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response_dict.get("id"))
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model",
@@ -395,11 +395,11 @@ def completion(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -495,9 +495,9 @@ def image_generate(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
response.id)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
kwargs.get("model", "black-forest-labs/FLUX.1-dev"))
@@ -530,11 +530,11 @@ def image_generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_TOGETHER,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_IMAGE,
diff --git a/sdk/python/src/openlit/instrumentation/transformers/transformers.py b/sdk/python/src/openlit/instrumentation/transformers/transformers.py
index f7f20d13..4d8592d5 100644
--- a/sdk/python/src/openlit/instrumentation/transformers/transformers.py
+++ b/sdk/python/src/openlit/instrumentation/transformers/transformers.py
@@ -5,7 +5,7 @@ Module for monitoring ChromaDB.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception, general_tokens
from openlit.semcov import SemanticConvetion
@@ -74,9 +74,9 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
gen_ai_endpoint)
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
SemanticConvetion.GEN_AI_SYSTEM_HUGGING_FACE)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_OPERATION,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
@@ -132,11 +132,11 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_HUGGING_FACE,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
diff --git a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py
index c1e63b25..e4a406a0 100644
--- a/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py
+++ b/sdk/python/src/openlit/instrumentation/vertexai/async_vertexai.py
@@ -6,7 +6,7 @@ Module for monitoring VertexAI API calls.
import logging
import math
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import get_chat_model_cost, get_embed_model_cost, handle_exception
from openlit.semcov import SemanticConvetion
@@ -86,9 +86,9 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_na
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -122,11 +122,11 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_na
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -172,9 +172,9 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_na
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -209,11 +209,11 @@ def generate_content_async(gen_ai_endpoint, version, environment, application_na
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -316,9 +316,9 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -352,11 +352,11 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -402,9 +402,9 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -439,11 +439,11 @@ def send_message_async(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -532,9 +532,9 @@ def predict_async(gen_ai_endpoint, version, environment, application_name, trace
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -568,11 +568,11 @@ def predict_async(gen_ai_endpoint, version, environment, application_name, trace
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -672,9 +672,9 @@ def predict_streaming_async(gen_ai_endpoint, version, environment, application_n
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -708,11 +708,11 @@ def predict_streaming_async(gen_ai_endpoint, version, environment, application_n
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -797,9 +797,9 @@ def start_chat_async(gen_ai_endpoint, version, environment, application_name, tr
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -833,11 +833,11 @@ def start_chat_async(gen_ai_endpoint, version, environment, application_name, tr
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -935,9 +935,9 @@ def start_chat_streaming_async(gen_ai_endpoint, version, environment, applicatio
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -971,11 +971,11 @@ def start_chat_streaming_async(gen_ai_endpoint, version, environment, applicatio
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -1056,9 +1056,9 @@ def embeddings_async(gen_ai_endpoint, version, environment, application_name, tr
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -1084,11 +1084,11 @@ def embeddings_async(gen_ai_endpoint, version, environment, application_name, tr
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py
index 75ee47e8..b0dba24f 100644
--- a/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py
+++ b/sdk/python/src/openlit/instrumentation/vertexai/vertexai.py
@@ -6,7 +6,7 @@ Module for monitoring VertexAI API calls.
import logging
import math
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import get_chat_model_cost, get_embed_model_cost, handle_exception
from openlit.semcov import SemanticConvetion
@@ -86,9 +86,9 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, tr
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -122,11 +122,11 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, tr
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -172,9 +172,9 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, tr
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -209,11 +209,11 @@ def generate_content(gen_ai_endpoint, version, environment, application_name, tr
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -316,9 +316,9 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracer
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -352,11 +352,11 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracer
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -402,9 +402,9 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracer
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -439,11 +439,11 @@ def send_message(gen_ai_endpoint, version, environment, application_name, tracer
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -532,9 +532,9 @@ def predict(gen_ai_endpoint, version, environment, application_name, tracer,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -568,11 +568,11 @@ def predict(gen_ai_endpoint, version, environment, application_name, tracer,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -672,9 +672,9 @@ def predict_streaming(gen_ai_endpoint, version, environment, application_name, t
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -708,11 +708,11 @@ def predict_streaming(gen_ai_endpoint, version, environment, application_name, t
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -797,9 +797,9 @@ def start_chat(gen_ai_endpoint, version, environment, application_name, tracer,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -833,11 +833,11 @@ def start_chat(gen_ai_endpoint, version, environment, application_name, tracer,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -935,9 +935,9 @@ def start_chat_streaming(gen_ai_endpoint, version, environment, application_name
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -971,11 +971,11 @@ def start_chat_streaming(gen_ai_endpoint, version, environment, application_name
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,
@@ -1056,9 +1056,9 @@ def embeddings(gen_ai_endpoint, version, environment, application_name, tracer,
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -1084,11 +1084,11 @@ def embeddings(gen_ai_endpoint, version, environment, application_name, tracer,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VERTEXAI,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_EMBEDDING,
diff --git a/sdk/python/src/openlit/instrumentation/vllm/vllm.py b/sdk/python/src/openlit/instrumentation/vllm/vllm.py
index 76d50e62..a7e4aedd 100644
--- a/sdk/python/src/openlit/instrumentation/vllm/vllm.py
+++ b/sdk/python/src/openlit/instrumentation/vllm/vllm.py
@@ -5,7 +5,7 @@ Module for monitoring vLLM API calls.
import logging
from opentelemetry.trace import SpanKind, Status, StatusCode
-from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
+from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
from openlit.__helpers import handle_exception, general_tokens
from openlit.semcov import SemanticConvetion
@@ -61,9 +61,9 @@ def generate(gen_ai_endpoint, version, environment, application_name,
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT)
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
gen_ai_endpoint)
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
+ span.set_attribute(DEPLOYMENT_ENVIRONMENT,
environment)
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
+ span.set_attribute(SERVICE_NAME,
application_name)
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
model)
@@ -112,11 +112,11 @@ def generate(gen_ai_endpoint, version, environment, application_name,
attributes = {
TELEMETRY_SDK_NAME:
"openlit",
- SemanticConvetion.GEN_AI_APPLICATION_NAME:
+ SERVICE_NAME:
application_name,
SemanticConvetion.GEN_AI_SYSTEM:
SemanticConvetion.GEN_AI_SYSTEM_VLLM,
- SemanticConvetion.GEN_AI_ENVIRONMENT:
+ DEPLOYMENT_ENVIRONMENT:
environment,
SemanticConvetion.GEN_AI_OPERATION:
SemanticConvetion.GEN_AI_OPERATION_TYPE_CHAT,