Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import json
from typing import Optional, Union

from opentelemetry._logs import Logger, LogRecord
from opentelemetry._events import Event
from opentelemetry._logs import Logger
from opentelemetry.instrumentation.anthropic.event_models import (
ChoiceEvent,
MessageEvent,
Expand Down Expand Up @@ -208,12 +209,12 @@ def _emit_message_event(event: MessageEvent, event_logger: Logger) -> None:
for tool_call in body["tool_calls"]:
tool_call["function"].pop("arguments", None)

log_record = LogRecord(
event = Event(
name=name,
body=body,
attributes=EVENT_ATTRIBUTES,
event_name=name
attributes=EVENT_ATTRIBUTES
)
event_logger.emit(log_record)
event_logger.emit(event)


def _emit_choice_event(event: ChoiceEvent, event_logger: Logger) -> None:
Expand All @@ -232,10 +233,9 @@ def _emit_choice_event(event: ChoiceEvent, event_logger: Logger) -> None:
for tool_call in body["tool_calls"]:
tool_call["function"].pop("arguments", None)

log_record = LogRecord(
event = Event(
name="gen_ai.choice",
body=body,
attributes=EVENT_ATTRIBUTES,
event_name="gen_ai.choice"

attributes=EVENT_ATTRIBUTES
)
event_logger.emit(log_record)
event_logger.emit(event)
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ async def aset_input_attributes(span, kwargs):
span, f"{prefix}.input_schema", json.dumps(input_schema)
)

output_format = kwargs.get("output_format")
if output_format and isinstance(output_format, dict):
if output_format.get("type") == "json_schema" and output_format.get("schema"):
set_span_attribute(
span,
SpanAttributes.LLM_REQUEST_STRUCTURED_OUTPUT_SCHEMA,
json.dumps(output_format.get("schema")),
)
elif output_format.get("type") == "json" and output_format.get("json_schema"):
schema = output_format.get("json_schema", {}).get("schema")
if schema:
set_span_attribute(
span,
SpanAttributes.LLM_REQUEST_STRUCTURED_OUTPUT_SCHEMA,
json.dumps(schema),
)


async def _aset_span_completions(span, response):
if not should_send_prompts():
Expand Down
Loading
Loading