Skip to content

Commit 3049746

Browse files
committed
some fixes
1 parent fddaac7 commit 3049746

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

  • instrumentation-genai
    • opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic
    • opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain
  • util/opentelemetry-util-genai/src/opentelemetry/util/genai

instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
gen_ai_attributes as GenAIAttributes,
2525
)
2626
from opentelemetry.util.genai.handler import TelemetryHandler
27-
from opentelemetry.util.genai.types import ( # pylint: disable=no-name-in-module # TODO: migrate to InferenceInvocation
28-
Error,
29-
LLMInvocation,
30-
)
27+
from opentelemetry.util.genai.types import Error
28+
from opentelemetry.util.genai.inference_invocation import LLMInvocation # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
3129
from opentelemetry.util.genai.utils import (
3230
should_capture_content_on_spans_in_experimental_mode,
3331
)
@@ -92,7 +90,7 @@ def traced_method(
9290
else params.model
9391
)
9492

95-
invocation = LLMInvocation(
93+
invocation = LLMInvocation( # pyright: ignore[reportDeprecated]
9694
request_model=request_model,
9795
provider=ANTHROPIC,
9896
input_messages=get_input_messages(params.messages)
@@ -105,7 +103,7 @@ def traced_method(
105103
)
106104

107105
# Use manual lifecycle management for both streaming and non-streaming
108-
handler.start_llm(invocation)
106+
handler.start_llm(invocation) # pyright: ignore[reportDeprecated]
109107
try:
110108
result = wrapped(*args, **kwargs)
111109
if isinstance(result, AnthropicStream):
@@ -115,10 +113,10 @@ def traced_method(
115113

116114
wrapper = MessageWrapper(result, capture_content)
117115
wrapper.extract_into(invocation)
118-
handler.stop_llm(invocation)
116+
handler.stop_llm(invocation) # pyright: ignore[reportDeprecated]
119117
return wrapper.message
120118
except Exception as exc:
121-
handler.fail_llm(
119+
handler.fail_llm( # pyright: ignore[reportDeprecated]
122120
invocation, Error(message=str(exc), type=type(exc))
123121
)
124122
raise

instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
from opentelemetry.util.genai.handler import TelemetryHandler
2222
from opentelemetry.util.genai.types import (
2323
Error,
24-
LLMInvocation, # pylint: disable=no-name-in-module # TODO: migrate to InferenceInvocation
2524
MessagePart,
2625
OutputMessage,
2726
)
27+
from opentelemetry.util.genai.inference_invocation import LLMInvocation # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
2828

2929
from .messages_extractors import (
3030
GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
@@ -60,7 +60,7 @@ def __init__(self, message: Message, capture_content: bool):
6060
self._message = message
6161
self._capture_content = capture_content
6262

63-
def extract_into(self, invocation: LLMInvocation) -> None:
63+
def extract_into(self, invocation: LLMInvocation) -> None: # pyright: ignore[reportDeprecated]
6464
"""Extract response data into the invocation."""
6565
if self._message.model:
6666
invocation.response_model_name = self._message.model
@@ -103,7 +103,7 @@ def __init__(
103103
self,
104104
stream: Stream[RawMessageStreamEvent],
105105
handler: TelemetryHandler,
106-
invocation: LLMInvocation,
106+
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
107107
capture_content: bool,
108108
):
109109
self._stream = stream
@@ -213,7 +213,7 @@ def _stop(self) -> None:
213213
"response attribute extraction",
214214
)
215215
self._safe_instrumentation(
216-
lambda: self._handler.stop_llm(self._invocation),
216+
lambda: self._handler.stop_llm(self._invocation), # pyright: ignore[reportDeprecated]
217217
"stop_llm",
218218
)
219219
self._finalized = True
@@ -222,7 +222,7 @@ def _fail(self, message: str, error_type: type[BaseException]) -> None:
222222
if self._finalized:
223223
return
224224
self._safe_instrumentation(
225-
lambda: self._handler.fail_llm(
225+
lambda: self._handler.fail_llm( # pyright: ignore[reportDeprecated]
226226
self._invocation, Error(message=message, type=error_type)
227227
),
228228
"fail_llm",

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
_InvocationManager,
2626
)
2727
from opentelemetry.util.genai.handler import TelemetryHandler
28+
from opentelemetry.util.genai.inference_invocation import LLMInvocation # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
2829
from opentelemetry.util.genai.types import (
2930
Error,
3031
InputMessage,
31-
LLMInvocation,
3232
MessagePart,
3333
OutputMessage,
3434
Text,
@@ -140,7 +140,7 @@ def on_chat_model_start(
140140
)
141141
)
142142

143-
llm_invocation = LLMInvocation(
143+
llm_invocation = LLMInvocation( # pyright: ignore[reportDeprecated]
144144
request_model=request_model,
145145
input_messages=input_messages,
146146
provider=provider,
@@ -152,7 +152,7 @@ def on_chat_model_start(
152152
temperature=temperature,
153153
max_tokens=max_tokens,
154154
)
155-
llm_invocation = self._telemetry_handler.start_llm(
155+
llm_invocation = self._telemetry_handler.start_llm( # pyright: ignore[reportDeprecated]
156156
invocation=llm_invocation
157157
)
158158
self._invocation_manager.add_invocation_state(
@@ -171,7 +171,7 @@ def on_llm_end(
171171
) -> None:
172172
llm_invocation = self._invocation_manager.get_invocation(run_id=run_id)
173173
if llm_invocation is None or not isinstance(
174-
llm_invocation, LLMInvocation
174+
llm_invocation, LLMInvocation # pyright: ignore[reportDeprecated]
175175
):
176176
# If the invocation does not exist, we cannot set attributes or end it
177177
return
@@ -246,7 +246,7 @@ def on_llm_end(
246246
if response_id is not None:
247247
llm_invocation.response_id = str(response_id)
248248

249-
llm_invocation = self._telemetry_handler.stop_llm(
249+
llm_invocation = self._telemetry_handler.stop_llm( # pyright: ignore[reportDeprecated]
250250
invocation=llm_invocation
251251
)
252252
if llm_invocation.span and not llm_invocation.span.is_recording():
@@ -262,13 +262,13 @@ def on_llm_error(
262262
) -> None:
263263
llm_invocation = self._invocation_manager.get_invocation(run_id=run_id)
264264
if llm_invocation is None or not isinstance(
265-
llm_invocation, LLMInvocation
265+
llm_invocation, LLMInvocation # pyright: ignore[reportDeprecated]
266266
):
267267
# If the invocation does not exist, we cannot set attributes or end it
268268
return
269269

270270
error_otel = Error(message=str(error), type=type(error))
271-
llm_invocation = self._telemetry_handler.fail_llm(
271+
llm_invocation = self._telemetry_handler.fail_llm( # pyright: ignore[reportDeprecated]
272272
invocation=llm_invocation, error=error_otel
273273
)
274274
if llm_invocation.span and not llm_invocation.span.is_recording():

util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def stop_llm(self, invocation: LLMInvocation) -> LLMInvocation: # pyright: igno
269269
)
270270
def fail_llm(
271271
self,
272-
invocation: LLMInvocation,
273-
error: Error, # pyright: ignore[reportDeprecated]
272+
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
273+
error: Error,
274274
) -> LLMInvocation: # pyright: ignore[reportDeprecated]
275275
"""Fail an LLM invocation and end its span with error status.
276276

0 commit comments

Comments
 (0)