-
Notifications
You must be signed in to change notification settings - Fork 786
Update the botocore
instrumentation to emit events via the logs API instead of the deprecated events API
#3624
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
f491545
0008618
948053d
e406a18
47270d1
1b83355
2bc37c7
a3da8b2
7a06210
a64b308
afb7a7e
82a8b35
ead2af9
765eaa5
17f3073
a4d65f5
7f4f596
4310e63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
from botocore.eventstream import EventStream, EventStreamError | ||
from wrapt import ObjectProxy | ||
|
||
from opentelemetry._events import Event | ||
from opentelemetry._logs import LogRecord | ||
from opentelemetry.context import get_current | ||
from opentelemetry.instrumentation.botocore.environment_variables import ( | ||
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, | ||
) | ||
|
@@ -492,7 +493,7 @@ def extract_tool_results( | |
|
||
def message_to_event( | ||
message: dict[str, Any], capture_content: bool | ||
) -> Iterator[Event]: | ||
) -> Iterator[LogRecord]: | ||
attributes = {GEN_AI_SYSTEM: GenAiSystemValues.AWS_BEDROCK.value} | ||
role = message.get("role") | ||
content = message.get("content") | ||
|
@@ -507,16 +508,18 @@ def message_to_event( | |
elif role == "user": | ||
# in case of tool calls we send one tool event for tool call and one for the user event | ||
for tool_body in extract_tool_results(message, capture_content): | ||
yield Event( | ||
name="gen_ai.tool.message", | ||
yield LogRecord( | ||
event_name="gen_ai.tool.message", | ||
attributes=attributes, | ||
body=tool_body, | ||
context=get_current(), | ||
) | ||
|
||
yield Event( | ||
name=f"gen_ai.{role}.message", | ||
yield LogRecord( | ||
event_name=f"gen_ai.{role}.message", | ||
attributes=attributes, | ||
body=body if body else None, | ||
context=get_current(), | ||
) | ||
|
||
|
||
|
@@ -617,11 +620,12 @@ def _to_body_dict(self) -> dict[str, Any]: | |
"message": self.message, | ||
} | ||
|
||
def to_choice_event(self, **event_kwargs) -> Event: | ||
def to_choice_event(self, **event_kwargs) -> LogRecord: | ||
attributes = {GEN_AI_SYSTEM: GenAiSystemValues.AWS_BEDROCK.value} | ||
return Event( | ||
name="gen_ai.choice", | ||
return LogRecord( | ||
event_name="gen_ai.choice", | ||
attributes=attributes, | ||
body=self._to_body_dict(), | ||
**event_kwargs, | ||
context=get_current(), | ||
|
||
) |
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.
Here I think we should put the span in context and pass the context instead of the 3 deprecated params.