Skip to content

Commit 3ae8264

Browse files
committed
update with precommit fixes
1 parent 96889d7 commit 3ae8264

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

instrumentation-genai/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from __future__ import annotations
1616

1717
from typing import Any
18-
from uuid import UUID
1918
from urllib.parse import urlparse
19+
from uuid import UUID
2020

2121
from langchain_core.callbacks import BaseCallbackHandler # type: ignore
2222
from langchain_core.messages import BaseMessage # type: ignore
@@ -107,7 +107,8 @@ def on_chat_model_start(
107107
GenAI.GenAiProviderNameValues.AZURE_AI_INFERENCE.value,
108108
):
109109
span.set_attribute(
110-
AZURE_RESOURCE_PROVIDER_NAMESPACE, "Microsoft.CognitiveServices"
110+
AZURE_RESOURCE_PROVIDER_NAMESPACE,
111+
"Microsoft.CognitiveServices",
111112
)
112113

113114
self._apply_request_attributes(span, params, metadata)

instrumentation-genai/opentelemetry-instrumentation-langchain/tests/test_callback_handler.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
AZURE_RESOURCE_PROVIDER_NAMESPACE,
2020
)
2121
from opentelemetry.semconv._incubating.attributes.openai_attributes import (
22-
OPENAI_REQUEST_SERVICE_TIER,
2322
OPENAI_RESPONSE_SERVICE_TIER,
2423
OPENAI_RESPONSE_SYSTEM_FINGERPRINT,
2524
)
@@ -62,9 +61,7 @@ def test_provider_and_server_metadata_extracted():
6261

6362
span = exporter.get_finished_spans()[0]
6463
assert span.name == "chat gpt-4o"
65-
assert (
66-
span.attributes[GenAI.GEN_AI_PROVIDER_NAME] == "azure.ai.openai"
67-
)
64+
assert span.attributes[GenAI.GEN_AI_PROVIDER_NAME] == "azure.ai.openai"
6865
assert (
6966
span.attributes[AZURE_RESOURCE_PROVIDER_NAMESPACE]
7067
== "Microsoft.CognitiveServices"
@@ -112,9 +109,7 @@ def test_llm_end_sets_response_metadata():
112109
assert span.attributes[GenAI.GEN_AI_RESPONSE_MODEL] == "gpt-4-0125"
113110
assert span.attributes[GenAI.GEN_AI_RESPONSE_ID] == "chatcmpl-test"
114111
assert span.attributes[OPENAI_RESPONSE_SERVICE_TIER] == "premium"
115-
assert (
116-
span.attributes[OPENAI_RESPONSE_SYSTEM_FINGERPRINT] == "fp-test"
117-
)
112+
assert span.attributes[OPENAI_RESPONSE_SYSTEM_FINGERPRINT] == "fp-test"
118113

119114

120115
def test_choice_count_not_set_when_one():
@@ -138,6 +133,4 @@ def test_choice_count_not_set_when_one():
138133

139134
handler.span_manager.end_span(run_id)
140135
span = exporter.get_finished_spans()[0]
141-
assert (
142-
GenAI.GEN_AI_REQUEST_CHOICE_COUNT not in span.attributes
143-
)
136+
assert GenAI.GEN_AI_REQUEST_CHOICE_COUNT not in span.attributes

instrumentation-genai/opentelemetry-instrumentation-langchain/tests/test_llm_call.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from opentelemetry.instrumentation.langchain.callback_handler import (
88
OpenTelemetryLangChainCallbackHandler,
99
)
10-
from opentelemetry.sdk.trace import ReadableSpan
11-
from opentelemetry.sdk.trace import TracerProvider
10+
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
1211
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
1312
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
1413
InMemorySpanExporter,
@@ -100,9 +99,7 @@ def assert_openai_completion_attributes(
10099
)
101100
assert span.attributes[gen_ai_attributes.GEN_AI_REQUEST_MAX_TOKENS] == 100
102101
assert span.attributes[gen_ai_attributes.GEN_AI_REQUEST_TEMPERATURE] == 0.1
103-
assert (
104-
span.attributes[gen_ai_attributes.GEN_AI_PROVIDER_NAME] == "openai"
105-
)
102+
assert span.attributes[gen_ai_attributes.GEN_AI_PROVIDER_NAME] == "openai"
106103
assert gen_ai_attributes.GEN_AI_RESPONSE_ID in span.attributes
107104
assert span.attributes[gen_ai_attributes.GEN_AI_REQUEST_TOP_P] == 0.9
108105
assert (
@@ -190,7 +187,9 @@ def test_azure_chat_sets_provider_and_server_attributes():
190187
exporter = InMemorySpanExporter()
191188
provider = TracerProvider()
192189
provider.add_span_processor(SimpleSpanProcessor(exporter))
193-
handler = OpenTelemetryLangChainCallbackHandler(provider.get_tracer(__name__))
190+
handler = OpenTelemetryLangChainCallbackHandler(
191+
provider.get_tracer(__name__)
192+
)
194193

195194
run_id = uuid4()
196195

@@ -215,18 +214,14 @@ def test_azure_chat_sets_provider_and_server_attributes():
215214
span = exporter.get_finished_spans()[0]
216215

217216
assert span.name == "chat gpt-4o"
218-
assert (
219-
span.attributes[gen_ai_attributes.GEN_AI_REQUEST_MODEL] == "gpt-4o"
220-
)
217+
assert span.attributes[gen_ai_attributes.GEN_AI_REQUEST_MODEL] == "gpt-4o"
221218
assert (
222219
span.attributes[gen_ai_attributes.GEN_AI_PROVIDER_NAME]
223220
== "azure.ai.openai"
224221
)
225222
assert span.attributes["server.address"] == "example.openai.azure.com"
226223
assert span.attributes["server.port"] == 443
227-
assert (
228-
span.attributes[gen_ai_attributes.GEN_AI_REQUEST_CHOICE_COUNT] == 2
229-
)
224+
assert span.attributes[gen_ai_attributes.GEN_AI_REQUEST_CHOICE_COUNT] == 2
230225
assert span.attributes[OPENAI_REQUEST_SERVICE_TIER] == "default"
231226
assert (
232227
span.attributes[AZURE_RESOURCE_PROVIDER_NAMESPACE]

0 commit comments

Comments
 (0)