openlit 1.33.18__py3-none-any.whl → 1.33.20__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 +11 -41
- 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 +10 -10
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +10 -10
- openlit/instrumentation/azure_ai_inference/utils.py +38 -38
- openlit/instrumentation/bedrock/__init__.py +2 -1
- openlit/instrumentation/bedrock/bedrock.py +32 -214
- openlit/instrumentation/bedrock/utils.py +252 -0
- 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/async_ollama.py +3 -3
- openlit/instrumentation/ollama/ollama.py +3 -3
- openlit/instrumentation/ollama/utils.py +50 -50
- 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/transformers.py +26 -26
- 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.18.dist-info → openlit-1.33.20.dist-info}/METADATA +8 -8
- openlit-1.33.20.dist-info/RECORD +131 -0
- {openlit-1.33.18.dist-info → openlit-1.33.20.dist-info}/WHEEL +1 -1
- openlit-1.33.18.dist-info/RECORD +0 -130
- {openlit-1.33.18.dist-info → openlit-1.33.20.dist-info}/LICENSE +0 -0
@@ -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__)
|
@@ -60,39 +60,39 @@ def async_wrap_julep(gen_ai_endpoint, version, environment, application_name,
|
|
60
60
|
|
61
61
|
try:
|
62
62
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
63
|
-
span.set_attribute(
|
63
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
64
64
|
gen_ai_endpoint)
|
65
|
-
span.set_attribute(
|
66
|
-
|
65
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
66
|
+
SemanticConvention.GEN_AI_SYSTEM_JULEP)
|
67
67
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
68
68
|
environment)
|
69
69
|
span.set_attribute(SERVICE_NAME,
|
70
70
|
application_name)
|
71
|
-
span.set_attribute(
|
72
|
-
|
71
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
72
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT)
|
73
73
|
|
74
74
|
if gen_ai_endpoint == "julep.agents_create":
|
75
|
-
span.set_attribute(
|
75
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ID,
|
76
76
|
response.id)
|
77
|
-
span.set_attribute(
|
77
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ROLE,
|
78
78
|
kwargs.get("name", ""))
|
79
|
-
span.set_attribute(
|
79
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
80
80
|
kwargs.get("model", "gpt-4-turbo"))
|
81
|
-
span.set_attribute(
|
81
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_CONTEXT,
|
82
82
|
kwargs.get("about", ""))
|
83
83
|
|
84
84
|
elif gen_ai_endpoint == "julep.task_create":
|
85
|
-
span.set_attribute(
|
85
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TOOLS,
|
86
86
|
str(kwargs.get("tools", "")))
|
87
87
|
|
88
88
|
elif gen_ai_endpoint == "julep.execution_create":
|
89
|
-
span.set_attribute(
|
89
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TASK_ID,
|
90
90
|
kwargs.get("task_id", ""))
|
91
91
|
if capture_message_content:
|
92
92
|
span.add_event(
|
93
|
-
name=
|
93
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
94
94
|
attributes={
|
95
|
-
|
95
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT:str(kwargs.get("input", "")),
|
96
96
|
},
|
97
97
|
)
|
98
98
|
|
@@ -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__)
|
@@ -60,39 +60,39 @@ def wrap_julep(gen_ai_endpoint, version, environment, application_name,
|
|
60
60
|
|
61
61
|
try:
|
62
62
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
63
|
-
span.set_attribute(
|
63
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
64
64
|
gen_ai_endpoint)
|
65
|
-
span.set_attribute(
|
66
|
-
|
65
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
66
|
+
SemanticConvention.GEN_AI_SYSTEM_JULEP)
|
67
67
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
68
68
|
environment)
|
69
69
|
span.set_attribute(SERVICE_NAME,
|
70
70
|
application_name)
|
71
|
-
span.set_attribute(
|
72
|
-
|
71
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
72
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT)
|
73
73
|
|
74
74
|
if gen_ai_endpoint == "julep.agents_create":
|
75
|
-
span.set_attribute(
|
75
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ID,
|
76
76
|
response.id)
|
77
|
-
span.set_attribute(
|
77
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ROLE,
|
78
78
|
kwargs.get("name", ""))
|
79
|
-
span.set_attribute(
|
79
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
80
80
|
kwargs.get("model", "gpt-4-turbo"))
|
81
|
-
span.set_attribute(
|
81
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_CONTEXT,
|
82
82
|
kwargs.get("about", ""))
|
83
83
|
|
84
84
|
elif gen_ai_endpoint == "julep.task_create":
|
85
|
-
span.set_attribute(
|
85
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TOOLS,
|
86
86
|
str(kwargs.get("tools", "")))
|
87
87
|
|
88
88
|
elif gen_ai_endpoint == "julep.execution_create":
|
89
|
-
span.set_attribute(
|
89
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TASK_ID,
|
90
90
|
kwargs.get("task_id", ""))
|
91
91
|
if capture_message_content:
|
92
92
|
span.add_event(
|
93
|
-
name=
|
93
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
94
94
|
attributes={
|
95
|
-
|
95
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT:str(kwargs.get("input", "")),
|
96
96
|
},
|
97
97
|
)
|
98
98
|
|
@@ -15,7 +15,7 @@ from openlit.__helpers import (
|
|
15
15
|
calculate_tbt,
|
16
16
|
create_metrics_attributes,
|
17
17
|
)
|
18
|
-
from openlit.semcov import
|
18
|
+
from openlit.semcov import SemanticConvention
|
19
19
|
|
20
20
|
# Initialize logger for logging potential issues and operations
|
21
21
|
logger = logging.getLogger(__name__)
|
@@ -87,17 +87,17 @@ def async_general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
87
87
|
|
88
88
|
try:
|
89
89
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
90
|
-
span.set_attribute(
|
91
|
-
|
92
|
-
span.set_attribute(
|
90
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
91
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
92
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
93
93
|
gen_ai_endpoint)
|
94
94
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
95
95
|
environment)
|
96
|
-
span.set_attribute(
|
97
|
-
|
96
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
97
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
|
98
98
|
span.set_attribute(SERVICE_NAME,
|
99
99
|
application_name)
|
100
|
-
span.set_attribute(
|
100
|
+
span.set_attribute(SemanticConvention.GEN_AI_RETRIEVAL_SOURCE,
|
101
101
|
response[0].metadata["source"])
|
102
102
|
span.set_status(Status(StatusCode.OK))
|
103
103
|
|
@@ -161,19 +161,19 @@ def async_hub(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
161
161
|
|
162
162
|
try:
|
163
163
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
164
|
-
span.set_attribute(
|
165
|
-
|
166
|
-
span.set_attribute(
|
164
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
165
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
166
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
167
167
|
gen_ai_endpoint)
|
168
168
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
169
169
|
environment)
|
170
|
-
span.set_attribute(
|
171
|
-
|
170
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
171
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
|
172
172
|
span.set_attribute(SERVICE_NAME,
|
173
173
|
application_name)
|
174
|
-
span.set_attribute(
|
174
|
+
span.set_attribute(SemanticConvention.GEN_AI_HUB_OWNER,
|
175
175
|
response.metadata["lc_hub_owner"])
|
176
|
-
span.set_attribute(
|
176
|
+
span.set_attribute(SemanticConvention.GEN_AI_HUB_REPO,
|
177
177
|
response.metadata["lc_hub_repo"])
|
178
178
|
span.set_status(Status(StatusCode.OK))
|
179
179
|
|
@@ -241,7 +241,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
241
241
|
else:
|
242
242
|
request_model = "NOT_FOUND"
|
243
243
|
|
244
|
-
span_name = f"{
|
244
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
245
245
|
|
246
246
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
247
247
|
start_time = time.time()
|
@@ -294,27 +294,27 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
294
294
|
|
295
295
|
# Set base span attribues (OTel Semconv)
|
296
296
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
297
|
-
span.set_attribute(
|
298
|
-
|
299
|
-
span.set_attribute(
|
300
|
-
|
301
|
-
span.set_attribute(
|
297
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
298
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
299
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
300
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
301
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
302
302
|
request_model)
|
303
|
-
span.set_attribute(
|
303
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
304
304
|
request_model)
|
305
|
-
span.set_attribute(
|
305
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
306
306
|
str(getattr(instance, 'temperature', 1)))
|
307
|
-
span.set_attribute(
|
307
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K,
|
308
308
|
str(getattr(instance, 'top_k', 1)))
|
309
|
-
span.set_attribute(
|
309
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
310
310
|
str(getattr(instance, 'top_p', 1)))
|
311
|
-
span.set_attribute(
|
311
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
312
312
|
input_tokens)
|
313
|
-
span.set_attribute(
|
313
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
314
314
|
output_tokens)
|
315
|
-
span.set_attribute(
|
315
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
316
316
|
server_address)
|
317
|
-
span.set_attribute(
|
317
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
318
318
|
server_port)
|
319
319
|
|
320
320
|
# Set base span attribues (Extras)
|
@@ -322,28 +322,28 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
322
322
|
environment)
|
323
323
|
span.set_attribute(SERVICE_NAME,
|
324
324
|
application_name)
|
325
|
-
span.set_attribute(
|
325
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
326
326
|
False)
|
327
|
-
span.set_attribute(
|
327
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
328
328
|
input_tokens + output_tokens)
|
329
|
-
span.set_attribute(
|
329
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
330
330
|
cost)
|
331
|
-
span.set_attribute(
|
331
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
332
332
|
end_time - start_time)
|
333
|
-
span.set_attribute(
|
333
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
334
334
|
version)
|
335
335
|
|
336
336
|
if capture_message_content:
|
337
337
|
span.add_event(
|
338
|
-
name=
|
338
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
339
339
|
attributes={
|
340
|
-
|
340
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
341
341
|
},
|
342
342
|
)
|
343
343
|
span.add_event(
|
344
|
-
name=
|
344
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
345
345
|
attributes={
|
346
|
-
|
346
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: llm_response,
|
347
347
|
},
|
348
348
|
)
|
349
349
|
|
@@ -353,8 +353,8 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
353
353
|
attributes = create_metrics_attributes(
|
354
354
|
service_name=application_name,
|
355
355
|
deployment_environment=environment,
|
356
|
-
operation=
|
357
|
-
system=
|
356
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
357
|
+
system=SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN,
|
358
358
|
request_model=request_model,
|
359
359
|
server_address=server_address,
|
360
360
|
server_port=server_port,
|
@@ -16,7 +16,7 @@ from openlit.__helpers import (
|
|
16
16
|
create_metrics_attributes,
|
17
17
|
extract_and_format_input,
|
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__)
|
@@ -88,17 +88,17 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
|
|
88
88
|
|
89
89
|
try:
|
90
90
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
91
|
-
span.set_attribute(
|
92
|
-
|
93
|
-
span.set_attribute(
|
91
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
92
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
93
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
94
94
|
gen_ai_endpoint)
|
95
95
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
96
96
|
environment)
|
97
|
-
span.set_attribute(
|
98
|
-
|
97
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
98
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
|
99
99
|
span.set_attribute(SERVICE_NAME,
|
100
100
|
application_name)
|
101
|
-
span.set_attribute(
|
101
|
+
span.set_attribute(SemanticConvention.GEN_AI_RETRIEVAL_SOURCE,
|
102
102
|
response[0].metadata["source"])
|
103
103
|
span.set_status(Status(StatusCode.OK))
|
104
104
|
|
@@ -162,19 +162,19 @@ def hub(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
162
162
|
|
163
163
|
try:
|
164
164
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
165
|
-
span.set_attribute(
|
166
|
-
|
167
|
-
span.set_attribute(
|
165
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
166
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
167
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
168
168
|
gen_ai_endpoint)
|
169
169
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
170
170
|
environment)
|
171
|
-
span.set_attribute(
|
172
|
-
|
171
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
172
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
|
173
173
|
span.set_attribute(SERVICE_NAME,
|
174
174
|
application_name)
|
175
|
-
span.set_attribute(
|
175
|
+
span.set_attribute(SemanticConvention.GEN_AI_HUB_OWNER,
|
176
176
|
response.metadata["lc_hub_owner"])
|
177
|
-
span.set_attribute(
|
177
|
+
span.set_attribute(SemanticConvention.GEN_AI_HUB_REPO,
|
178
178
|
response.metadata["lc_hub_repo"])
|
179
179
|
span.set_status(Status(StatusCode.OK))
|
180
180
|
|
@@ -242,7 +242,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
242
242
|
else:
|
243
243
|
request_model = "NOT_FOUND"
|
244
244
|
|
245
|
-
span_name = f"{
|
245
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
246
246
|
|
247
247
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
248
248
|
start_time = time.time()
|
@@ -268,27 +268,27 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
268
268
|
|
269
269
|
# Set base span attribues (OTel Semconv)
|
270
270
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
271
|
-
span.set_attribute(
|
272
|
-
|
273
|
-
span.set_attribute(
|
274
|
-
|
275
|
-
span.set_attribute(
|
271
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
272
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
273
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
274
|
+
SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
|
275
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
276
276
|
request_model)
|
277
|
-
span.set_attribute(
|
277
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
278
278
|
request_model)
|
279
|
-
span.set_attribute(
|
279
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
280
280
|
str(getattr(instance, 'temperature', 1)))
|
281
|
-
span.set_attribute(
|
281
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K,
|
282
282
|
str(getattr(instance, 'top_k', 1)))
|
283
|
-
span.set_attribute(
|
283
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
284
284
|
str(getattr(instance, 'top_p', 1)))
|
285
|
-
span.set_attribute(
|
285
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
286
286
|
input_tokens)
|
287
|
-
span.set_attribute(
|
287
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
288
288
|
output_tokens)
|
289
|
-
span.set_attribute(
|
289
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
290
290
|
server_address)
|
291
|
-
span.set_attribute(
|
291
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
292
292
|
server_port)
|
293
293
|
|
294
294
|
# Set base span attribues (Extras)
|
@@ -296,28 +296,28 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
296
296
|
environment)
|
297
297
|
span.set_attribute(SERVICE_NAME,
|
298
298
|
application_name)
|
299
|
-
span.set_attribute(
|
299
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
300
300
|
False)
|
301
|
-
span.set_attribute(
|
301
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
302
302
|
input_tokens + output_tokens)
|
303
|
-
span.set_attribute(
|
303
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
304
304
|
cost)
|
305
|
-
span.set_attribute(
|
305
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
306
306
|
end_time - start_time)
|
307
|
-
span.set_attribute(
|
307
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
308
308
|
version)
|
309
309
|
|
310
310
|
if capture_message_content:
|
311
311
|
span.add_event(
|
312
|
-
name=
|
312
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
313
313
|
attributes={
|
314
|
-
|
314
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
315
315
|
},
|
316
316
|
)
|
317
317
|
span.add_event(
|
318
|
-
name=
|
318
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
319
319
|
attributes={
|
320
|
-
|
320
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: llm_response,
|
321
321
|
},
|
322
322
|
)
|
323
323
|
|
@@ -327,8 +327,8 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
327
327
|
attributes = create_metrics_attributes(
|
328
328
|
service_name=application_name,
|
329
329
|
deployment_environment=environment,
|
330
|
-
operation=
|
331
|
-
system=
|
330
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
331
|
+
system=SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN,
|
332
332
|
request_model=request_model,
|
333
333
|
server_address=server_address,
|
334
334
|
server_port=server_port,
|
@@ -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, get_chat_model_cost
|
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,27 +56,27 @@ def create_agent(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_LETTA)
|
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
|
response.id)
|
71
|
-
span.set_attribute(
|
71
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_ROLE,
|
72
72
|
response.name)
|
73
|
-
span.set_attribute(
|
73
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_INSTRUCTIONS,
|
74
74
|
response.system)
|
75
|
-
span.set_attribute(
|
75
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
76
76
|
response.llm_config.model)
|
77
|
-
span.set_attribute(
|
77
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TYPE,
|
78
78
|
response.agent_type)
|
79
|
-
span.set_attribute(
|
79
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_TOOLS,
|
80
80
|
response.tool_names)
|
81
81
|
|
82
82
|
span.set_status(Status(StatusCode.OK))
|
@@ -139,37 +139,37 @@ def send_message(gen_ai_endpoint, version, environment, application_name,
|
|
139
139
|
response.usage.completion_tokens)
|
140
140
|
# Set base span attribues
|
141
141
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
142
|
-
span.set_attribute(
|
143
|
-
|
144
|
-
span.set_attribute(
|
145
|
-
|
146
|
-
span.set_attribute(
|
142
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
143
|
+
SemanticConvention.GEN_AI_SYSTEM_LETTA)
|
144
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
145
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_AGENT)
|
146
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
147
147
|
gen_ai_endpoint)
|
148
148
|
span.set_attribute(SERVICE_NAME,
|
149
149
|
application_name)
|
150
|
-
span.set_attribute(
|
150
|
+
span.set_attribute(SemanticConvention.GEN_AI_AGENT_STEP_COUNT,
|
151
151
|
response.usage.step_count)
|
152
|
-
span.set_attribute(
|
152
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
153
153
|
response.usage.prompt_tokens)
|
154
|
-
span.set_attribute(
|
154
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
155
155
|
response.usage.completion_tokens)
|
156
|
-
span.set_attribute(
|
156
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
157
157
|
response.usage.total_tokens)
|
158
|
-
span.set_attribute(
|
158
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
159
159
|
cost)
|
160
160
|
|
161
161
|
if capture_message_content:
|
162
162
|
span.add_event(
|
163
|
-
name=
|
163
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
164
164
|
attributes={
|
165
|
-
|
165
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),
|
166
166
|
},
|
167
167
|
)
|
168
168
|
span.add_event(
|
169
|
-
name=
|
169
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
170
170
|
# pylint: disable=line-too-long
|
171
171
|
attributes={
|
172
|
-
|
172
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response.messages),
|
173
173
|
},
|
174
174
|
)
|
175
175
|
|