Skip to content

Datadog

application_kit.datadog.configure_datadog

configure_datadog(worker_name=None)

Setups datadog integration.

  • service name will be computed from current application name optionally appending worker_name to it.
  • checks that worker_name is declared in the workers section of the manifest if not None
PARAMETER DESCRIPTION
worker_name

The worker_name to use.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
str | None

The datadog service name that was computed

Source code in application_kit/datadog/__init__.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def configure_datadog(
    worker_name: Annotated[str | None, Doc("The worker_name to use.")] = None,
) -> Annotated[str | None, Doc("The datadog service name that was computed")]:
    """Setups datadog integration.

    - service name will be computed from current application name optionally appending worker_name to it.
    - checks that worker_name is declared in the workers section of the manifest if not None
    """

    service_name = None
    datadog_configuration = get_datadog_configuration(worker_name)

    if datadog_configuration is not None:
        service_name = datadog_configuration.service_name

        logger.info(
            f"Configuring datadog with service : '{service_name}' with environment "
            f"'{datadog_configuration.environment}'."
        )

        ddtrace.trace.tracer.configure(hostname="dd-agent", port=8126, enabled=True)

        ddtrace.config.django["service_name"] = service_name

        ddtrace.config.http.trace_query_string = True

        ddtrace.config.service = service_name

        ddtrace.trace.tracer.set_tags(
            {
                "env": datadog_configuration.environment,
                "version": datadog_configuration.version,
                "service": service_name,
            }
        )
        ddtrace.trace.tracer._services = {service_name}
        ddtrace.patch_all()
        RuntimeMetrics.enable(dogstatsd_url="udp://dd-agent:8125", tracer=ddtrace.trace.tracer)
    else:
        ddtrace.trace.tracer.configure(enabled=False)

    return service_name