Skip to content
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

Instrumentation splits transactions into steps when streaming=True in codeAgent #1322

Open
bruriah1999 opened this issue Mar 1, 2025 · 6 comments
Labels
bug Something isn't working instrumentation: smolagents

Comments

@bruriah1999
Copy link

My app writes instrumentations via Opentelemtry-sdk==1.29.0, opentelemtry-exporter-otlp==1.29.0 and openinference-instrumentation-smolagents==0.1.4
My smolagents version is 1.9.2

my_agent = CodeAgent(model=my_model, tools=my_tools_list)
my_agent.run("say hello", stream=True) causes each span to be its own step instead of all step being gathered under the same trace

Thank you for your help

@bruriah1999 bruriah1999 added bug Something isn't working triage Issues that require triage labels Mar 1, 2025
Copy link

dosubot bot commented Mar 1, 2025

Hey @bruriah1999! 👋 I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!

The behavior you're observing, where each span is treated as its own step instead of being grouped under a single trace when stream=True, is likely due to how the openinference-instrumentation-smolagents package handles streaming operations. In streaming mode, the response is wrapped in a streaming object, and the span is managed alongside this streaming response, which might lead to spans being created for each step separately [1].

To address this, ensure that the SmolagentsInstrumentor is correctly set up to manage spans and traces during the execution of the run method. The instrumentor should wrap the run and step methods to enable comprehensive tracing, capturing all steps under a single trace. This involves using the OITracer to manage the lifecycle of spans and ensure they are correctly grouped [2].

If the issue persists, you might want to check the configuration of your OpenTelemetry setup to ensure that spans are being correctly linked to the same trace. This could involve verifying the context propagation settings or reviewing how spans are started and ended in your specific implementation.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@bruriah1999
Copy link
Author

@dosu

How can I make my smolagents instrument treat a step as MultiAgent.run child span and not as it's own span then? Is there a way to control it from the configuration?

Copy link

dosubot bot commented Mar 2, 2025

To make your smolagents instrument treat a step as a child span of MultiAgent.run rather than as its own span, you can control the parent-child relationship of spans using the OITracer class. Specifically, you can use the startActiveSpan method to create a parent span and the startSpan method to create a child span. The child span should be nested under the parent span by ensuring that the parentSpanId of the child span matches the spanId of the parent span [1].

Additionally, you can configure span grouping using context managers like using_session, using_user, and using_attributes to specify session IDs, user IDs, and other metadata. This helps in tracking and grouping spans under a single trace [2].

Ensure that your configuration and implementation correctly utilize these methods and context managers to achieve the desired span hierarchy.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@bruriah1999
Copy link
Author

@dosu
I'm not the one writing the spans tho, that's the way openinference-instrumentation-smolagents has implemented it - in such a way each step is being it's own transaction and not a span under CodeAgent.run
Is there a way you can fix it or I could pass some configuration to make it aggregated?

Copy link

dosubot bot commented Mar 2, 2025

The openinference-instrumentation-smolagents package manages span hierarchy by default, but it seems like the current implementation is creating separate transactions for each step. Unfortunately, I can't directly fix this for you, but you can try configuring the SmolagentsInstrumentor to change the default behavior.

You can pass a custom TraceConfig and tracer_provider when calling the _instrument method of the SmolagentsInstrumentor. This allows you to customize how spans are created and managed, potentially enabling you to aggregate steps under a single parent span like CodeAgent.run [1].

If the package doesn't currently support this configuration directly, you might need to modify the instrumentation logic to ensure that spans are nested correctly. This could involve adjusting how spans are started and ended, ensuring that child spans are created with the correct parent span context.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@RogerHYang RogerHYang removed the triage Issues that require triage label Mar 3, 2025
@mikeldking
Copy link
Contributor

Hi @bruriah1999 thanks for reporting! We'll take a look very soon - the smolagents team did the initial contribution for this integration but we'll report back here when we know more.

@axiomofjoy axiomofjoy removed their assignment Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working instrumentation: smolagents
Projects
Status: No status
Development

No branches or pull requests

4 participants