Python: Telemetry and observability follow-up (#833)

* updated telemetry work

* updated telemetry

* slight improvement

* updated tests

* fixes for telemetry

* fixes for mypy

* added settings setup to runner to avoid error

* streamline usage

* updated tests

* updated tests

* further refinement

* fix dumped item for otel

* removed enable_workflow_otel

* final fixes

* final fixes

* updated samples

* removed exporters

* fix tests

* fixed last import'

* fixed devui
This commit is contained in:
Eduard van Valkenburg
2025-09-23 08:21:56 +02:00
committed by GitHub
Unverified
parent f93f16a9ad
commit 2576e7a091
52 changed files with 1625 additions and 1586 deletions
@@ -4,7 +4,7 @@ import asyncio
import os
from typing import Any
from agent_framework import Executor, WorkflowBuilder, WorkflowContext, handler
from agent_framework import Executor, WorkflowBuilder, WorkflowContext, get_logger, handler
"""Basic tracing workflow sample.
@@ -14,7 +14,7 @@ A minimal two executor workflow demonstrates built in OpenTelemetry spans when d
The sample raises an error if tracing is not configured.
Purpose:
- Require diagnostics by checking AGENT_FRAMEWORK_WORKFLOW_ENABLE_OTEL_DIAGNOSTICS and wiring a console exporter.
- Require diagnostics by checking ENABLE_OTEL and wiring a console exporter.
- Show the span categories produced by a simple graph:
- workflow.build (events: build.started, build.validation_completed, build.completed, edge_group.process)
- workflow.run (events: workflow.started, workflow.completed or workflow.error)
@@ -26,32 +26,26 @@ Prerequisites:
- No external services required for the workflow itself.
- To print spans to the console, install the OpenTelemetry SDK: pip install opentelemetry-sdk
- Enable diagnostics:
configure your .env file with `AGENT_FRAMEWORK_WORKFLOW_ENABLE_OTEL_DIAGNOSTICS=true` or run:
export AGENT_FRAMEWORK_WORKFLOW_ENABLE_OTEL_DIAGNOSTICS=true
configure your .env file with `ENABLE_OTEL=true` or run:
export ENABLE_OTEL=true
"""
logger = get_logger()
def _ensure_tracing_configured() -> None:
"""Fail fast unless diagnostics are enabled and the SDK is present.
If the env var is set, attach a ConsoleSpanExporter so spans print to stdout.
"""
env = os.getenv("AGENT_FRAMEWORK_WORKFLOW_ENABLE_OTEL_DIAGNOSTICS", "").lower()
env = os.getenv("ENABLE_OTEL", "").lower()
if env not in {"1", "true", "yes"}:
raise RuntimeError(
"Tracing diagnostics are disabled. Set AGENT_FRAMEWORK_WORKFLOW_ENABLE_OTEL_DIAGNOSTICS=true "
"and rerun the sample."
)
try:
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
except Exception as exc: # pragma: no cover
raise RuntimeError("OpenTelemetry SDK not found. Install it with: pip install opentelemetry-sdk") from exc
logger.info("Tracing diagnostics are disabled in the env. Setting this manually here.")
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(provider)
from agent_framework.observability import setup_observability
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
setup_observability(exporters=[ConsoleSpanExporter()])
class StartExecutor(Executor):