Skip to content

Add optional OpenTelemetry tracing and metrics - #1615

Closed
singhvishalkr wants to merge 1 commit into
kyegomez:masterfrom
singhvishalkr:feat/opentelemetry-integration
Closed

Add optional OpenTelemetry tracing and metrics#1615
singhvishalkr wants to merge 1 commit into
kyegomez:masterfrom
singhvishalkr:feat/opentelemetry-integration

Conversation

@singhvishalkr

@singhvishalkr singhvishalkr commented May 16, 2026

Copy link
Copy Markdown

Summary

This PR adds OpenTelemetry instrumentation for observability into agent and multi-agent workflow executions, addressing issue #1199.

Key features:

  • Optional tracing that activates only when SWARMS_OTEL_ENABLED=true and dependencies are installed
  • Automatic span creation for Agent.run(), SwarmRouter.run(), SequentialWorkflow.run(), and ConcurrentWorkflow.run()
  • Metrics collection for run counts, durations, and errors
  • Graceful degradation when OTEL packages aren't installed

Span attributes captured:

  • Agent: name, id, model, max_loops, has_image, duration, status
  • Swarm: name, id, type, agent_count, duration, status

Configuration via environment variables:

  • SWARMS_OTEL_ENABLED - Enable/disable tracing (default: false)
  • OTEL_SERVICE_NAME - Service name (default: swarms)
  • OTEL_EXPORTER_OTLP_ENDPOINT - OTLP collector endpoint

Changes

  • Add swarms/telemetry/otel.py with tracing context manager, decorators, and metrics
  • Integrate tracing into Agent, SwarmRouter, SequentialWorkflow, ConcurrentWorkflow
  • Add optional opentelemetry-* dependencies to pyproject.toml
  • Add documentation at docs/swarms/telemetry/opentelemetry.md
  • Add example at examples/telemetry/otel_tracing_example.py
  • Add unit tests at ests/telemetry/test_otel.py

Test plan

  • Verify syntax compilation passes (done locally)
  • Run with OTEL disabled - no overhead or errors
  • Run with OTEL enabled + Jaeger - traces appear correctly
  • Run existing tests to ensure no regressions

Closes #1199


📚 Documentation preview 📚: https://swarms--1615.org.readthedocs.build/en/1615/

Add OpenTelemetry instrumentation for agent and multi-agent workflow observability. Tracing is disabled by default and activates only when SWARMS_OTEL_ENABLED=true and dependencies are available.

Changes: Add swarms/telemetry/otel.py with tracing decorators and metrics. Integrate tracing into Agent.run(), SwarmRouter, SequentialWorkflow, ConcurrentWorkflow. Add optional opentelemetry dependencies. Add documentation, example, and tests.

Closes kyegomez#1199

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests structs telemetry labels May 16, 2026
@kyegomez kyegomez closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation structs telemetry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT][OpenTelemetry Integration][Bounty][100$]

2 participants