opentelemetry-instrumentation-openai 0.25.0__tar.gz → 0.25.2__tar.gz

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.

Potentially problematic release.


This version of opentelemetry-instrumentation-openai might be problematic. Click here for more details.

Files changed (17) hide show
  1. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/PKG-INFO +1 -1
  2. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/__init__.py +3 -1
  3. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/__init__.py +5 -1
  4. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/chat_wrappers.py +7 -4
  5. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/completion_wrappers.py +1 -1
  6. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/config.py +4 -0
  7. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py +3 -3
  8. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py +2 -2
  9. opentelemetry_instrumentation_openai-0.25.2/opentelemetry/instrumentation/openai/version.py +1 -0
  10. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/pyproject.toml +1 -1
  11. opentelemetry_instrumentation_openai-0.25.0/opentelemetry/instrumentation/openai/version.py +0 -1
  12. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/README.md +0 -0
  13. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/utils.py +0 -0
  14. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/v0/__init__.py +0 -0
  15. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/v1/__init__.py +0 -0
  16. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/v1/assistant_wrappers.py +0 -0
  17. {opentelemetry_instrumentation_openai-0.25.0 → opentelemetry_instrumentation_openai-0.25.2}/opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentelemetry-instrumentation-openai
3
- Version: 0.25.0
3
+ Version: 0.25.2
4
4
  Summary: OpenTelemetry OpenAI instrumentation
5
5
  Home-page: https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-openai
6
6
  License: Apache-2.0
@@ -1,4 +1,4 @@
1
- from typing import Collection
1
+ from typing import Callable, Collection
2
2
 
3
3
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
4
4
 
@@ -18,11 +18,13 @@ class OpenAIInstrumentor(BaseInstrumentor):
18
18
  enrich_assistant: bool = False,
19
19
  enrich_token_usage: bool = False,
20
20
  exception_logger=None,
21
+ get_common_metrics_attributes: Callable[[], dict] = lambda: {},
21
22
  ):
22
23
  super().__init__()
23
24
  Config.enrich_assistant = enrich_assistant
24
25
  Config.enrich_token_usage = enrich_token_usage
25
26
  Config.exception_logger = exception_logger
27
+ Config.get_common_metrics_attributes = get_common_metrics_attributes
26
28
 
27
29
  def instrumentation_dependencies(self) -> Collection[str]:
28
30
  return _instruments
@@ -8,6 +8,7 @@ from importlib.metadata import version
8
8
 
9
9
  from opentelemetry import context as context_api
10
10
 
11
+ from opentelemetry.instrumentation.openai.shared.config import Config
11
12
  from opentelemetry.semconv.ai import SpanAttributes
12
13
  from opentelemetry.instrumentation.openai.utils import (
13
14
  dont_throw,
@@ -256,10 +257,13 @@ def _token_type(token_type: str):
256
257
  return None
257
258
 
258
259
 
259
- def _metric_shared_attributes(
260
+ def metric_shared_attributes(
260
261
  response_model: str, operation: str, server_address: str, is_streaming: bool = False
261
262
  ):
263
+ attributes = Config.get_common_metrics_attributes()
264
+
262
265
  return {
266
+ **attributes,
263
267
  SpanAttributes.LLM_SYSTEM: "openai",
264
268
  SpanAttributes.LLM_RESPONSE_MODEL: response_model,
265
269
  "gen_ai.operation.name": operation,
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  import time
4
+ from opentelemetry.instrumentation.openai.shared.config import Config
4
5
  from wrapt import ObjectProxy
5
6
 
6
7
 
@@ -18,7 +19,7 @@ from opentelemetry.instrumentation.openai.utils import (
18
19
  dont_throw,
19
20
  )
20
21
  from opentelemetry.instrumentation.openai.shared import (
21
- _metric_shared_attributes,
22
+ metric_shared_attributes,
22
23
  _set_client_attributes,
23
24
  _set_request_attributes,
24
25
  _set_span_attribute,
@@ -155,7 +156,7 @@ async def achat_wrapper(
155
156
  if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY) or context_api.get_value(
156
157
  SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY
157
158
  ):
158
- return wrapped(*args, **kwargs)
159
+ return await wrapped(*args, **kwargs)
159
160
 
160
161
  span = tracer.start_span(
161
162
  SPAN_NAME,
@@ -172,7 +173,9 @@ async def achat_wrapper(
172
173
  end_time = time.time()
173
174
  duration = end_time - start_time if "start_time" in locals() else 0
174
175
 
176
+ common_attributes = Config.get_common_metrics_attributes()
175
177
  attributes = {
178
+ **common_attributes,
176
179
  "error.type": e.__class__.__name__,
177
180
  }
178
181
 
@@ -277,7 +280,7 @@ def _handle_response(
277
280
  def _set_chat_metrics(
278
281
  instance, token_counter, choice_counter, duration_histogram, response_dict, duration
279
282
  ):
280
- shared_attributes = _metric_shared_attributes(
283
+ shared_attributes = metric_shared_attributes(
281
284
  response_model=response_dict.get("model") or None,
282
285
  operation="chat",
283
286
  server_address=_get_openai_base_url(instance),
@@ -554,7 +557,7 @@ class ChatStream(ObjectProxy):
554
557
  _accumulate_stream_items(item, self._complete_response)
555
558
 
556
559
  def _shared_attributes(self):
557
- return _metric_shared_attributes(
560
+ return metric_shared_attributes(
558
561
  response_model=self._complete_response.get("model")
559
562
  or self._request_kwargs.get("model")
560
563
  or None,
@@ -67,7 +67,7 @@ async def acompletion_wrapper(tracer, wrapped, instance, args, kwargs):
67
67
  if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY) or context_api.get_value(
68
68
  SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY
69
69
  ):
70
- return wrapped(*args, **kwargs)
70
+ return await wrapped(*args, **kwargs)
71
71
 
72
72
  span = tracer.start_span(
73
73
  name=SPAN_NAME,
@@ -1,4 +1,8 @@
1
+ from typing import Callable
2
+
3
+
1
4
  class Config:
2
5
  enrich_token_usage = False
3
6
  enrich_assistant = False
4
7
  exception_logger = None
8
+ get_common_metrics_attributes: Callable[[], dict] = lambda: {}
@@ -16,7 +16,7 @@ from opentelemetry.instrumentation.openai.utils import (
16
16
  _with_embeddings_telemetry_wrapper,
17
17
  )
18
18
  from opentelemetry.instrumentation.openai.shared import (
19
- _metric_shared_attributes,
19
+ metric_shared_attributes,
20
20
  _set_client_attributes,
21
21
  _set_request_attributes,
22
22
  _set_span_attribute,
@@ -112,7 +112,7 @@ async def aembeddings_wrapper(
112
112
  if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY) or context_api.get_value(
113
113
  SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY
114
114
  ):
115
- return wrapped(*args, **kwargs)
115
+ return await wrapped(*args, **kwargs)
116
116
 
117
117
  async with start_as_current_span_async(
118
118
  tracer=tracer,
@@ -198,7 +198,7 @@ def _set_embeddings_metrics(
198
198
  response_dict,
199
199
  duration,
200
200
  ):
201
- shared_attributes = _metric_shared_attributes(
201
+ shared_attributes = metric_shared_attributes(
202
202
  response_model=response_dict.get("model") or None,
203
203
  operation="embeddings",
204
204
  server_address=_get_openai_base_url(instance),
@@ -4,7 +4,7 @@ from opentelemetry import context as context_api
4
4
  from opentelemetry.instrumentation.openai import is_openai_v1
5
5
  from opentelemetry.instrumentation.openai.shared import (
6
6
  _get_openai_base_url,
7
- _metric_shared_attributes,
7
+ metric_shared_attributes,
8
8
  model_as_dict,
9
9
  )
10
10
  from opentelemetry.instrumentation.openai.utils import (
@@ -55,7 +55,7 @@ def image_gen_metrics_wrapper(
55
55
  response_dict = response
56
56
 
57
57
  # not provide response.model in ImagesResponse response, use model in request kwargs
58
- shared_attributes = _metric_shared_attributes(
58
+ shared_attributes = metric_shared_attributes(
59
59
  response_model=kwargs.get("model") or None,
60
60
  operation="image_gen",
61
61
  server_address=_get_openai_base_url(instance),
@@ -8,7 +8,7 @@ show_missing = true
8
8
 
9
9
  [tool.poetry]
10
10
  name = "opentelemetry-instrumentation-openai"
11
- version = "0.25.0"
11
+ version = "0.25.2"
12
12
  description = "OpenTelemetry OpenAI instrumentation"
13
13
  authors = [
14
14
  "Gal Kleinman <gal@traceloop.com>",