Class DatadogTracing

java.lang.Object
codes.grow.packages.datadogapm.DatadogTracing

public final class DatadogTracing extends Object
initTracing for Datadog: the OpenTelemetry SDK exporting OTLP to the Datadog Agent (HTTP/protobuf on 4318 by default, or gRPC on 4317), unified service tagging, the Datadog + W3C propagators, the Datadog error attributes and the terminated-context links (API.md section 2, DECISIONS.md #2, #5).

 try (DatadogTracingHandle tracing = DatadogTracing.initTracing(
     TracingConfig.builder("checkout").environment("prod").build())) {
   Spans.withSpan("charge", () -> charge(order));
 }
 
  • Field Details

    • DATADOG_DEFAULT_PROPAGATORS

      public static final List<String> DATADOG_DEFAULT_PROPAGATORS
      Default propagators of this package: Datadog headers, W3C trace context and baggage.
  • Method Details

    • orderPropagators

      public static List<String> orderPropagators(List<String> names)
      Puts tracecontext before datadog so the Datadog propagator sees the W3C result and applies the conflict rules (Datadog wins); every other name keeps its position. Names are trimmed and lower-cased.
      Parameters:
      names - propagator names
      Returns:
      the ordered names
    • exporterFactory

      public static SpanExporterFactory exporterFactory()
      The exporter factory of this package (see createExporter(TracingConfig)).
      Returns:
      factory
    • createExporter

      public static io.opentelemetry.sdk.trace.export.SpanExporter createExporter(TracingConfig config)
      Creates the span exporter: OTLP http/protobuf or grpc to the config's endpoint (default: the local Agent, http://127.0.0.1:4318/v1/traces or http://127.0.0.1:4317), wrapped in a DatadogSpanExporter.
      Parameters:
      config - tracing config
      Returns:
      exporter
      Throws:
      ConfigException - for the native protocol (the package exports OTLP only)
    • tracingConfig

      public static TracingConfig.Builder tracingConfig(DatadogApmConfig apm)
      A tracing config builder prefilled from a DatadogApmConfig: service name, version, environment, OTLP endpoint and protocol, DD_TAGS as resource attributes, TLS and the Datadog default propagators.
      Parameters:
      apm - Agent/service settings
      Returns:
      builder
      Throws:
      ConfigException - when apm has no service name (DD_SERVICE)
    • initTracing

      public static DatadogTracingHandle initTracing()
      Sets up tracing entirely from the environment (DatadogApmConfig.fromEnv(): DD_SERVICE, DD_ENV, DD_VERSION, DD_TAGS, DD_AGENT_HOST, GROW_DATADOG_APM_*, OTEL_EXPORTER_OTLP_*).
      Returns:
      handle
      Throws:
      ConfigException - when the environment is invalid or names no service
    • initTracing

      public static DatadogTracingHandle initTracing(TracingConfig config)
      Sets up OpenTelemetry tracing that exports to the Datadog Agent (SPEC section 5), with the environment (DatadogApmConfig) as defaults for the fields config leaves unset. A field equal to its template default (protocol http/protobuf, propagators tracecontext,baggage) counts as unset.
      • OTLP http/protobuf to http://<agent>:4318/v1/traces by default, or grpc to http://<agent>:4317 (the Agent needs its OTLP receiver enabled);
      • unified service tagging: service name / version / environment become resource service.name / service.version / deployment.environment.name (Datadog service, version, env), plus DD_TAGS as resource attributes;
      • propagators datadog, tracecontext, baggage when config keeps the template default list (Datadog headers win on conflict);
      • the Datadog error attributes and the terminated-context link (DatadogSpanExporter).
      Parameters:
      config - tracing config
      Returns:
      handle
      Throws:
      ConfigException - for the native protocol or an invalid environment
    • initTracing

      public static DatadogTracingHandle initTracing(TracingConfig config, DatadogApmConfig apm)
      initTracing(TracingConfig) with explicit Agent/service settings instead of the environment.
      Parameters:
      config - tracing config
      apm - Agent/service settings (Agent host, OTLP endpoint, version, env, tags, TLS)
      Returns:
      handle
      Throws:
      ConfigException - for the native protocol