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
@@ -12,7 +12,7 @@ from openlit.__helpers import (
|
|
12
12
|
create_metrics_attributes,
|
13
13
|
set_server_address_and_port
|
14
14
|
)
|
15
|
-
from openlit.semcov import
|
15
|
+
from openlit.semcov import SemanticConvention
|
16
16
|
|
17
17
|
# Initialize logger for logging potential issues and operations
|
18
18
|
logger = logging.getLogger(__name__)
|
@@ -54,7 +54,7 @@ def async_chat(version, environment, application_name,
|
|
54
54
|
server_address, server_port = set_server_address_and_port(instance, "api.reka.ai", 443)
|
55
55
|
request_model = kwargs.get("model", "reka-core-20240501")
|
56
56
|
|
57
|
-
span_name = f"{
|
57
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
58
58
|
|
59
59
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
60
60
|
start_time = time.time()
|
@@ -89,41 +89,41 @@ def async_chat(version, environment, application_name,
|
|
89
89
|
|
90
90
|
# Set Span attributes (OTel Semconv)
|
91
91
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
92
|
-
span.set_attribute(
|
93
|
-
|
94
|
-
span.set_attribute(
|
95
|
-
|
96
|
-
span.set_attribute(
|
92
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
93
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
94
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
95
|
+
SemanticConvention.GEN_AI_SYSTEM_REKAAI)
|
96
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
97
97
|
request_model)
|
98
|
-
span.set_attribute(
|
98
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
99
99
|
server_port)
|
100
|
-
span.set_attribute(
|
100
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
101
101
|
kwargs.get("seed", ""))
|
102
|
-
span.set_attribute(
|
102
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
103
103
|
kwargs.get("max_tokens", -1))
|
104
|
-
span.set_attribute(
|
104
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
105
105
|
kwargs.get("stop", []))
|
106
|
-
span.set_attribute(
|
106
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
107
107
|
kwargs.get("presence_penalty", 0.0))
|
108
|
-
span.set_attribute(
|
108
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
109
109
|
kwargs.get("temperature", 0.4))
|
110
|
-
span.set_attribute(
|
110
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K,
|
111
111
|
kwargs.get("top_k", 1.0))
|
112
|
-
span.set_attribute(
|
112
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
113
113
|
kwargs.get("top_p", 1.0))
|
114
|
-
span.set_attribute(
|
114
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
115
115
|
[response.responses[0].finish_reason])
|
116
|
-
span.set_attribute(
|
116
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
117
117
|
response.id)
|
118
|
-
span.set_attribute(
|
118
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
119
119
|
response.model)
|
120
|
-
span.set_attribute(
|
120
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
121
121
|
input_tokens)
|
122
|
-
span.set_attribute(
|
122
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
123
123
|
output_tokens)
|
124
|
-
span.set_attribute(
|
124
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
125
125
|
server_address)
|
126
|
-
span.set_attribute(
|
126
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
127
127
|
'text')
|
128
128
|
|
129
129
|
# Set Span attributes (Extra)
|
@@ -131,28 +131,28 @@ def async_chat(version, environment, application_name,
|
|
131
131
|
environment)
|
132
132
|
span.set_attribute(SERVICE_NAME,
|
133
133
|
application_name)
|
134
|
-
span.set_attribute(
|
134
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
135
135
|
False)
|
136
|
-
span.set_attribute(
|
136
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
137
137
|
input_tokens + output_tokens)
|
138
|
-
span.set_attribute(
|
138
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
139
139
|
cost)
|
140
|
-
span.set_attribute(
|
140
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
141
141
|
end_time - start_time)
|
142
|
-
span.set_attribute(
|
142
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
143
143
|
version)
|
144
144
|
|
145
145
|
if capture_message_content:
|
146
146
|
span.add_event(
|
147
|
-
name=
|
147
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
148
148
|
attributes={
|
149
|
-
|
149
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
150
150
|
},
|
151
151
|
)
|
152
152
|
span.add_event(
|
153
|
-
name=
|
153
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
154
154
|
attributes={
|
155
|
-
|
155
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: response.responses[0].message.content,
|
156
156
|
},
|
157
157
|
)
|
158
158
|
|
@@ -162,8 +162,8 @@ def async_chat(version, environment, application_name,
|
|
162
162
|
attributes = create_metrics_attributes(
|
163
163
|
service_name=application_name,
|
164
164
|
deployment_environment=environment,
|
165
|
-
operation=
|
166
|
-
system=
|
165
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
166
|
+
system=SemanticConvention.GEN_AI_SYSTEM_REKAAI,
|
167
167
|
request_model=request_model,
|
168
168
|
server_address=server_address,
|
169
169
|
server_port=server_port,
|
@@ -12,7 +12,7 @@ from openlit.__helpers import (
|
|
12
12
|
create_metrics_attributes,
|
13
13
|
set_server_address_and_port
|
14
14
|
)
|
15
|
-
from openlit.semcov import
|
15
|
+
from openlit.semcov import SemanticConvention
|
16
16
|
|
17
17
|
# Initialize logger for logging potential issues and operations
|
18
18
|
logger = logging.getLogger(__name__)
|
@@ -54,7 +54,7 @@ def chat(version, environment, application_name,
|
|
54
54
|
server_address, server_port = set_server_address_and_port(instance, "api.reka.ai", 443)
|
55
55
|
request_model = kwargs.get("model", "reka-core-20240501")
|
56
56
|
|
57
|
-
span_name = f"{
|
57
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
58
58
|
|
59
59
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
60
60
|
start_time = time.time()
|
@@ -89,41 +89,41 @@ def chat(version, environment, application_name,
|
|
89
89
|
|
90
90
|
# Set Span attributes (OTel Semconv)
|
91
91
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
92
|
-
span.set_attribute(
|
93
|
-
|
94
|
-
span.set_attribute(
|
95
|
-
|
96
|
-
span.set_attribute(
|
92
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
93
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
94
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
95
|
+
SemanticConvention.GEN_AI_SYSTEM_REKAAI)
|
96
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
97
97
|
request_model)
|
98
|
-
span.set_attribute(
|
98
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
99
99
|
server_port)
|
100
|
-
span.set_attribute(
|
100
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
101
101
|
kwargs.get("seed", ""))
|
102
|
-
span.set_attribute(
|
102
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
103
103
|
kwargs.get("max_tokens", -1))
|
104
|
-
span.set_attribute(
|
104
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
105
105
|
kwargs.get("stop", []))
|
106
|
-
span.set_attribute(
|
106
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
107
107
|
kwargs.get("presence_penalty", 0.0))
|
108
|
-
span.set_attribute(
|
108
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
109
109
|
kwargs.get("temperature", 0.4))
|
110
|
-
span.set_attribute(
|
110
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K,
|
111
111
|
kwargs.get("top_k", 1.0))
|
112
|
-
span.set_attribute(
|
112
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
113
113
|
kwargs.get("top_p", 1.0))
|
114
|
-
span.set_attribute(
|
114
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
115
115
|
[response.responses[0].finish_reason])
|
116
|
-
span.set_attribute(
|
116
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
117
117
|
response.id)
|
118
|
-
span.set_attribute(
|
118
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
119
119
|
response.model)
|
120
|
-
span.set_attribute(
|
120
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
121
121
|
input_tokens)
|
122
|
-
span.set_attribute(
|
122
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
123
123
|
output_tokens)
|
124
|
-
span.set_attribute(
|
124
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
125
125
|
server_address)
|
126
|
-
span.set_attribute(
|
126
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
127
127
|
'text')
|
128
128
|
|
129
129
|
# Set Span attributes (Extra)
|
@@ -131,28 +131,28 @@ def chat(version, environment, application_name,
|
|
131
131
|
environment)
|
132
132
|
span.set_attribute(SERVICE_NAME,
|
133
133
|
application_name)
|
134
|
-
span.set_attribute(
|
134
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
135
135
|
False)
|
136
|
-
span.set_attribute(
|
136
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
137
137
|
input_tokens + output_tokens)
|
138
|
-
span.set_attribute(
|
138
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
139
139
|
cost)
|
140
|
-
span.set_attribute(
|
140
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
141
141
|
end_time - start_time)
|
142
|
-
span.set_attribute(
|
142
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
143
143
|
version)
|
144
144
|
|
145
145
|
if capture_message_content:
|
146
146
|
span.add_event(
|
147
|
-
name=
|
147
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
148
148
|
attributes={
|
149
|
-
|
149
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
150
150
|
},
|
151
151
|
)
|
152
152
|
span.add_event(
|
153
|
-
name=
|
153
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
154
154
|
attributes={
|
155
|
-
|
155
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: response.responses[0].message.content,
|
156
156
|
},
|
157
157
|
)
|
158
158
|
|
@@ -162,8 +162,8 @@ def chat(version, environment, application_name,
|
|
162
162
|
attributes = create_metrics_attributes(
|
163
163
|
service_name=application_name,
|
164
164
|
deployment_environment=environment,
|
165
|
-
operation=
|
166
|
-
system=
|
165
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
166
|
+
system=SemanticConvention.GEN_AI_SYSTEM_REKAAI,
|
167
167
|
request_model=request_model,
|
168
168
|
server_address=server_address,
|
169
169
|
server_port=server_port,
|
@@ -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__)
|
@@ -157,46 +157,46 @@ def async_completion(version, environment, application_name,
|
|
157
157
|
|
158
158
|
# Set Span attributes (OTel Semconv)
|
159
159
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
160
|
-
self._span.set_attribute(
|
161
|
-
|
162
|
-
self._span.set_attribute(
|
163
|
-
|
164
|
-
self._span.set_attribute(
|
160
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
161
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
162
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
163
|
+
SemanticConvention.GEN_AI_SYSTEM_TOGETHER)
|
164
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
165
165
|
request_model)
|
166
|
-
self._span.set_attribute(
|
166
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
167
167
|
self._kwargs.get("seed", ""))
|
168
|
-
self._span.set_attribute(
|
168
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
169
169
|
self._server_port)
|
170
|
-
self._span.set_attribute(
|
170
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
171
171
|
self._kwargs.get("frequency_penalty", 0.0))
|
172
|
-
self._span.set_attribute(
|
172
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
173
173
|
self._kwargs.get("max_tokens", -1))
|
174
|
-
self._span.set_attribute(
|
174
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
175
175
|
self._kwargs.get("presence_penalty", 0.0))
|
176
|
-
self._span.set_attribute(
|
176
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
177
177
|
self._kwargs.get("stop", []))
|
178
|
-
self._span.set_attribute(
|
178
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
179
179
|
self._kwargs.get("temperature", 1.0))
|
180
|
-
self._span.set_attribute(
|
180
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
181
181
|
self._kwargs.get("top_p", 1.0))
|
182
|
-
self._span.set_attribute(
|
182
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
183
183
|
[self._finish_reason])
|
184
|
-
self._span.set_attribute(
|
184
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
185
185
|
self._response_id)
|
186
|
-
self._span.set_attribute(
|
186
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
187
187
|
self._response_model)
|
188
|
-
self._span.set_attribute(
|
188
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
189
189
|
self._input_tokens)
|
190
|
-
self._span.set_attribute(
|
190
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
191
191
|
self._output_tokens)
|
192
|
-
self._span.set_attribute(
|
192
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
193
193
|
self._server_address)
|
194
194
|
|
195
195
|
if isinstance(self._llmresponse, str):
|
196
|
-
self._span.set_attribute(
|
196
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
197
197
|
"text")
|
198
198
|
else:
|
199
|
-
self._span.set_attribute(
|
199
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
200
200
|
"json")
|
201
201
|
|
202
202
|
# Set Span attributes (Extra)
|
@@ -204,31 +204,31 @@ def async_completion(version, environment, application_name,
|
|
204
204
|
environment)
|
205
205
|
self._span.set_attribute(SERVICE_NAME,
|
206
206
|
application_name)
|
207
|
-
self._span.set_attribute(
|
207
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
208
208
|
self._kwargs.get("user", ""))
|
209
|
-
self._span.set_attribute(
|
209
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
210
210
|
True)
|
211
|
-
self._span.set_attribute(
|
211
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
212
212
|
self._input_tokens + self._output_tokens)
|
213
|
-
self._span.set_attribute(
|
213
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
214
214
|
cost)
|
215
|
-
self._span.set_attribute(
|
215
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
216
216
|
self._tbt)
|
217
|
-
self._span.set_attribute(
|
217
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
218
218
|
self._ttft)
|
219
|
-
self._span.set_attribute(
|
219
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
220
220
|
version)
|
221
221
|
if capture_message_content:
|
222
222
|
self._span.add_event(
|
223
|
-
name=
|
223
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
224
224
|
attributes={
|
225
|
-
|
225
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
226
226
|
},
|
227
227
|
)
|
228
228
|
self._span.add_event(
|
229
|
-
name=
|
229
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
230
230
|
attributes={
|
231
|
-
|
231
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
232
232
|
},
|
233
233
|
)
|
234
234
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -237,8 +237,8 @@ def async_completion(version, environment, application_name,
|
|
237
237
|
attributes = create_metrics_attributes(
|
238
238
|
service_name=application_name,
|
239
239
|
deployment_environment=environment,
|
240
|
-
operation=
|
241
|
-
system=
|
240
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
241
|
+
system=SemanticConvention.GEN_AI_SYSTEM_TOGETHER,
|
242
242
|
request_model=request_model,
|
243
243
|
server_address=self._server_address,
|
244
244
|
server_port=self._server_port,
|
@@ -290,7 +290,7 @@ def async_completion(version, environment, application_name,
|
|
290
290
|
server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
|
291
291
|
request_model = kwargs.get("model", "gpt-4o")
|
292
292
|
|
293
|
-
span_name = f"{
|
293
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
294
294
|
|
295
295
|
# pylint: disable=no-else-return
|
296
296
|
if streaming:
|
@@ -338,37 +338,37 @@ def async_completion(version, environment, application_name,
|
|
338
338
|
|
339
339
|
# Set base span attribues (OTel Semconv)
|
340
340
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
341
|
-
span.set_attribute(
|
342
|
-
|
343
|
-
span.set_attribute(
|
344
|
-
|
345
|
-
span.set_attribute(
|
341
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
342
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
343
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
344
|
+
SemanticConvention.GEN_AI_SYSTEM_TOGETHER)
|
345
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
346
346
|
request_model)
|
347
|
-
span.set_attribute(
|
347
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
348
348
|
kwargs.get("seed", ""))
|
349
|
-
span.set_attribute(
|
349
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
350
350
|
server_port)
|
351
|
-
span.set_attribute(
|
351
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
352
352
|
kwargs.get("frequency_penalty", 0.0))
|
353
|
-
span.set_attribute(
|
353
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
354
354
|
kwargs.get("max_tokens", -1))
|
355
|
-
span.set_attribute(
|
355
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
356
356
|
kwargs.get("presence_penalty", 0.0))
|
357
|
-
span.set_attribute(
|
357
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
358
358
|
kwargs.get("stop", []))
|
359
|
-
span.set_attribute(
|
359
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
360
360
|
kwargs.get("temperature", 1.0))
|
361
|
-
span.set_attribute(
|
361
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
362
362
|
kwargs.get("top_p", 1.0))
|
363
|
-
span.set_attribute(
|
363
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
364
364
|
response_dict.get("id"))
|
365
|
-
span.set_attribute(
|
365
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
366
366
|
response_dict.get('model'))
|
367
|
-
span.set_attribute(
|
367
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
368
368
|
input_tokens)
|
369
|
-
span.set_attribute(
|
369
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
370
370
|
output_tokens)
|
371
|
-
span.set_attribute(
|
371
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
372
372
|
server_address)
|
373
373
|
|
374
374
|
# Set base span attribues (Extras)
|
@@ -376,46 +376,46 @@ def async_completion(version, environment, application_name,
|
|
376
376
|
environment)
|
377
377
|
span.set_attribute(SERVICE_NAME,
|
378
378
|
application_name)
|
379
|
-
span.set_attribute(
|
379
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
380
380
|
kwargs.get("user", ""))
|
381
|
-
span.set_attribute(
|
381
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
382
382
|
False)
|
383
|
-
span.set_attribute(
|
383
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
384
384
|
input_tokens + output_tokens)
|
385
|
-
span.set_attribute(
|
385
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
386
386
|
cost)
|
387
|
-
span.set_attribute(
|
387
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
388
388
|
end_time - start_time)
|
389
|
-
span.set_attribute(
|
389
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
390
390
|
version)
|
391
391
|
if capture_message_content:
|
392
392
|
span.add_event(
|
393
|
-
name=
|
393
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
394
394
|
attributes={
|
395
|
-
|
395
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
396
396
|
},
|
397
397
|
)
|
398
398
|
|
399
399
|
for i in range(kwargs.get('n',1)):
|
400
|
-
span.set_attribute(
|
400
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
401
401
|
[str(response_dict.get('choices')[i].get('finish_reason'))])
|
402
402
|
if capture_message_content:
|
403
403
|
span.add_event(
|
404
|
-
name=
|
404
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
405
405
|
attributes={
|
406
406
|
# pylint: disable=line-too-long
|
407
|
-
|
407
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),
|
408
408
|
},
|
409
409
|
)
|
410
410
|
if kwargs.get('tools'):
|
411
|
-
span.set_attribute(
|
411
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
412
412
|
str(response_dict.get('choices')[i].get('message').get('tool_calls')))
|
413
413
|
|
414
414
|
if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):
|
415
|
-
span.set_attribute(
|
415
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
416
416
|
"text")
|
417
417
|
elif response_dict.get('choices')[i].get('message').get('content') is not None:
|
418
|
-
span.set_attribute(
|
418
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
419
419
|
"json")
|
420
420
|
|
421
421
|
span.set_status(Status(StatusCode.OK))
|
@@ -424,8 +424,8 @@ def async_completion(version, environment, application_name,
|
|
424
424
|
attributes = create_metrics_attributes(
|
425
425
|
service_name=application_name,
|
426
426
|
deployment_environment=environment,
|
427
|
-
operation=
|
428
|
-
system=
|
427
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
428
|
+
system=SemanticConvention.GEN_AI_SYSTEM_TOGETHER,
|
429
429
|
request_model=request_model,
|
430
430
|
server_address=server_address,
|
431
431
|
server_port=server_port,
|
@@ -495,7 +495,7 @@ def async_image_generate(version, environment, application_name,
|
|
495
495
|
server_address, server_port = set_server_address_and_port(instance, "api.together.xyz", 443)
|
496
496
|
request_model = kwargs.get("model", "dall-e-2")
|
497
497
|
|
498
|
-
span_name = f"{
|
498
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE} {request_model}"
|
499
499
|
|
500
500
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
501
501
|
start_time = time.time()
|
@@ -521,21 +521,21 @@ def async_image_generate(version, environment, application_name,
|
|
521
521
|
for items in response.data:
|
522
522
|
# Set Span attributes (OTel Semconv)
|
523
523
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
524
|
-
span.set_attribute(
|
525
|
-
|
526
|
-
span.set_attribute(
|
527
|
-
|
528
|
-
span.set_attribute(
|
524
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
525
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE)
|
526
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
527
|
+
SemanticConvention.GEN_AI_SYSTEM_TOGETHER)
|
528
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
529
529
|
request_model)
|
530
|
-
span.set_attribute(
|
530
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
531
531
|
server_address)
|
532
|
-
span.set_attribute(
|
532
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
533
533
|
server_port)
|
534
|
-
span.set_attribute(
|
534
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
535
535
|
response.id)
|
536
|
-
span.set_attribute(
|
536
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
537
537
|
response.model)
|
538
|
-
span.set_attribute(
|
538
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
539
539
|
"image")
|
540
540
|
|
541
541
|
# Set Span attributes (Extras)
|
@@ -543,29 +543,29 @@ def async_image_generate(version, environment, application_name,
|
|
543
543
|
environment)
|
544
544
|
span.set_attribute(SERVICE_NAME,
|
545
545
|
application_name)
|
546
|
-
span.set_attribute(
|
546
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_SIZE,
|
547
547
|
image_size)
|
548
|
-
span.set_attribute(
|
548
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
549
549
|
version)
|
550
550
|
|
551
551
|
if capture_message_content:
|
552
552
|
span.add_event(
|
553
|
-
name=
|
553
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
554
554
|
attributes={
|
555
|
-
|
555
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
556
556
|
},
|
557
557
|
)
|
558
|
-
attribute_name = f"{
|
558
|
+
attribute_name = f"{SemanticConvention.GEN_AI_RESPONSE_IMAGE}.{images_count}"
|
559
559
|
span.add_event(
|
560
560
|
name=attribute_name,
|
561
561
|
attributes={
|
562
|
-
|
562
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
|
563
563
|
},
|
564
564
|
)
|
565
565
|
|
566
566
|
images_count+=1
|
567
567
|
|
568
|
-
span.set_attribute(
|
568
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
569
569
|
len(response.data) * cost)
|
570
570
|
span.set_status(Status(StatusCode.OK))
|
571
571
|
|
@@ -573,8 +573,8 @@ def async_image_generate(version, environment, application_name,
|
|
573
573
|
attributes = create_metrics_attributes(
|
574
574
|
service_name=application_name,
|
575
575
|
deployment_environment=environment,
|
576
|
-
operation=
|
577
|
-
system=
|
576
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE,
|
577
|
+
system=SemanticConvention.GEN_AI_SYSTEM_TOGETHER,
|
578
578
|
request_model=request_model,
|
579
579
|
server_address=server_address,
|
580
580
|
server_port=server_port,
|