admin管理员组

文章数量:1122832

I'm using Datadog with a Flask/Dash application and while the basic Flask routes seem to be traced, I can't see the spans from my Dash callbacks in Datadog. Here's my setup:

from dash import Dash
from functools import wraps
from ddtrace import tracer
from webapp.config import app_config
from framework.logging import logger
from framework.decorators.tracing import trace_callback

class DashWithTelemetry(Dash):
    """Provide logging telemetry for Dash callbacks"""

    def callback(self, *_args, **_kwargs) -> callable:
        def decorator(function: callable) -> callable:
            @super(DashWithTelemetry, self).callback(
                *_args, **_kwargs,
            )
            def wrapper(*args, **kwargs) -> callable:
                decorated_func = trace_callback(
                    pagename=function.__module__.split(".")[-1],
                    name=function.__name__,
                )(function)
                return decorated_func(*args, **kwargs)

            return wrapper

        return decorator

def trace_callback(pagename: str, name: str | None = None) -> callable:
    """
    Decorator to trace Dash callbacks.
    Tracing is disabled when running locally.
    """
    def decorator(func: callable) -> callable:
        @wraps(func)
        def wrapper(*args, **kwargs) -> callable:
            if not app_config.enable_tracing:
                logger.error(f"Tracing {func.__name__} on {pagename=} {name=}")
                return func(*args, **kwargs)

            with tracer.trace(name=name or func.__name__, resource=pagename, service="callbacks"):
                return func(*args, **kwargs)

        return wrapper
    return decorator

The application is ran with:

  • ddtrace-run python app.py
  • app_config.enable_tracing = True
  • apm_config = True

I see the Datadog agent running and collecting my logs. But do not see any spans in Datadog for my Dash Callbacks.

Am I missing something?

The Datadog service is hosted by our Middleware, and they run the ddtrace-run for us.

本文标签: pythonDatadog tracing not showing spans for Dash in Flask applicationStack Overflow