-
Notifications
You must be signed in to change notification settings - Fork 505
Implement concurrent.futures instrumentation for OpenTelemetry contex… #1018
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
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
tcdent
left a comment
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.
Nice!
Can you merge in #1021 before I approve since there will likely be some conflicts.
I do like having the constants at the top of instrumentation/__init__.py
744ef47 to
397760c
Compare
…dd-concurrency-instrumentaion
…dd-concurrency-instrumentaion
dot-agi
left a comment
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.
My primary concern is this should not be instrumented but rather be a part of the core SDK using proper context management and thread handling.
The SDK is responsible for creating the traces, instrumentation, span management and export so it does not make sense for it to be an instrumentation object. Also, monkey patching is for the external libraries and not for the default internal libraries.
Fundamental design issue here so this must be refactored into the core SDK.
|
With this instrumentation, context propagation for concurrent.futures only activates when ThreadPoolExecutor is actually used. If we integrate this into the SDK core, the context management overhead would be present for all applications, even those that never use concurrent.futures threading. The current approach follows the principle of lazy loading - context propagation is only applied when the specific threading mechanism is utilized. This keeps the core SDK lightweight while ensuring robust context handling only where needed. |
…dd-concurrency-instrumentaion
dot-agi
left a comment
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.
- Using the code in the gist, I got only 2 LLM calls for the first 2 prompts. Validate this.
withtrace context management is now a feature but does not work with this.
…dd-concurrency-instrumentaion
dot-agi
left a comment
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.
We rolling @fenilfaldu 🔥


📥 Pull Request
📘 Description
While implementing mem0 instrumentation, discovered that multiple isolated traces were being created instead of proper parent-child span relationships within a session. This broke the trace hierarchy and made it difficult to understand the flow of operations.
Root Cause: mem0 (and potentially other LLM libraries) uses
ThreadPoolExecutorfor concurrent operations, but AgentOps lacked instrumentation for thread pool execution contexts. This caused trace context to be lost when operations moved to background threads, resulting in orphaned spans instead of a cohesive trace tree.These changes improve the observability and reliability of concurrent operations within the AgentOps SDK.
🧪 Testing
https://gist.github.com/fenilfaldu/e3d2b8479e8a0eee3c10608878e49a2e