feat(telemetry): add configuration to disable OpenTelemetry instrumentation #1477
+158
−5
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.
Description
Adds an
enabledparameter toStrandsTelemetryclass that allows disabling OpenTelemetry instrumentation. This addresses the use case where Strands Agents is used as part of a system that already has OpenTelemetry enabled, and the user doesn't want to include child spans from Strands.Related Issues
Resolves #1059
Documentation PR
No documentation changes required - the feature is self-documenting via docstrings and follows the existing patterns.
Type of Change
Changes Made
StrandsTelemetryclass enhancements:New
enabledparameter in constructor:TrueunlessSTRANDS_OTEL_ENABLEDenvironment variable is set tofalse/0/no/offenabled=Falseoverrides environment variableNoOpTracerProviderusage:NoOpTracerProviderinstead ofSDKTracerProviderNo-op setup methods:
setup_console_exporter(),setup_otlp_exporter(), andsetup_meter()become no-ops when disabledselfto maintain method chaining compatibilityNew
enabledproperty:Usage Examples
Testing
Added 10 new unit tests covering:
Disabling via constructor
Disabling via environment variable (multiple formats:
false,0,off,no)Explicit enable overriding environment variable
No-op behavior of setup methods when disabled
Method chaining compatibility when disabled
I ran
hatch run prepare(all checks pass locally)CI Status Notes
✅ All unit tests pass (Python 3.10-3.13 on Linux, Windows, macOS)
⚠️ check-api failure is EXPECTED and ACCEPTABLE - This PR intentionally adds a new public API parameter (
✅ Lint checks pass (rebased onto latest main)
enabled) toStrandsTelemetry. This is a non-breaking addition (defaults maintain existing behavior).Checklist
🤖 This is an experimental AI agent response from the Strands team, powered by Strands Agents. We're exploring how AI agents can help with community support and development. Your feedback helps us improve! If you'd prefer human assistance, please let us know.