-
Notifications
You must be signed in to change notification settings - Fork 805
OpenAI v2 onboard onto semantic conventions 1.37.0: chat history and other breaking changes #3715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lmolkova
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
lmolkova:openai-v2-input-output-attrs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,432
−1,608
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,10 @@ | |
| from opentelemetry._events import get_event_logger | ||
| from opentelemetry.instrumentation.instrumentor import BaseInstrumentor | ||
| from opentelemetry.instrumentation.openai_v2.package import _instruments | ||
| from opentelemetry.instrumentation.openai_v2.utils import is_content_enabled | ||
| from opentelemetry.instrumentation.openai_v2.utils import ( | ||
| get_content_mode, | ||
| is_latest_experimental_enabled, | ||
| ) | ||
| from opentelemetry.instrumentation.utils import unwrap | ||
| from opentelemetry.metrics import get_meter | ||
| from opentelemetry.semconv.schemas import Schemas | ||
|
|
@@ -71,38 +74,47 @@ def _instrument(self, **kwargs): | |
| __name__, | ||
| "", | ||
| tracer_provider, | ||
| schema_url=Schemas.V1_28_0.value, | ||
| schema_url="https://opentelemetry.io/schemas/1.37.0", # TODO: Schemas.V1_37_0.value, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably need a telemetry test for the attributes in this telemetry. |
||
| ) | ||
| event_logger_provider = kwargs.get("event_logger_provider") | ||
| event_logger = get_event_logger( | ||
| __name__, | ||
| "", | ||
| schema_url=Schemas.V1_28_0.value, | ||
| schema_url="https://opentelemetry.io/schemas/1.37.0", # TODO: Schemas.V1_37_0.value, | ||
| event_logger_provider=event_logger_provider, | ||
| ) | ||
| meter_provider = kwargs.get("meter_provider") | ||
| self._meter = get_meter( | ||
| __name__, | ||
| "", | ||
| meter_provider, | ||
| schema_url=Schemas.V1_28_0.value, | ||
| schema_url="https://opentelemetry.io/schemas/1.37.0", # TODO: Schemas.V1_37_0.value, | ||
| ) | ||
|
|
||
| instruments = Instruments(self._meter) | ||
|
|
||
| latest_experimental_enabled = is_latest_experimental_enabled() | ||
| wrap_function_wrapper( | ||
| module="openai.resources.chat.completions", | ||
| name="Completions.create", | ||
| wrapper=chat_completions_create( | ||
| tracer, event_logger, instruments, is_content_enabled() | ||
| tracer, | ||
| event_logger, | ||
| instruments, | ||
| get_content_mode(latest_experimental_enabled), | ||
| latest_experimental_enabled, | ||
| ), | ||
| ) | ||
|
|
||
| wrap_function_wrapper( | ||
| module="openai.resources.chat.completions", | ||
| name="AsyncCompletions.create", | ||
| wrapper=async_chat_completions_create( | ||
| tracer, event_logger, instruments, is_content_enabled() | ||
| tracer, | ||
| event_logger, | ||
| instruments, | ||
| get_content_mode(latest_experimental_enabled), | ||
| latest_experimental_enabled, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally - introduce a new
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT_MODEvariable, which will include a list of supported modes - i.e.spaneventspan,event- sometimes preferred for development/teasting.Reusing
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTseems fine too.if we decide to support
span,event, it will require either introducingContentCapturingMode.SPAN_AND_EVENTor supporting a list of capturing modes. May be helper methods likeis_capturing_span()andis_capturing_event.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now we have two config items in Spring AI prototype:
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT- (for compatibility) decide whether we capture the chat messages.false- (by default) don't capture any chat messagestrue- capture all chat messages, specific behaviors depend on additional configurationOTEL_INSTRUMENTATION_GENAI_MESSAGE_CONTENT_CAPTURE_STRATEGY- decide how we capture the chat messages.span-attributes- (by default) capturing them as span attributesevent- capturing them as a eventevent, span-attributesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cirilla-zmh , thanks for sharing!
As a long-time java developer - can't resist the comment
VERY_JAVA_STYLE_VERBOSE_EVNIRONMENT_VARIABLE_NAMING🤣But seriously
span-attributesfor clarity.event, span-attributes, it is quite popular for testing.CAPTURE_MESSAGE_CONTENTandMESSAGE_CONTENT_CAPTURE_STRATEGYin env naming. I would 👍 to reuseOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTenv var.cc: @lmolkova
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhirafovod
Ahh, that's it...🤣 But it comes from the requirement of multi-language compatibility and isolation, it's more clear when transported to a property key:
otel.instrumentation.genai.capture_messages_content.For compatibility, I tend to add another config key to control the behavior of the messages capturing - the naming could be discussed again.