Skip to content

Commit 4d4e31d

Browse files
committed
replace @deprecated with docstring info to avoid warnings for users
1 parent 80b86e2 commit 4d4e31d

File tree

7 files changed

+30
-44
lines changed

7 files changed

+30
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from opentelemetry.util.genai.types import (
3131
InputMessage,
32-
LLMInvocation, # pyright: ignore[reportDeprecated]
32+
LLMInvocation,
3333
MessagePart,
3434
OutputMessage,
3535
)
@@ -155,7 +155,7 @@ def get_output_messages_from_message(
155155

156156

157157
def set_invocation_response_attributes(
158-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
158+
invocation: LLMInvocation,
159159
message: Message | None,
160160
capture_content: bool,
161161
) -> None:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from opentelemetry.util.genai.handler import TelemetryHandler
2929
from opentelemetry.util.genai.types import (
3030
Error,
31-
LLMInvocation, # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
31+
LLMInvocation, # TODO: migrate to InferenceInvocation
3232
)
3333
from opentelemetry.util.genai.utils import (
3434
should_capture_content_on_spans_in_experimental_mode,
@@ -94,7 +94,7 @@ def traced_method(
9494
else params.model
9595
)
9696

97-
invocation = LLMInvocation( # pyright: ignore[reportDeprecated]
97+
invocation = LLMInvocation(
9898
request_model=request_model,
9999
provider=ANTHROPIC,
100100
input_messages=get_input_messages(params.messages)
@@ -107,7 +107,7 @@ def traced_method(
107107
)
108108

109109
# Use manual lifecycle management for both streaming and non-streaming
110-
handler.start_llm(invocation) # pyright: ignore[reportDeprecated]
110+
handler.start_llm(invocation)
111111
try:
112112
result = wrapped(*args, **kwargs)
113113
if isinstance(result, AnthropicStream):
@@ -117,10 +117,10 @@ def traced_method(
117117

118118
wrapper = MessageWrapper(result, capture_content)
119119
wrapper.extract_into(invocation)
120-
handler.stop_llm(invocation) # pyright: ignore[reportDeprecated]
120+
handler.stop_llm(invocation)
121121
return wrapper.message
122122
except Exception as exc:
123-
handler.fail_llm( # pyright: ignore[reportDeprecated]
123+
handler.fail_llm(
124124
invocation, Error(message=str(exc), type=type(exc))
125125
)
126126
raise

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from opentelemetry.util.genai.handler import TelemetryHandler
3232
from opentelemetry.util.genai.types import (
3333
Error,
34-
LLMInvocation, # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
34+
LLMInvocation, # TODO: migrate to InferenceInvocation
3535
)
3636

3737
from .messages_extractors import set_invocation_response_attributes
@@ -68,7 +68,7 @@
6868

6969

7070
def _set_response_attributes(
71-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
71+
invocation: LLMInvocation,
7272
result: "Message | None",
7373
capture_content: bool,
7474
) -> None:
@@ -112,7 +112,7 @@ def __init__(self, message: Message, capture_content: bool):
112112
self._message = message
113113
self._capture_content = capture_content
114114

115-
def extract_into(self, invocation: LLMInvocation) -> None: # pyright: ignore[reportDeprecated]
115+
def extract_into(self, invocation: LLMInvocation) -> None:
116116
"""Extract response data into the invocation."""
117117
set_invocation_response_attributes(
118118
invocation, self._message, self._capture_content
@@ -136,7 +136,7 @@ def __init__(
136136
self,
137137
stream: "Stream[RawMessageStreamEvent] | MessageStream[ResponseFormatT]",
138138
handler: TelemetryHandler,
139-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
139+
invocation: LLMInvocation,
140140
capture_content: bool,
141141
):
142142
self.stream = stream
@@ -203,14 +203,14 @@ def _stop(self) -> None:
203203
self.invocation, self._message, self._capture_content
204204
)
205205
with self._safe_instrumentation("stop_llm"):
206-
self.handler.stop_llm(self.invocation) # pyright: ignore[reportDeprecated]
206+
self.handler.stop_llm(self.invocation)
207207
self._finalized = True
208208

209209
def _fail(self, message: str, error_type: type[BaseException]) -> None:
210210
if self._finalized:
211211
return
212212
with self._safe_instrumentation("fail_llm"):
213-
self.handler.fail_llm( # pyright: ignore[reportDeprecated]
213+
self.handler.fail_llm(
214214
self.invocation, Error(message=message, type=error_type)
215215
)
216216
self._finalized = True
@@ -258,7 +258,7 @@ def __init__(
258258
self,
259259
stream: "AsyncStream[RawMessageStreamEvent] | AsyncMessageStream[ResponseFormatT]",
260260
handler: TelemetryHandler,
261-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
261+
invocation: LLMInvocation,
262262
capture_content: bool,
263263
):
264264
self.stream = stream
@@ -324,7 +324,7 @@ def __init__(
324324
self,
325325
manager: "MessageStreamManager[ResponseFormatT]",
326326
handler: TelemetryHandler,
327-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
327+
invocation: LLMInvocation,
328328
capture_content: bool,
329329
):
330330
self._manager = manager
@@ -382,7 +382,7 @@ def __init__(
382382
self,
383383
manager: "AsyncMessageStreamManager[ResponseFormatT]",
384384
handler: TelemetryHandler,
385-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
385+
invocation: LLMInvocation,
386386
capture_content: bool,
387387
):
388388
self._manager = manager

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from opentelemetry.util.genai.types import (
2929
Error,
3030
InputMessage,
31-
LLMInvocation, # pyright: ignore[reportDeprecated] # TODO: migrate to InferenceInvocation
31+
LLMInvocation, # TODO: migrate to InferenceInvocation
3232
MessagePart,
3333
OutputMessage,
3434
Text,
@@ -140,7 +140,7 @@ def on_chat_model_start(
140140
)
141141
)
142142

143-
llm_invocation = LLMInvocation( # pyright: ignore[reportDeprecated]
143+
llm_invocation = LLMInvocation(
144144
request_model=request_model,
145145
input_messages=input_messages,
146146
provider=provider,
@@ -152,13 +152,13 @@ def on_chat_model_start(
152152
temperature=temperature,
153153
max_tokens=max_tokens,
154154
)
155-
llm_invocation = self._telemetry_handler.start_llm( # pyright: ignore[reportDeprecated]
155+
llm_invocation = self._telemetry_handler.start_llm(
156156
invocation=llm_invocation
157157
)
158158
self._invocation_manager.add_invocation_state(
159159
run_id=run_id,
160160
parent_run_id=parent_run_id,
161-
invocation=llm_invocation, # pyright: ignore[reportArgumentType]
161+
invocation=llm_invocation,
162162
)
163163

164164
def on_llm_end(
@@ -172,7 +172,7 @@ def on_llm_end(
172172
llm_invocation = self._invocation_manager.get_invocation(run_id=run_id)
173173
if llm_invocation is None or not isinstance(
174174
llm_invocation,
175-
LLMInvocation, # pyright: ignore[reportDeprecated]
175+
LLMInvocation,
176176
):
177177
# If the invocation does not exist, we cannot set attributes or end it
178178
return
@@ -247,7 +247,7 @@ def on_llm_end(
247247
if response_id is not None:
248248
llm_invocation.response_id = str(response_id)
249249

250-
llm_invocation = self._telemetry_handler.stop_llm( # pyright: ignore[reportDeprecated]
250+
llm_invocation = self._telemetry_handler.stop_llm(
251251
invocation=llm_invocation
252252
)
253253
if llm_invocation.span and not llm_invocation.span.is_recording():
@@ -264,13 +264,13 @@ def on_llm_error(
264264
llm_invocation = self._invocation_manager.get_invocation(run_id=run_id)
265265
if llm_invocation is None or not isinstance(
266266
llm_invocation,
267-
LLMInvocation, # pyright: ignore[reportDeprecated]
267+
LLMInvocation,
268268
):
269269
# If the invocation does not exist, we cannot set attributes or end it
270270
return
271271

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

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from dataclasses import asdict, dataclass, field
1818
from typing import Any
1919

20-
from typing_extensions import deprecated
21-
2220
from opentelemetry._logs import Logger, LogRecord
2321
from opentelemetry.semconv._incubating.attributes import (
2422
gen_ai_attributes as GenAI,
@@ -254,7 +252,6 @@ def _emit_event(self) -> None:
254252
)
255253

256254

257-
@deprecated("LLMInvocation is deprecated. Use InferenceInvocation instead.")
258255
@dataclass
259256
class LLMInvocation:
260257
"""Deprecated. Use InferenceInvocation instead.

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
from contextlib import contextmanager
5252
from typing import Iterator
5353

54-
from typing_extensions import deprecated
55-
5654
from opentelemetry._logs import (
5755
LoggerProvider,
5856
get_logger,
@@ -132,9 +130,6 @@ def start_inference(
132130
server_port=server_port,
133131
)
134132

135-
@deprecated(
136-
"handler.start_llm() is deprecated. Use handler.start_inference() instead."
137-
)
138133
def start_llm(self, invocation: LLMInvocation) -> LLMInvocation: # pyright: ignore[reportDeprecated]
139134
"""Start an LLM invocation.
140135
@@ -208,10 +203,7 @@ def start_workflow(
208203
self._tracer, self._metrics_recorder, self._logger, name
209204
)
210205

211-
@deprecated(
212-
"handler.stop_llm() is deprecated. Use handler.start_inference() and then ``inference.stop()`` instead."
213-
)
214-
def stop_llm(self, invocation: LLMInvocation) -> LLMInvocation: # pylint: disable=no-self-use # pyright: ignore[reportDeprecated]
206+
def stop_llm(self, invocation: LLMInvocation) -> LLMInvocation: # pylint: disable=no-self-use
215207
"""Finalize an LLM invocation successfully and end its span.
216208
217209
.. deprecated::
@@ -222,14 +214,11 @@ def stop_llm(self, invocation: LLMInvocation) -> LLMInvocation: # pylint: disab
222214
invocation._inference_invocation.stop()
223215
return invocation
224216

225-
@deprecated(
226-
"handler.fail_llm() is deprecated. Use handler.start_inference() and then ``inference.fail()`` instead."
227-
)
228217
def fail_llm( # pylint: disable=no-self-use
229218
self,
230-
invocation: LLMInvocation, # pyright: ignore[reportDeprecated]
219+
invocation: LLMInvocation,
231220
error: Error,
232-
) -> LLMInvocation: # pyright: ignore[reportDeprecated]
221+
) -> LLMInvocation:
233222
"""Fail an LLM invocation and end its span with error status.
234223
235224
.. deprecated::

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
if TYPE_CHECKING:
2222
from opentelemetry.util.genai._inference_invocation import ( # pylint: disable=useless-import-alias
23-
LLMInvocation as LLMInvocation, # noqa: PLC0414 # pyright: ignore[reportDeprecated]
23+
LLMInvocation as LLMInvocation, # noqa: PLC0414
2424
)
2525
from opentelemetry.util.genai._invocation import ( # pylint: disable=useless-import-alias
2626
GenAIInvocation as GenAIInvocation, # noqa: PLC0414
@@ -248,8 +248,8 @@ def __getattr__(name: str) -> object:
248248
return _inv.GenAIInvocation
249249
if name == "LLMInvocation":
250250
from opentelemetry.util.genai._inference_invocation import ( # noqa: PLC0415 # pylint: disable=import-outside-toplevel
251-
LLMInvocation, # pyright: ignore[reportDeprecated]
251+
LLMInvocation,
252252
)
253253

254-
return LLMInvocation # pyright: ignore[reportDeprecated]
254+
return (LLMInvocation,)
255255
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)