Skip to content

Commit 07c3324

Browse files
author
Liudmila Molkova
authored
OpenAI - update semantic conventions to the latest version, write logs based events instead of span events (#2925)
1 parent 54c7ee8 commit 07c3324

19 files changed

+2813
-331
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## Unreleased
9+
10+
- Update OpenAI instrumentation to Semantic Conventions v1.28.0: add new attributes
11+
and switch prompts and completions to log-based events.
12+
([#2925](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2925))
13+
14+
- Initial OpenAI instrumentation
15+
([#2759](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2759))

instrumentation/opentelemetry-instrumentation-openai-v2/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
OpenTelemetry OpenAI Instrumentation
2-
====================================
2+
====================================
33

44
|pypi|
55

66
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-openai-v2.svg
77
:target: https://pypi.org/project/opentelemetry-instrumentation-openai-v2/
88

9-
Instrumentation with OpenAI that supports the openai library and is
9+
Instrumentation with OpenAI that supports the OpenAI library and is
1010
specified to trace_integration using 'OpenAI'.
1111

1212

instrumentation/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
.. code:: python
2525
2626
from openai import OpenAI
27-
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
27+
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
2828
2929
OpenAIInstrumentor().instrument()
3030
@@ -44,8 +44,10 @@
4444

4545
from wrapt import wrap_function_wrapper
4646

47+
from opentelemetry._events import get_event_logger
4748
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
4849
from opentelemetry.instrumentation.openai_v2.package import _instruments
50+
from opentelemetry.instrumentation.openai_v2.utils import is_content_enabled
4951
from opentelemetry.instrumentation.utils import unwrap
5052
from opentelemetry.semconv.schemas import Schemas
5153
from opentelemetry.trace import get_tracer
@@ -64,15 +66,25 @@ def _instrument(self, **kwargs):
6466
__name__,
6567
"",
6668
tracer_provider,
67-
schema_url=Schemas.V1_27_0.value,
69+
schema_url=Schemas.V1_28_0.value,
6870
)
71+
event_logger_provider = kwargs.get("event_logger_provider")
72+
event_logger = get_event_logger(
73+
__name__,
74+
"",
75+
schema_url=Schemas.V1_28_0.value,
76+
event_logger_provider=event_logger_provider,
77+
)
78+
6979
wrap_function_wrapper(
7080
module="openai.resources.chat.completions",
7181
name="Completions.create",
72-
wrapper=chat_completions_create(tracer),
82+
wrapper=chat_completions_create(
83+
tracer, event_logger, is_content_enabled()
84+
),
7385
)
7486

7587
def _uninstrument(self, **kwargs):
76-
import openai
88+
import openai # pylint: disable=import-outside-toplevel
7789

7890
unwrap(openai.resources.chat.completions.Completions, "create")

0 commit comments

Comments
 (0)