huggingface / huggingface/smolagents

[BUG] OTEL tracing not grouping traces when using GradioUI

Open
#477 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
29.3k
Forks
3k
Avg merge
17m
Merged PRs (30d)
2

Description

**Describe the bug**
I´m trying the example from [here](https://huggingface.co/docs/smolagents/en/tutorials/inspect_runs) and adding the GradioUI at the end, and I see that after adding the GradioUI then the traces are not being grouped together on the OTEL tracing tool (Arize). Without GradioUI it works as expected.

**Code to reproduce the error**
```
from smolagents import (
CodeAgent,
ToolCallingAgent,
ManagedAgent,
DuckDuckGoSearchTool,
VisitWebpageTool,
OpenAIServerModel,
GradioUI,
)
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

endpoint = "http://localhost:6006/v1/traces"
trace_provider = TracerProvider()
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)

model = OpenAIServerModel(
model_id="meta-llama/Llama-3.3-70B-Instruct",
api_key="-",
api_base="http://localhost:10000/v1",
)

agent = ToolCallingAgent(
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
model=model,
)
managed_agent = ManagedAgent(
agent=agent,
name="managed_agent",
description="This is an agent that can do web search.",
)
manager_agent = CodeAgent(
tools=[],
model=model,
managed_agents=[managed_agent],
)

GradioUI(manager_agent).launch()
```

**Error logs (if any)**

![Image](https://github.com/user-attachments/assets/2ce0d43f-c771-4d7e-9f13-223cbc26921f)

**Expected behavior**
All steps should be grouped under the same CodeAgent.run trace, similar as it is already working when not using GradioUI

**Packages version:**
smolagents 1.7.0

**Additional context**
No additional context required

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided CodeAgent, ManagedAgent, and GradioUI example, comparing spans with and without GradioUI. Start by tracing the GradioUI launch path and the CodeAgent.run boundary; done means all steps appear under one CodeAgent.run trace in the OTEL tracing tool.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.