Skip to content

OpenTelemetry is required even when tracing is disabled — should be optional #6768

Closed
@yoichiro0abe

Description

@yoichiro0abe

What happened?

Describe the bug

Even when runtime tracing is explicitly disabled using either:

  • AUTOGEN_DISABLE_RUNTIME_TRACING=true (environment variable), or
  • tracer_provider=NoOpTracerProvider() (in code),

AutoGen still attempts to import OpenTelemetry modules such as:

File "/tmp/8ddbe045cd6d0a5/src/pages/sample_page.py", line 6, in <module>
    from utils.autogen_agent import setup_agent
File "/tmp/8ddbe045cd6d0a5/src/utils/autogen_agent.py", line 1, in <module>
    from autogen_agentchat.agents import (
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_agentchat/agents/__init__.py", line 6, in <module>
    from ._assistant_agent import AssistantAgent
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_agentchat/agents/_assistant_agent.py", line 23, in <module>
    from autogen_core import CancellationToken, Component, ComponentModel, FunctionCall
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_core/__init__.py", line 59, in <module>
    from ._single_threaded_agent_runtime import SingleThreadedAgentRuntime
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 45, in <module>
    from ._telemetry import EnvelopeMetadata, MessageRuntimeTracingConfig, TraceHelper, get_telemetry_envelope_metadata
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_core/_telemetry/__init__.py", line 1, in <module>
    from ._genai import (
File "/tmp/8ddbe045cd6d0a5/antenv/lib/python3.12/site-packages/autogen_core/_telemetry/_genai.py", line 6, in <module>
    from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import (

Expected behavior

If tracing is disabled, OpenTelemetry should not be required as a dependency. Ideally, the import should be:

Lazy-loaded only when tracing is enabled, or
Wrapped in a try/except ImportError block with a clear fallback

Why this matters

It breaks minimal installations where telemetry is not needed
It contradicts the idea that tracing is optional
It increases the dependency surface unnecessarily

Real-world impact

We encountered this issue when deploying an AutoGen 0.6.2-based application to Azure App Service. The deployment failed due to an import error related to opentelemetry.semconv._incubating.attributes.gen_ai_attributes, even though runtime tracing was explicitly disabled.

Azure App Service includes opentelemetry-semantic-conventions==0.52b1 by default in its Python environment. However, AutoGen 0.6.2 requires opentelemetry-semantic-conventions==0.55b1 or later to resolve the import. Since the import is unconditional, and tracing cannot be fully disabled to avoid it, this results in a runtime failure that cannot be bypassed without modifying the environment or the source code.

This makes it difficult to deploy AutoGen in production environments like Azure App Service, where minimizing dependencies and avoiding unnecessary packages is important. It also breaks the expectation that OpenTelemetry is optional when tracing is turned off.

Suggested solution

Consider refactoring the telemetry-related imports to be conditional or lazy-loaded, so that users who opt out of tracing can run AutoGen without installing OpenTelemetry.

Which packages was the bug in?

Python Core (autogen-core)

AutoGen library version.

Python 0.6.2

Other library version.

No response

Model used

No response

Model provider

Azure OpenAI

Other model provider

No response

Python version

3.12

.NET version

None

Operating system

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions