traceloop / traceloop/openllmetry
๐ Bug Report: GenerationSpanData missing response field causes _extract_response_attributes to never execute
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.4k
- Forks
- 1.1k
- Avg merge
- 8d 14h
- Merged PRs (30d)
- 2
Description
Which component is this bug for?
OpenAI Instrumentation
๐ Description
GenerationSpanData missing response field causes _extract_response_attributes to never execute
@dont_throw
def on_span_end(self, span):
"""Called when a span ends - finish OpenTelemetry span."""
from agents import GenerationSpanData
if not span or not hasattr(span, "span_data"):
return
if span in self._otel_spans:
otel_span = self._otel_spans[span]
span_data = getattr(span, "span_data", None)
trace_content = should_send_prompts()
if span_data and (
type(span_data).__name__ == "ResponseSpanData"
or isinstance(span_data, GenerationSpanData)
):
# Extract prompt data from input
input_data = getattr(span_data, "input", [])
_extract_prompt_attributes(otel_span, input_data, trace_content)
# Add function/tool specifications to the request using OpenAI semantic conventions
response = getattr(span_data, "response", None) # if span_data is GenerationSpanData, so _extract_response_attributes to never execute
if response:
model_settings = _extract_response_attributes(otel_span, response, trace_content)
self._last_model_settings = model_settings
๐ Reproduction steps
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
trace.set_tracer_provider(trace_provider)
OpenAIAgentsInstrumentor(
replace_existing_processors=True
).instrument(
agent_name="TestAgent",
tracer_provider=trace_provider,
)
agent = Agent(
name=name,
instructions=f"{RECOMMENDED_PROMPT_PREFIX}\n\n{mark_instructions}",
model=LitellmModel(model=model),
model_settings=ModelSettings(
include_usage=True
))
Runner.run_streamed(agent, messages, context=context, **kwargs)
๐ Expected behavior
There should be gen_ai.output.xxx
๐ Actual Behavior with Screenshots
๐ค Python Version
No response
๐ Provide any additional context for the Bug.
No response
๐ Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up โ it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the OpenAI Instrumentation on_span_end path shown in the report, then inspect GenerationSpanData and _extract_response_attributes. Reproduce the streamed Runner.run_streamed case with LitellmModel and include_usage enabled; done means the span contains the expected gen_ai.output.xxx attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100