Skip to content

Conversation

@strands-agent
Copy link
Contributor

@strands-agent strands-agent commented Jan 14, 2026

Description

Adds an enabled parameter to StrandsTelemetry class 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

  • New feature (non-breaking change which adds functionality)

Changes Made

StrandsTelemetry class enhancements:

  1. New enabled parameter in constructor:

    • Defaults to True unless STRANDS_OTEL_ENABLED environment variable is set to false/0/no/off
    • Explicit enabled=False overrides environment variable
  2. NoOpTracerProvider usage:

    • When disabled, uses OpenTelemetry's built-in NoOpTracerProvider instead of SDKTracerProvider
    • No spans are created or exported
  3. No-op setup methods:

    • setup_console_exporter(), setup_otlp_exporter(), and setup_meter() become no-ops when disabled
    • Methods still return self to maintain method chaining compatibility
  4. New enabled property:

    • Read-only property to check if telemetry is enabled

Usage Examples

# Disable via constructor
StrandsTelemetry(enabled=False)

# Disable via environment variable
# export STRANDS_OTEL_ENABLED=false
StrandsTelemetry()  # Will use NoOpTracerProvider

# Method chaining still works when disabled
StrandsTelemetry(enabled=False).setup_console_exporter().setup_otlp_exporter()

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)
Lint checks pass (rebased onto latest main)
⚠️ check-api failure is EXPECTED and ACCEPTABLE - This PR intentionally adds a new public API parameter (enabled) to StrandsTelemetry. This is a non-breaking addition (defaults maintain existing behavior).

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective
  • My changes generate no new warnings
  • This is a non-breaking change (existing code continues to work unchanged)

🤖 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.

@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@strands-agent strands-agent force-pushed the feat/disable-otel-instrumentation branch from 36ec56f to c094c85 Compare January 15, 2026 12:14
@github-actions github-actions bot removed the size/m label Jan 15, 2026
…tation

Adds an 'enabled' parameter to StrandsTelemetry class that allows
disabling OpenTelemetry instrumentation. When disabled:

- Uses NoOpTracerProvider instead of SDKTracerProvider
- All setup methods (setup_console_exporter, setup_otlp_exporter,
  setup_meter) become no-ops but still return self for chaining
- Supports both programmatic disabling and environment variable

Configuration options:
- enabled=False in constructor
- STRANDS_OTEL_ENABLED=false|0|no|off environment variable

Resolves strands-agents#1059
@strands-agent strands-agent force-pushed the feat/disable-otel-instrumentation branch from c094c85 to 0304cbc Compare January 17, 2026 20:08
@github-actions github-actions bot added size/m and removed size/m labels Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add a configuration to disable OpenTelemetry instrumentation

1 participant