openlit 1.33.19__py3-none-any.whl → 1.33.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openlit/__helpers.py +64 -7
- openlit/__init__.py +3 -3
- openlit/evals/utils.py +7 -7
- openlit/guard/utils.py +7 -7
- openlit/instrumentation/ag2/ag2.py +24 -24
- openlit/instrumentation/ai21/ai21.py +3 -3
- openlit/instrumentation/ai21/async_ai21.py +3 -3
- openlit/instrumentation/ai21/utils.py +59 -59
- openlit/instrumentation/anthropic/anthropic.py +2 -2
- openlit/instrumentation/anthropic/async_anthropic.py +2 -2
- openlit/instrumentation/anthropic/utils.py +34 -34
- openlit/instrumentation/assemblyai/assemblyai.py +24 -24
- openlit/instrumentation/astra/astra.py +3 -3
- openlit/instrumentation/astra/async_astra.py +3 -3
- openlit/instrumentation/astra/utils.py +39 -39
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +2 -2
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +2 -2
- openlit/instrumentation/azure_ai_inference/utils.py +36 -36
- openlit/instrumentation/bedrock/bedrock.py +2 -2
- openlit/instrumentation/bedrock/utils.py +35 -35
- openlit/instrumentation/chroma/chroma.py +57 -57
- openlit/instrumentation/cohere/async_cohere.py +88 -88
- openlit/instrumentation/cohere/cohere.py +88 -88
- openlit/instrumentation/controlflow/controlflow.py +15 -15
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +14 -14
- openlit/instrumentation/crawl4ai/crawl4ai.py +14 -14
- openlit/instrumentation/crewai/crewai.py +22 -22
- openlit/instrumentation/dynamiq/dynamiq.py +19 -19
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +24 -25
- openlit/instrumentation/elevenlabs/elevenlabs.py +23 -25
- openlit/instrumentation/embedchain/embedchain.py +15 -15
- openlit/instrumentation/firecrawl/firecrawl.py +10 -10
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +33 -33
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +33 -33
- openlit/instrumentation/gpt4all/gpt4all.py +78 -78
- openlit/instrumentation/gpu/__init__.py +8 -8
- openlit/instrumentation/groq/async_groq.py +74 -74
- openlit/instrumentation/groq/groq.py +74 -74
- openlit/instrumentation/haystack/haystack.py +6 -6
- openlit/instrumentation/julep/async_julep.py +14 -14
- openlit/instrumentation/julep/julep.py +14 -14
- openlit/instrumentation/langchain/async_langchain.py +39 -39
- openlit/instrumentation/langchain/langchain.py +39 -39
- openlit/instrumentation/letta/letta.py +26 -26
- openlit/instrumentation/litellm/async_litellm.py +94 -94
- openlit/instrumentation/litellm/litellm.py +94 -94
- openlit/instrumentation/llamaindex/llamaindex.py +7 -7
- openlit/instrumentation/mem0/mem0.py +13 -13
- openlit/instrumentation/milvus/milvus.py +47 -47
- openlit/instrumentation/mistral/async_mistral.py +88 -88
- openlit/instrumentation/mistral/mistral.py +88 -88
- openlit/instrumentation/multion/async_multion.py +21 -21
- openlit/instrumentation/multion/multion.py +21 -21
- openlit/instrumentation/ollama/__init__.py +47 -34
- openlit/instrumentation/ollama/async_ollama.py +7 -5
- openlit/instrumentation/ollama/ollama.py +7 -5
- openlit/instrumentation/ollama/utils.py +58 -54
- openlit/instrumentation/openai/async_openai.py +225 -225
- openlit/instrumentation/openai/openai.py +225 -225
- openlit/instrumentation/openai_agents/openai_agents.py +11 -11
- openlit/instrumentation/phidata/phidata.py +15 -15
- openlit/instrumentation/pinecone/pinecone.py +43 -43
- openlit/instrumentation/premai/premai.py +86 -86
- openlit/instrumentation/qdrant/async_qdrant.py +95 -95
- openlit/instrumentation/qdrant/qdrant.py +99 -99
- openlit/instrumentation/reka/async_reka.py +33 -33
- openlit/instrumentation/reka/reka.py +33 -33
- openlit/instrumentation/together/async_together.py +90 -90
- openlit/instrumentation/together/together.py +90 -90
- openlit/instrumentation/transformers/__init__.py +11 -7
- openlit/instrumentation/transformers/transformers.py +32 -168
- openlit/instrumentation/transformers/utils.py +183 -0
- openlit/instrumentation/vertexai/async_vertexai.py +64 -64
- openlit/instrumentation/vertexai/vertexai.py +64 -64
- openlit/instrumentation/vllm/vllm.py +24 -24
- openlit/otel/metrics.py +11 -11
- openlit/semcov/__init__.py +3 -3
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/METADATA +8 -8
- openlit-1.33.21.dist-info/RECORD +132 -0
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/WHEEL +1 -1
- openlit-1.33.19.dist-info/RECORD +0 -131
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/LICENSE +0 -0
@@ -8,7 +8,7 @@ from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOY
|
|
8
8
|
from openlit.__helpers import (
|
9
9
|
handle_exception,
|
10
10
|
)
|
11
|
-
from openlit.semcov import
|
11
|
+
from openlit.semcov import SemanticConvention
|
12
12
|
|
13
13
|
# Initialize logger for logging potential issues and operations
|
14
14
|
logger = logging.getLogger(__name__)
|
@@ -21,16 +21,16 @@ def set_span_attributes(span, version, operation_name, environment,
|
|
21
21
|
|
22
22
|
# Set Span attributes (OTel Semconv)
|
23
23
|
span.set_attribute(TELEMETRY_SDK_NAME, 'openlit')
|
24
|
-
span.set_attribute(
|
25
|
-
span.set_attribute(
|
26
|
-
span.set_attribute(
|
27
|
-
span.set_attribute(
|
28
|
-
span.set_attribute(
|
24
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION, operation_name)
|
25
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM, SemanticConvention.GEN_AI_SYSTEM_AG2)
|
26
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS, server_address)
|
27
|
+
span.set_attribute(SemanticConvention.SERVER_PORT, server_port)
|
28
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL, request_model)
|
29
29
|
|
30
30
|
# Set Span attributes (Extras)
|
31
31
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
|
32
32
|
span.set_attribute(SERVICE_NAME, application_name)
|
33
|
-
span.set_attribute(
|
33
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION, version)
|
34
34
|
|
35
35
|
def create_agent(version, environment, application_name,
|
36
36
|
tracer, event_provider, pricing_info, capture_message_content, metrics, disable_metrics):
|
@@ -41,17 +41,17 @@ def create_agent(version, environment, application_name,
|
|
41
41
|
server_address, server_port = '127.0.0.1', 80
|
42
42
|
|
43
43
|
agent_name = kwargs.get('name', 'openai_agent')
|
44
|
-
span_name = f'{
|
44
|
+
span_name = f'{SemanticConvention.GEN_AI_OPERATION_TYPE_CREATE_AGENT} {agent_name}'
|
45
45
|
|
46
46
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
47
47
|
try:
|
48
48
|
response = wrapped(*args, **kwargs)
|
49
49
|
|
50
|
-
set_span_attributes(span, version,
|
50
|
+
set_span_attributes(span, version, SemanticConvention.GEN_AI_OPERATION_TYPE_CREATE_AGENT,
|
51
51
|
environment, application_name, server_address, server_port, kwargs.get('model', 'gpt-4o'))
|
52
|
-
span.set_attribute(
|
52
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_NAME, agent_name)
|
53
53
|
|
54
|
-
span.set_attribute(
|
54
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_DESCRIPTION, kwargs.get('instructions', ''))
|
55
55
|
|
56
56
|
span.set_status(Status(StatusCode.OK))
|
57
57
|
|
@@ -9,7 +9,7 @@ from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOY
|
|
9
9
|
from openlit.__helpers import (
|
10
10
|
handle_exception,
|
11
11
|
)
|
12
|
-
from openlit.semcov import
|
12
|
+
from openlit.semcov import SemanticConvention
|
13
13
|
|
14
14
|
# Initialize logger for logging potential issues and operations
|
15
15
|
logger = logging.getLogger(__name__)
|
@@ -56,33 +56,33 @@ def phidata_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
56
56
|
try:
|
57
57
|
# Set base span attribues
|
58
58
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
59
|
-
span.set_attribute(
|
60
|
-
|
61
|
-
span.set_attribute(
|
62
|
-
|
63
|
-
span.set_attribute(
|
59
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
60
|
+
SemanticConvention.GEN_AI_SYSTEM_PHIDATA)
|
61
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
62
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT)
|
63
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
64
64
|
gen_ai_endpoint)
|
65
65
|
span.set_attribute(SERVICE_NAME,
|
66
66
|
application_name)
|
67
67
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
68
68
|
environment)
|
69
|
-
span.set_attribute(
|
69
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ID,
|
70
70
|
getattr(instance, 'agent_id', '') or '')
|
71
|
-
span.set_attribute(
|
71
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ROLE,
|
72
72
|
getattr(instance, 'name', '') or '')
|
73
|
-
span.set_attribute(
|
73
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
74
74
|
getattr(getattr(instance, 'model', None), 'id', '') or '')
|
75
|
-
span.set_attribute(
|
75
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TOOLS,
|
76
76
|
str(getattr(instance, 'tools', '')) or '')
|
77
|
-
span.set_attribute(
|
77
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_CONTEXT,
|
78
78
|
str(getattr(instance, 'knowledge', '')) or '')
|
79
|
-
span.set_attribute(
|
79
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TASK,
|
80
80
|
str(getattr(instance, 'task', '')) or '')
|
81
|
-
span.set_attribute(
|
81
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_INSTRUCTIONS,
|
82
82
|
str(getattr(instance, 'instructions', '')) or '')
|
83
|
-
span.set_attribute(
|
83
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_STORAGE,
|
84
84
|
str(getattr(instance, 'storage', '')) or '')
|
85
|
-
span.set_attribute(
|
85
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ENABLE_HISTORY,
|
86
86
|
str(getattr(instance, 'add_history_to_messages', '')) or '')
|
87
87
|
|
88
88
|
span.set_status(Status(StatusCode.OK))
|
@@ -7,7 +7,7 @@ import logging
|
|
7
7
|
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
8
|
from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
|
9
9
|
from openlit.__helpers import handle_exception
|
10
|
-
from openlit.semcov import
|
10
|
+
from openlit.semcov import SemanticConvention
|
11
11
|
|
12
12
|
# Initialize logger for logging potential issues and operations
|
13
13
|
logger = logging.getLogger(__name__)
|
@@ -70,74 +70,74 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
70
70
|
|
71
71
|
try:
|
72
72
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
73
|
-
span.set_attribute(
|
73
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
74
74
|
gen_ai_endpoint)
|
75
75
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
76
76
|
environment)
|
77
77
|
span.set_attribute(SERVICE_NAME,
|
78
78
|
application_name)
|
79
|
-
span.set_attribute(
|
80
|
-
|
81
|
-
span.set_attribute(
|
82
|
-
|
79
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
80
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB)
|
81
|
+
span.set_attribute(SemanticConvention.DB_SYSTEM_NAME,
|
82
|
+
SemanticConvention.DB_SYSTEM_PINECONE)
|
83
83
|
|
84
84
|
if gen_ai_endpoint == "pinecone.create_index":
|
85
|
-
db_operation =
|
86
|
-
span.set_attribute(
|
87
|
-
|
88
|
-
span.set_attribute(
|
85
|
+
db_operation = SemanticConvention.DB_OPERATION_CREATE_INDEX
|
86
|
+
span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
|
87
|
+
SemanticConvention.DB_OPERATION_CREATE_INDEX)
|
88
|
+
span.set_attribute(SemanticConvention.DB_INDEX_NAME,
|
89
89
|
kwargs.get("name", ""))
|
90
|
-
span.set_attribute(
|
90
|
+
span.set_attribute(SemanticConvention.DB_INDEX_DIMENSION,
|
91
91
|
kwargs.get("dimensions", ""))
|
92
|
-
span.set_attribute(
|
92
|
+
span.set_attribute(SemanticConvention.DB_INDEX_METRIC,
|
93
93
|
kwargs.get("metric", ""))
|
94
|
-
span.set_attribute(
|
94
|
+
span.set_attribute(SemanticConvention.DB_INDEX_SPEC,
|
95
95
|
str(kwargs.get("spec", "")))
|
96
96
|
|
97
97
|
elif gen_ai_endpoint == "pinecone.query":
|
98
|
-
db_operation =
|
99
|
-
span.set_attribute(
|
100
|
-
|
101
|
-
span.set_attribute(
|
98
|
+
db_operation = SemanticConvention.DB_OPERATION_QUERY
|
99
|
+
span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
|
100
|
+
SemanticConvention.DB_OPERATION_QUERY)
|
101
|
+
span.set_attribute(SemanticConvention.DB_STATEMENT,
|
102
102
|
str(kwargs.get("vector")))
|
103
|
-
span.set_attribute(
|
103
|
+
span.set_attribute(SemanticConvention.DB_N_RESULTS,
|
104
104
|
kwargs.get("top_k", ""))
|
105
|
-
span.set_attribute(
|
105
|
+
span.set_attribute(SemanticConvention.DB_FILTER,
|
106
106
|
str(kwargs.get("filter", "")))
|
107
|
-
span.set_attribute(
|
107
|
+
span.set_attribute(SemanticConvention.DB_NAMESPACE,
|
108
108
|
str(kwargs.get("namespace", "")))
|
109
109
|
|
110
110
|
elif gen_ai_endpoint == "pinecone.update":
|
111
|
-
db_operation =
|
112
|
-
span.set_attribute(
|
113
|
-
|
114
|
-
span.set_attribute(
|
111
|
+
db_operation = SemanticConvention.DB_OPERATION_UPDATE
|
112
|
+
span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
|
113
|
+
SemanticConvention.DB_OPERATION_UPDATE)
|
114
|
+
span.set_attribute(SemanticConvention.DB_UPDATE_ID,
|
115
115
|
kwargs.get("id",""))
|
116
|
-
span.set_attribute(
|
116
|
+
span.set_attribute(SemanticConvention.DB_UPDATE_VALUES,
|
117
117
|
str(kwargs.get("values",[])))
|
118
|
-
span.set_attribute(
|
118
|
+
span.set_attribute(SemanticConvention.DB_NAMESPACE,
|
119
119
|
str(kwargs.get("namespace", "")))
|
120
|
-
span.set_attribute(
|
120
|
+
span.set_attribute(SemanticConvention.DB_UPDATE_METADATA,
|
121
121
|
str(kwargs.get("set_metadata", "")))
|
122
122
|
|
123
123
|
elif gen_ai_endpoint == "pinecone.upsert":
|
124
|
-
db_operation =
|
125
|
-
span.set_attribute(
|
126
|
-
|
127
|
-
span.set_attribute(
|
124
|
+
db_operation = SemanticConvention.DB_OPERATION_UPSERT
|
125
|
+
span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
|
126
|
+
SemanticConvention.DB_OPERATION_UPSERT)
|
127
|
+
span.set_attribute(SemanticConvention.DB_VECTOR_COUNT,
|
128
128
|
object_count(kwargs.get("vectors")))
|
129
129
|
|
130
130
|
elif gen_ai_endpoint == "pinecone.delete":
|
131
|
-
db_operation =
|
132
|
-
span.set_attribute(
|
133
|
-
|
134
|
-
span.set_attribute(
|
131
|
+
db_operation = SemanticConvention.DB_OPERATION_DELETE
|
132
|
+
span.set_attribute(SemanticConvention.DB_OPERATION_NAME,
|
133
|
+
SemanticConvention.DB_OPERATION_DELETE)
|
134
|
+
span.set_attribute(SemanticConvention.DB_ID_COUNT,
|
135
135
|
object_count(kwargs.get("ids")))
|
136
|
-
span.set_attribute(
|
136
|
+
span.set_attribute(SemanticConvention.DB_FILTER,
|
137
137
|
str(kwargs.get("filter", "")))
|
138
|
-
span.set_attribute(
|
138
|
+
span.set_attribute(SemanticConvention.DB_DELETE_ALL,
|
139
139
|
kwargs.get("delete_all", False))
|
140
|
-
span.set_attribute(
|
140
|
+
span.set_attribute(SemanticConvention.DB_NAMESPACE,
|
141
141
|
kwargs.get("namespace", ""))
|
142
142
|
|
143
143
|
span.set_status(Status(StatusCode.OK))
|
@@ -148,13 +148,13 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
148
148
|
"openlit",
|
149
149
|
SERVICE_NAME:
|
150
150
|
application_name,
|
151
|
-
|
152
|
-
|
151
|
+
SemanticConvention.DB_SYSTEM_NAME:
|
152
|
+
SemanticConvention.DB_SYSTEM_PINECONE,
|
153
153
|
DEPLOYMENT_ENVIRONMENT:
|
154
154
|
environment,
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
SemanticConvention.GEN_AI_OPERATION:
|
156
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_VECTORDB,
|
157
|
+
SemanticConvention.DB_OPERATION_NAME:
|
158
158
|
db_operation
|
159
159
|
}
|
160
160
|
|
@@ -16,7 +16,7 @@ from openlit.__helpers import (
|
|
16
16
|
create_metrics_attributes,
|
17
17
|
set_server_address_and_port
|
18
18
|
)
|
19
|
-
from openlit.semcov import
|
19
|
+
from openlit.semcov import SemanticConvention
|
20
20
|
|
21
21
|
# Initialize logger for logging potential issues and operations
|
22
22
|
logger = logging.getLogger(__name__)
|
@@ -139,45 +139,45 @@ def chat(version, environment, application_name,
|
|
139
139
|
|
140
140
|
# Set Span attributes (OTel Semconv)
|
141
141
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
142
|
-
self._span.set_attribute(
|
143
|
-
|
144
|
-
self._span.set_attribute(
|
145
|
-
|
146
|
-
self._span.set_attribute(
|
142
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
143
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
144
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
145
|
+
SemanticConvention.GEN_AI_SYSTEM_PREMAI)
|
146
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
147
147
|
request_model)
|
148
|
-
self._span.set_attribute(
|
148
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
149
149
|
self._kwargs.get("seed", ""))
|
150
|
-
self._span.set_attribute(
|
150
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
151
151
|
self._server_port)
|
152
|
-
self._span.set_attribute(
|
152
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
153
153
|
self._kwargs.get("frequency_penalty", 0.0))
|
154
|
-
self._span.set_attribute(
|
154
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
155
155
|
self._kwargs.get("max_tokens", -1))
|
156
|
-
self._span.set_attribute(
|
156
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
157
157
|
self._kwargs.get("presence_penalty", 0.0))
|
158
|
-
self._span.set_attribute(
|
158
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
159
159
|
self._kwargs.get("stop", []))
|
160
|
-
self._span.set_attribute(
|
160
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
161
161
|
self._kwargs.get("temperature", 1.0))
|
162
|
-
self._span.set_attribute(
|
162
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
163
163
|
self._kwargs.get("top_p", 1.0))
|
164
|
-
self._span.set_attribute(
|
164
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
165
165
|
[self._finish_reason])
|
166
|
-
self._span.set_attribute(
|
166
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
167
167
|
self._response_id)
|
168
|
-
self._span.set_attribute(
|
168
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
169
169
|
self._response_model)
|
170
|
-
self._span.set_attribute(
|
170
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
171
171
|
input_tokens)
|
172
|
-
self._span.set_attribute(
|
172
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
173
173
|
output_tokens)
|
174
|
-
self._span.set_attribute(
|
174
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
175
175
|
self._server_address)
|
176
176
|
if isinstance(self._llmresponse, str):
|
177
|
-
self._span.set_attribute(
|
177
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
178
178
|
"text")
|
179
179
|
else:
|
180
|
-
self._span.set_attribute(
|
180
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
181
181
|
"json")
|
182
182
|
|
183
183
|
# Set Span attributes (Extra)
|
@@ -185,31 +185,31 @@ def chat(version, environment, application_name,
|
|
185
185
|
environment)
|
186
186
|
self._span.set_attribute(SERVICE_NAME,
|
187
187
|
application_name)
|
188
|
-
self._span.set_attribute(
|
188
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
189
189
|
self._kwargs.get("user", ""))
|
190
|
-
self._span.set_attribute(
|
190
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
191
191
|
True)
|
192
|
-
self._span.set_attribute(
|
192
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
193
193
|
input_tokens + output_tokens)
|
194
|
-
self._span.set_attribute(
|
194
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
195
195
|
cost)
|
196
|
-
self._span.set_attribute(
|
196
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
197
197
|
self._tbt)
|
198
|
-
self._span.set_attribute(
|
198
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
199
199
|
self._ttft)
|
200
|
-
self._span.set_attribute(
|
200
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
201
201
|
version)
|
202
202
|
if capture_message_content:
|
203
203
|
self._span.add_event(
|
204
|
-
name=
|
204
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
205
205
|
attributes={
|
206
|
-
|
206
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
207
207
|
},
|
208
208
|
)
|
209
209
|
self._span.add_event(
|
210
|
-
name=
|
210
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
211
211
|
attributes={
|
212
|
-
|
212
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
213
213
|
},
|
214
214
|
)
|
215
215
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -218,8 +218,8 @@ def chat(version, environment, application_name,
|
|
218
218
|
attributes = create_metrics_attributes(
|
219
219
|
service_name=application_name,
|
220
220
|
deployment_environment=environment,
|
221
|
-
operation=
|
222
|
-
system=
|
221
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
222
|
+
system=SemanticConvention.GEN_AI_SYSTEM_PREMAI,
|
223
223
|
request_model=request_model,
|
224
224
|
server_address=self._server_address,
|
225
225
|
server_port=self._server_port,
|
@@ -271,7 +271,7 @@ def chat(version, environment, application_name,
|
|
271
271
|
server_address, server_port = set_server_address_and_port(instance, "app.premai.io", 443)
|
272
272
|
request_model = kwargs.get("model", "gpt-4o-mini")
|
273
273
|
|
274
|
-
span_name = f"{
|
274
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
275
275
|
|
276
276
|
# pylint: disable=no-else-return
|
277
277
|
if streaming:
|
@@ -317,35 +317,35 @@ def chat(version, environment, application_name,
|
|
317
317
|
|
318
318
|
# Set base span attribues (OTel Semconv)
|
319
319
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
320
|
-
span.set_attribute(
|
321
|
-
|
322
|
-
span.set_attribute(
|
323
|
-
|
324
|
-
span.set_attribute(
|
320
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
321
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
322
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
323
|
+
SemanticConvention.GEN_AI_SYSTEM_PREMAI)
|
324
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
325
325
|
request_model)
|
326
|
-
span.set_attribute(
|
326
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
327
327
|
server_port)
|
328
|
-
span.set_attribute(
|
328
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
329
329
|
kwargs.get("frequency_penalty", 0.0))
|
330
|
-
span.set_attribute(
|
330
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
331
331
|
kwargs.get("max_tokens", -1))
|
332
|
-
span.set_attribute(
|
332
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
333
333
|
kwargs.get("presence_penalty", 0.0))
|
334
|
-
span.set_attribute(
|
334
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
335
335
|
kwargs.get("stop", []))
|
336
|
-
span.set_attribute(
|
336
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
337
337
|
kwargs.get("temperature", 1.0))
|
338
|
-
span.set_attribute(
|
338
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
339
339
|
kwargs.get("top_p", 1.0))
|
340
|
-
span.set_attribute(
|
340
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
341
341
|
response.additional_properties.get('id'))
|
342
|
-
span.set_attribute(
|
342
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
343
343
|
response.model)
|
344
|
-
span.set_attribute(
|
344
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
345
345
|
input_tokens)
|
346
|
-
span.set_attribute(
|
346
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
347
347
|
output_tokens)
|
348
|
-
span.set_attribute(
|
348
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
349
349
|
server_address)
|
350
350
|
|
351
351
|
# Set base span attribues (Extras)
|
@@ -353,39 +353,39 @@ def chat(version, environment, application_name,
|
|
353
353
|
environment)
|
354
354
|
span.set_attribute(SERVICE_NAME,
|
355
355
|
application_name)
|
356
|
-
span.set_attribute(
|
356
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
357
357
|
False)
|
358
|
-
span.set_attribute(
|
358
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
359
359
|
input_tokens + output_tokens)
|
360
|
-
span.set_attribute(
|
360
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
361
361
|
cost)
|
362
|
-
span.set_attribute(
|
362
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
363
363
|
end_time - start_time)
|
364
|
-
span.set_attribute(
|
364
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
365
365
|
version)
|
366
366
|
if capture_message_content:
|
367
367
|
span.add_event(
|
368
|
-
name=
|
368
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
369
369
|
attributes={
|
370
|
-
|
370
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
371
371
|
},
|
372
372
|
)
|
373
373
|
span.add_event(
|
374
|
-
name=
|
374
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
375
375
|
attributes={
|
376
|
-
|
376
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response.choices[0].message.content),
|
377
377
|
},
|
378
378
|
)
|
379
379
|
|
380
380
|
if kwargs.get('tools'):
|
381
|
-
span.set_attribute(
|
381
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
382
382
|
str(response.choices[0].message.tool_calls))
|
383
383
|
|
384
384
|
if kwargs.get('response_format', '') != '':
|
385
|
-
span.set_attribute(
|
385
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
386
386
|
"json")
|
387
387
|
else:
|
388
|
-
span.set_attribute(
|
388
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
389
389
|
"text")
|
390
390
|
|
391
391
|
span.set_status(Status(StatusCode.OK))
|
@@ -394,8 +394,8 @@ def chat(version, environment, application_name,
|
|
394
394
|
attributes = create_metrics_attributes(
|
395
395
|
service_name=application_name,
|
396
396
|
deployment_environment=environment,
|
397
|
-
operation=
|
398
|
-
system=
|
397
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
398
|
+
system=SemanticConvention.GEN_AI_SYSTEM_PREMAI,
|
399
399
|
request_model=request_model,
|
400
400
|
server_address=server_address,
|
401
401
|
server_port=server_port,
|
@@ -465,7 +465,7 @@ def embedding(version, environment, application_name,
|
|
465
465
|
server_address, server_port = set_server_address_and_port(instance, "app.premai.io", 443)
|
466
466
|
request_model = kwargs.get("model", "text-embedding-ada-002")
|
467
467
|
|
468
|
-
span_name = f"{
|
468
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
|
469
469
|
|
470
470
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
471
471
|
start_time = time.time()
|
@@ -481,21 +481,21 @@ def embedding(version, environment, application_name,
|
|
481
481
|
|
482
482
|
# Set Span attributes (OTel Semconv)
|
483
483
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
484
|
-
span.set_attribute(
|
485
|
-
|
486
|
-
span.set_attribute(
|
487
|
-
|
488
|
-
span.set_attribute(
|
484
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
485
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING)
|
486
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
487
|
+
SemanticConvention.GEN_AI_SYSTEM_PREMAI)
|
488
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
489
489
|
request_model)
|
490
|
-
span.set_attribute(
|
490
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_ENCODING_FORMATS,
|
491
491
|
[kwargs.get('encoding_format', 'float')])
|
492
|
-
span.set_attribute(
|
492
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
493
493
|
response.model)
|
494
|
-
span.set_attribute(
|
494
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
495
495
|
server_address)
|
496
|
-
span.set_attribute(
|
496
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
497
497
|
server_port)
|
498
|
-
span.set_attribute(
|
498
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
499
499
|
input_tokens)
|
500
500
|
|
501
501
|
# Set Span attributes (Extras)
|
@@ -503,20 +503,20 @@ def embedding(version, environment, application_name,
|
|
503
503
|
environment)
|
504
504
|
span.set_attribute(SERVICE_NAME,
|
505
505
|
application_name)
|
506
|
-
span.set_attribute(
|
506
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
507
507
|
kwargs.get("user", ""))
|
508
|
-
span.set_attribute(
|
508
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
509
509
|
input_tokens)
|
510
|
-
span.set_attribute(
|
510
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
511
511
|
cost)
|
512
|
-
span.set_attribute(
|
512
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
513
513
|
version)
|
514
514
|
|
515
515
|
if capture_message_content:
|
516
516
|
span.add_event(
|
517
|
-
name=
|
517
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
518
518
|
attributes={
|
519
|
-
|
519
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: str(kwargs.get("input", "")),
|
520
520
|
},
|
521
521
|
)
|
522
522
|
|
@@ -526,8 +526,8 @@ def embedding(version, environment, application_name,
|
|
526
526
|
attributes = create_metrics_attributes(
|
527
527
|
service_name=application_name,
|
528
528
|
deployment_environment=environment,
|
529
|
-
operation=
|
530
|
-
system=
|
529
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING,
|
530
|
+
system=SemanticConvention.GEN_AI_SYSTEM_PREMAI,
|
531
531
|
request_model=request_model,
|
532
532
|
server_address=server_address,
|
533
533
|
server_port=server_port,
|