-
-
Notifications
You must be signed in to change notification settings - Fork 717
[BOUNTY/FEAT-TELEMETRY][Added Telemetry to agent.py and all swarms structs] #1200
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
base: master
Are you sure you want to change the base?
Conversation
Added OpenTelemetry integration for tracing and metrics.
Added OpenTelemetry integration functions to __all__ export.
This file implements OpenTelemetry integration for the Swarms framework, enabling distributed tracing, metrics, and logging capabilities. It includes configuration options via environment variables and provides functions for tracing, logging, and metrics recording.
Add telemetry support for agent execution and LLM calls.
| from swarms.telemetry.opentelemetry_integration import ( | ||
| trace_span, | ||
| record_metric, | ||
| log_event, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| from swarms.telemetry.opentelemetry_integration import ( | ||
| trace_span, | ||
| record_metric, | ||
| get_current_trace_context, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| span_manager = nullcontext() | ||
|
|
||
| try: | ||
| self.swarm = self._create_swarm(task, *args, **kwargs) |
Check failure
Code scanning / Pyre
Undefined attribute Error
| span_manager = nullcontext() | ||
|
|
||
| try: | ||
| self.swarm = self._create_swarm(task, *args, **kwargs) |
Check failure
Code scanning / Pyre
Incompatible parameter type Error
| from swarms.telemetry.opentelemetry_integration import ( | ||
| get_tracer, | ||
| get_meter, | ||
| trace_span, | ||
| trace_function, | ||
| record_metric, | ||
| get_current_trace_context, | ||
| set_trace_context, | ||
| log_event, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import ( | ||
| OTLPMetricExporter, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( | ||
| OTLPLogExporter, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( | ||
| OTLPLogExporter, | ||
| ) | ||
| from opentelemetry.sdk.resources import Resource |
Check failure
Code scanning / Pyre
Undefined import Error
| from opentelemetry.trace.propagation.tracecontext import ( | ||
| TraceContextTextMapPropagator, | ||
| ) |
Check failure
Code scanning / Pyre
Undefined import Error
| return | ||
|
|
||
| try: | ||
| from opentelemetry._logs import SeverityNumber |
Check failure
Code scanning / Pyre
Undefined import Error
Description
This PR adds comprehensive OpenTelemetry telemetry integration to the Swarms framework, enabling distributed tracing, metrics, and logging capabilities across agents and multi-agent structures. The implementation follows OpenTelemetry standards and provides observability for agent executions, swarm router operations, and LLM calls.
Key Features
Implementation Details
The telemetry system is integrated at multiple levels:
File Changes
swarms/telemetry/opentelemetry_integration.py(NEW FILE)trace_span()context manager for creating spansrecord_metric()for metrics collectionlog_event()for structured loggingget_current_trace_context()andset_trace_context()swarms/telemetry/__init__.pyswarms/structs/agent.pyenable_telemetryparameter to Agent__init__()method_run()method:call_llm()method:swarms/structs/swarm_router.pytelemetry_enabledparameter to SwarmRouter__init__()method_run()method:Dependencies
opentelemetry-api>=1.20.0opentelemetry-sdk>=1.20.0opentelemetry-exporter-otlp>=1.20.0Note: These dependencies are optional. The framework works without them, but telemetry features will be disabled.
Configuration
Telemetry is configured via environment variables:
OTEL_ENABLED: Enable/disable OpenTelemetry (default: "true")OTEL_SERVICE_NAME: Service name for traces (default: "swarms")OTEL_EXPORTER_OTLP_ENDPOINT: OTLP endpoint URL (e.g., "http://localhost:4317")OTEL_EXPORTER_OTLP_HEADERS: Headers for OTLP exporter (JSON format)OTEL_TRACES_EXPORTER: Traces exporter (default: "otlp")OTEL_METRICS_EXPORTER: Metrics exporter (default: "otlp")OTEL_LOGS_EXPORTER: Logs exporter (default: "otlp")OTEL_SDK_DISABLED: Disable OpenTelemetry SDK (default: "false")Usage Example
Testing
Telemetry integration is tested with Jaeger, Tempo, and OpenTelemetry Collector
Verified trace propagation across agent hierarchies
Confirmed metrics collection and export
Tested graceful degradation when OpenTelemetry packages are not installed
Video of testing with Jaeger:
bounty2.mp4
Issue: #1199
Tag Maintainer
@kyegomez
Twitter Handle
https://x.com/IlumTheProtogen
📚 Documentation preview 📚: https://swarms--1200.org.readthedocs.build/en/1200/