-
Notifications
You must be signed in to change notification settings - Fork 150
Add OpenTelemetry integration for OpenAI AgentsOpenAI/otel #1286
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
Draft
tconley1428
wants to merge
9
commits into
main
Choose a base branch
from
openai/otel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds seamless OTEL telemetry export for OpenAI agents within Temporal workflows, with proper replay semantics. Features: - Ergonomic API: just pass `otel_exporters=[...]` to OpenAIAgentsPlugin or AgentEnvironment - Multiple exporters: send telemetry to multiple OTEL endpoints simultaneously - Replay-safe: spans only exported when workflows actually complete, not during replays - Deterministic IDs: consistent span IDs across workflow replays for reliable correlation - Automatic setup: no manual instrumentation required - Graceful degradation: works with or without OTEL dependencies installed - Comprehensive documentation in README with examples Implementation: - Added TemporalSpanProcessor for replay-aware span processing (private API) - Enhanced OpenAIAgentsPlugin with otel_exporters parameter - Enhanced AgentEnvironment with otel_exporters parameter - Automatic OTEL instrumentor lifecycle management in plugin run_context - Updated all tests to use new ergonomic API - Moved TemporalSpanProcessor from test code to main codebase as private implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The opentelemetryv2 module and tests have been moved to the 'opentelemetryv2-improvements' branch as they are separate improvements independent from the OpenAI agents OTEL integration. This keeps the OpenAI agents OTEL integration focused and allows the opentelemetryv2 improvements to be tracked separately. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The modifications made to the existing opentelemetry.py module are no longer needed for the OpenAI agents OTEL integration. The OpenAI agents integration now uses its own private TemporalSpanProcessor and doesn't require changes to the core OpenTelemetry interceptor. Reverted changes: - Removed agents import that's not needed in core module - Removed create_spans parameter and related logic - Removed debug print statements - Restored original TracingInterceptor behavior This keeps the core OpenTelemetry module clean and focused on its original purpose while the OpenAI agents OTEL integration handles its own requirements through private implementation details. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Cleaned up debug prints that were added during development: - Removed print statements from _temporal_trace_provider.py trace/span handlers - Removed traceback.print_stack() call - Removed print statements from _trace_interceptor.py context handling - Removed workflow execution debug prints - Removed unused traceback import Production code should not contain debug prints. Test prints were preserved as they're useful for debugging test failures. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…m spans This change gives users explicit control over when their custom spans are captured: **Changes:** - Remove automatic trace creation in `_maybe_trace_and_span()` - Replace with `_maybe_span()` that only creates spans when trace context exists - Users must explicitly call `trace()` to capture their `custom_span()` calls - OpenAI Agent executions still create traces automatically when OTEL exporters are configured **Behavior:** - Without explicit trace: custom_span() calls are dropped (no-ops) - With explicit trace: full span hierarchy is captured correctly - Agent executions always traced when OTEL is enabled **Tests Added:** - `test_custom_span_without_trace_context`: Validates spans are dropped without trace - Enhanced `test_otel_tracing_in_runner`: Validates proper hierarchy with explicit trace This ensures users have full control over their tracing and prevents unwanted automatic trace creation while preserving observability for agent executions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds seamless OTEL telemetry export for OpenAI agents within Temporal workflows, featuring:
Key Files in PR: