{"slug": "autogen-observability-monitoring-with-opentelemetry", "title": "AutoGen Observability & Monitoring with OpenTelemetry", "summary": "Microsoft and SigNoz have released a guide for setting up observability and monitoring for AutoGen AI applications using OpenTelemetry, enabling developers to export logs, traces, and metrics to SigNoz for real-time visibility into latency, error rates, and usage trends. The integration allows users to instrument AutoGen workflows with no-code auto-instrumentation or manual configuration, capturing request/response details and system-level metrics to debug issues, optimize performance, and improve reliability.", "body_md": "Overview\n\nThis guide walks you through setting up observability and monitoring for AutoGen using [OpenTelemetry](https://opentelemetry.io/) and exporting logs, traces, and metrics to SigNoz. With this integration, you can observe various models performance, capture request/response details, and track system-level metrics in SigNoz, giving you real-time visibility into latency, error rates, and usage trends for your AutoGen applications.\n\nInstrumenting AutoGen in your AI applications with telemetry ensures full observability across your AI workflows, making it easier to debug issues, optimize performance, and understand user interactions. By leveraging SigNoz, you can analyze correlated traces, logs, and metrics in unified dashboards, configure alerts, and gain actionable insights to continuously improve reliability, responsiveness, and user experience.\n\nPrerequisites\n\n- A\n[SigNoz Cloud account](https://signoz.io/teams/)with an active ingestion key - Internet access to send telemetry data to SigNoz Cloud\n- Python 3.10+ with AutoGen installed (\n`pip install autogen-agentchat autogen-ext autogen-core`\n\n) - For Python:\n`pip`\n\ninstalled for managing Python packages and*(optional but recommended)*a Python virtual environment to isolate dependencies\n\nMonitoring AutoGen\n\nFor more detailed info on tracing your AutoGen applications click [here](https://microsoft.github.io/autogen/stable//user-guide/core-user-guide/framework/telemetry.html). For logging, click [here](https://microsoft.github.io/autogen/stable//user-guide/core-user-guide/framework/logging.html).\n\nNo-code auto-instrumentation is recommended for quick setup with minimal code changes. It's ideal when you want to get observability up and running without modifying your application code and are leveraging standard instrumentor libraries.\n\n**Step 1:** Install the necessary packages in your Python environment.\n\n```\npip install \\\n  opentelemetry-api \\\n  opentelemetry-distro \\\n  opentelemetry-exporter-otlp \\\n  httpx \\\n  \"autogen-agentchat\" \\\n  \"autogen-ext[openai]\" \\\n  \"autogen-core\"\n```\n\n**Step 2:** Add Automatic Instrumentation\n\n```\nopentelemetry-bootstrap --action=install\n```\n\n**Step 3:** Instrument your AutoGen application\n\n**For Traces:**\n\nConfigure AutoGen to use OpenTelemetry tracing by passing the tracer provider to the runtime:\n\n``` python\nfrom opentelemetry import trace\nfrom autogen_core import SingleThreadedAgentRuntime\n\ntracer_provider = trace.get_tracer_provider()\nsingle_threaded_runtime = SingleThreadedAgentRuntime(tracer_provider=tracer_provider)\n```\n\n**For Logs:**\n\nConfigure AutoGen logging to capture trace logs:\n\n``` python\nimport logging\n\nfrom autogen_core import TRACE_LOGGER_NAME\n\nlogging.basicConfig(level=logging.WARNING)\nlogger = logging.getLogger(TRACE_LOGGER_NAME)\nlogger.addHandler(logging.StreamHandler())\nlogger.setLevel(logging.DEBUG)\n```\n\n📌 Note: Ensure this is configured before initializing your AutoGen agents to properly instrument your application\n\n**Step 4:** Run an example\n\n``` python\nfrom autogen_agentchat.agents import AssistantAgent\nfrom autogen_agentchat.ui import Console\nfrom autogen_ext.models.openai import OpenAIChatCompletionClient\nfrom opentelemetry import trace\nfrom autogen_core import (\n\n    SingleThreadedAgentRuntime,\n    TRACE_LOGGER_NAME\n)\nimport logging\nimport asyncio\n\nlogging.basicConfig(level=logging.WARNING)\n\nlogger = logging.getLogger(TRACE_LOGGER_NAME)\nlogger.addHandler(logging.StreamHandler())\nlogger.setLevel(logging.DEBUG)\n\n# Get the tracer provider from your application\ntracer_provider = trace.get_tracer_provider()\n\n# for single threaded runtime\nsingle_threaded_runtime = SingleThreadedAgentRuntime(tracer_provider=tracer_provider)\n\n# Define a model client.\nmodel_client = OpenAIChatCompletionClient(\n    model=\"gpt-4o-mini\"\n)\n\n# Define a simple function tool that the agent can use.\n# For this example, we use a fake weather tool for demonstration purposes.\nasync def get_weather(city: str) -> str:\n    \"\"\"Get the weather for a given city.\"\"\"\n    return f\"The weather in {city} is 73 degrees and Sunny.\"\n\n# Define an AssistantAgent with the model, tool, system message, and reflection enabled.\n# The system message instructs the agent via natural language.\nagent = AssistantAgent(\n    name=\"weather_agent\",\n    model_client=model_client,\n    tools=[get_weather],\n    system_message=\"You are a helpful assistant.\",\n    reflect_on_tool_use=True,\n    model_client_stream=True,  # Enable streaming tokens from the model client.\n)\n\n# Run the agent and stream the messages to the console.\nasync def main() -> None:\n    await Console(agent.run_stream(task=\"What is the weather in New York?\"))\n    # Close the connection to the model client.\n    await model_client.close()\n\nasyncio.run(main())\n```\n\n📌 Note: Before running this code, ensure that you have set the environment variable\n\n`OPENAI_API_KEY`\n\nwith your generated API key.\n\n**Step 5:** Run your application with auto-instrumentation\n\n```\nOTEL_RESOURCE_ATTRIBUTES=\"service.name=<service_name>\" \\\nOTEL_EXPORTER_OTLP_ENDPOINT=\"https://ingest.<region>.signoz.cloud:443\" \\\nOTEL_EXPORTER_OTLP_HEADERS=\"signoz-ingestion-key=<your-ingestion-key>\" \\\nOTEL_EXPORTER_OTLP_PROTOCOL=grpc \\\nOTEL_TRACES_EXPORTER=otlp \\\nOTEL_METRICS_EXPORTER=otlp \\\nOTEL_LOGS_EXPORTER=otlp \\\nOTEL_PYTHON_LOG_CORRELATION=true \\\nOTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true \\\nopentelemetry-instrument <your_run_command>\n```\n\nis the name of your service`<service_name>`\n\n`<region>`\n\n: Your[SigNoz Cloud region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint)`<your-ingestion-key>`\n\n: Your SigNoz[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/)- Replace\n`<your_run_command>`\n\nwith the actual command you would use to run your application. For example:`python main.py`\n\nUsing self-hosted SigNoz? Most steps are identical. To adapt this guide, update the endpoint and remove the ingestion key header as shown in [Cloud → Self-Hosted](/docs/ingestion/cloud-vs-self-hosted/#cloud-to-self-hosted).\n\nCode-based instrumentation gives you fine-grained control over your telemetry configuration. Use this approach when you need to customize resource attributes, sampling strategies, or integrate with existing observability infrastructure.\n\n**Step 1:** Install the necessary packages in your Python environment.\n\n```\npip install \\\n  opentelemetry-api \\\n  opentelemetry-sdk \\\n  opentelemetry-exporter-otlp \\\n  opentelemetry-instrumentation-httpx \\\n  opentelemetry-instrumentation-system-metrics \\\n  \"autogen-agentchat\" \\\n  \"autogen-ext[openai]\" \\\n  \"autogen-core\"\n```\n\n**Step 2:** Import the necessary modules in your Python application\n\n**Traces:**\n\n``` python\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\n```\n\n**Logs:**\n\n``` python\nfrom opentelemetry.sdk._logs import LoggerProvider, LoggingHandler\nfrom opentelemetry.sdk._logs.export import BatchLogRecordProcessor\nfrom opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter\nfrom opentelemetry._logs import set_logger_provider\nimport logging\n```\n\n**Metrics:**\n\n``` python\nfrom opentelemetry.sdk.metrics import MeterProvider\nfrom opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter\nfrom opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader\nfrom opentelemetry import metrics\nfrom opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor\nfrom opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor\n```\n\n**Step 3:** Set up the OpenTelemetry Tracer Provider to send traces directly to SigNoz Cloud\n\n``` python\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry import trace\nimport os\n\nresource = Resource.create({\"service.name\": \"<service_name>\"})\nprovider = TracerProvider(resource=resource)\nspan_exporter = OTLPSpanExporter(\n    endpoint= os.getenv(\"OTEL_EXPORTER_TRACES_ENDPOINT\"),\n    headers={\"signoz-ingestion-key\": os.getenv(\"SIGNOZ_INGESTION_KEY\")},\n)\nprocessor = BatchSpanProcessor(span_exporter)\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n```\n\nis the name of your service`<service_name>`\n\n→ SigNoz Cloud trace endpoint with appropriate`OTEL_EXPORTER_TRACES_ENDPOINT`\n\n[region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint):`https://ingest.<region>.signoz.cloud:443/v1/traces`\n\n→ Your SigNoz`SIGNOZ_INGESTION_KEY`\n\n[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/)\n\nUsing self-hosted SigNoz? Most steps are identical. To adapt this guide, update the endpoint and remove the ingestion key header as shown in [Cloud → Self-Hosted](/docs/ingestion/cloud-vs-self-hosted/#cloud-to-self-hosted).\n\n**Step 4**: Setup Logs\n\n``` python\nimport logging\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry._logs import set_logger_provider\nfrom opentelemetry.sdk._logs import LoggerProvider, LoggingHandler\nfrom opentelemetry.sdk._logs.export import BatchLogRecordProcessor\nfrom opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter\nimport os\n\nresource = Resource.create({\"service.name\": \"<service_name>\"})\nlogger_provider = LoggerProvider(resource=resource)\nset_logger_provider(logger_provider)\n\notlp_log_exporter = OTLPLogExporter(\n    endpoint= os.getenv(\"OTEL_EXPORTER_LOGS_ENDPOINT\"),\n    headers={\"signoz-ingestion-key\": os.getenv(\"SIGNOZ_INGESTION_KEY\")},\n)\nlogger_provider.add_log_record_processor(\n    BatchLogRecordProcessor(otlp_log_exporter)\n)\n# Attach OTel logging handler to root logger\nhandler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider)\nlogging.basicConfig(level=logging.INFO, handlers=[handler])\n\nlogger = logging.getLogger(__name__)\n```\n\nis the name of your service`<service_name>`\n\n→ SigNoz Cloud endpoint with appropriate`OTEL_EXPORTER_LOGS_ENDPOINT`\n\n[region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint):`https://ingest.<region>.signoz.cloud:443/v1/logs`\n\n→ Your SigNoz`SIGNOZ_INGESTION_KEY`\n\n[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/)\n\nUsing self-hosted SigNoz? Most steps are identical. To adapt this guide, update the endpoint and remove the ingestion key header as shown in [Cloud → Self-Hosted](/docs/ingestion/cloud-vs-self-hosted/#cloud-to-self-hosted).\n\n**Step 5**: Setup Metrics\n\n``` python\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.metrics import MeterProvider\nfrom opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter\nfrom opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader\nfrom opentelemetry import metrics\nfrom opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor\nimport os\n\nresource = Resource.create({\"service.name\": \"<service-name>\"})\nmetric_exporter = OTLPMetricExporter(\n    endpoint= os.getenv(\"OTEL_EXPORTER_METRICS_ENDPOINT\"),\n    headers={\"signoz-ingestion-key\": os.getenv(\"SIGNOZ_INGESTION_KEY\")},\n)\nreader = PeriodicExportingMetricReader(metric_exporter)\nmetric_provider = MeterProvider(metric_readers=[reader], resource=resource)\nmetrics.set_meter_provider(metric_provider)\n\nmeter = metrics.get_meter(__name__)\n\n# turn on out-of-the-box metrics\nSystemMetricsInstrumentor().instrument()\nHTTPXClientInstrumentor().instrument()\n```\n\nis the name of your service`<service_name>`\n\n→ SigNoz Cloud endpoint with appropriate`OTEL_EXPORTER_METRICS_ENDPOINT`\n\n[region](https://signoz.io/docs/ingestion/signoz-cloud/overview/#endpoint):`https://ingest.<region>.signoz.cloud:443/v1/metrics`\n\n→ Your SigNoz`SIGNOZ_INGESTION_KEY`\n\n[ingestion key](https://signoz.io/docs/ingestion/signoz-cloud/keys/)\n\nUsing self-hosted SigNoz? Most steps are identical. To adapt this guide, update the endpoint and remove the ingestion key header as shown in [Cloud → Self-Hosted](/docs/ingestion/cloud-vs-self-hosted/#cloud-to-self-hosted).\n\n📌 Note: SystemMetricsInstrumentor provides system metrics (CPU, memory, etc.), and HTTPXClientInstrumentor provides outbound HTTP request metrics such as request duration. If you want to add custom metrics to your AutoGen application, see\n\n[Python Custom Metrics].\n\n**Step 6:** Instrument your AutoGen application\n\n**For Traces:**\n\nConfigure AutoGen to use OpenTelemetry tracing by passing the tracer provider to the runtime:\n\n``` python\nfrom opentelemetry import trace\nfrom autogen_core import SingleThreadedAgentRuntime\n\ntracer_provider = trace.get_tracer_provider()\nsingle_threaded_runtime = SingleThreadedAgentRuntime(tracer_provider=tracer_provider)\n```\n\n**For Logs:**\n\nConfigure AutoGen logging to capture trace logs:\n\n``` python\nimport logging\nfrom autogen_core import TRACE_LOGGER_NAME\n\nlogging.basicConfig(level=logging.WARNING)\nlogger = logging.getLogger(TRACE_LOGGER_NAME)\nlogger.addHandler(logging.StreamHandler())\nlogger.setLevel(logging.DEBUG)\n```\n\n📌 Note: Ensure this is configured before initializing your AutoGen agents to properly instrument your application\n\n**Step 7:** Run an example\n\n``` python\nfrom autogen_agentchat.agents import AssistantAgent\nfrom autogen_agentchat.ui import Console\nfrom autogen_ext.models.openai import OpenAIChatCompletionClient\nimport asyncio\n\n# Define a model client.\nmodel_client = OpenAIChatCompletionClient(\n    model=\"gpt-4o-mini\"\n)\n\n# Define a simple function tool that the agent can use.\n# For this example, we use a fake weather tool for demonstration purposes.\nasync def get_weather(city: str) -> str:\n    \"\"\"Get the weather for a given city.\"\"\"\n    return f\"The weather in {city} is 73 degrees and Sunny.\"\n\n# Define an AssistantAgent with the model, tool, system message, and reflection enabled.\n# The system message instructs the agent via natural language.\nagent = AssistantAgent(\n    name=\"weather_agent\",\n    model_client=model_client,\n    tools=[get_weather],\n    system_message=\"You are a helpful assistant.\",\n    reflect_on_tool_use=True,\n    model_client_stream=True,  # Enable streaming tokens from the model client.\n)\n\n# Run the agent and stream the messages to the console.\nasync def main() -> None:\n    await Console(agent.run_stream(task=\"What is the weather in New York?\"))\n    # Close the connection to the model client.\n    await model_client.close()\n\nasyncio.run(main())\n```\n\n📌 Note: Before running this code, ensure that you have set the environment variable\n\n`OPENAI_API_KEY`\n\nwith your generated API key.\n\nView Traces, Logs, and Metrics in SigNoz\n\nYour AutoGen commands should now automatically emit traces, logs, and metrics.\n\nYou should be able to view traces in Signoz Cloud under the traces tab:\n\nWhen you click on a trace in SigNoz, you'll see a detailed view of the trace, including all associated spans, along with their events and attributes.\n\nYou should be able to view logs in Signoz Cloud under the logs tab. You can also view logs by clicking on the “Related Logs” button in the trace view to see correlated logs:\n\nWhen you click on any of these logs in SigNoz, you'll see a detailed view of the log, including attributes:\n\nYou should be able to see AutoGen related metrics in Signoz Cloud under the metrics tab:\n\nWhen you click on any of these metrics in SigNoz, you'll see a detailed view of the metric, including attributes:\n\nTroubleshooting\n\nIf you don't see your telemetry data:\n\n**Verify network connectivity**- Ensure your application can reach SigNoz Cloud endpoints** Check ingestion key**- Verify your SigNoz ingestion key is correct** Wait for data**- OpenTelemetry batches data before sending, so wait 10-30 seconds after making API calls** Try a console exporter**— Enable a console exporter locally to confirm that your application is generating telemetry data before it’s sent to SigNoz\n\nNext Steps\n\nYou can also check out our custom AutoGen dashboard [here](https://signoz.io/docs/dashboards/dashboard-templates/autogen-dashboard/) which provides specialized visualizations for monitoring your AutoGen usage in applications. The dashboard includes pre-built charts specifically tailored for LLM usage, along with import instructions to get started quickly.\n\nAdditional resources:\n\n- Set up\n[alerts](https://signoz.io/docs/alerts/)for high latency or error rates - Learn more about\n[querying traces](https://signoz.io/docs/userguide/traces/) - Explore\n[log correlation](https://signoz.io/docs/userguide/logs_query_builder/)", "url": "https://wpnews.pro/news/autogen-observability-monitoring-with-opentelemetry", "canonical_source": "https://signoz.io/docs/autogen-observability", "published_at": "2026-06-11 00:00:00+00:00", "updated_at": "2026-06-12 09:59:41.445789+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "large-language-models", "ai-agents", "mlops"], "entities": ["AutoGen", "OpenTelemetry", "SigNoz"], "alternates": {"html": "https://wpnews.pro/news/autogen-observability-monitoring-with-opentelemetry", "markdown": "https://wpnews.pro/news/autogen-observability-monitoring-with-opentelemetry.md", "text": "https://wpnews.pro/news/autogen-observability-monitoring-with-opentelemetry.txt", "jsonld": "https://wpnews.pro/news/autogen-observability-monitoring-with-opentelemetry.jsonld"}}