Class DatadogApmConfig

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

public final class DatadogApmConfig extends Object
Immutable configuration of a DatadogApmClient, DatadogTracing.initTracing() and DatadogSpansQuery (SPEC section 2.2, API.md section 0, DECISIONS.md #1).

Build one with builder() or read it from the environment with fromEnv(). Precedence: explicit builder value > GROW_DATADOG_APM_<NAME> > vendor variables > default. toString() never prints credentials.

Environment variables
FieldGROW_DATADOG_APM_*Vendor variables
urlURLDD_TRACE_AGENT_URL, else http://${DD_AGENT_HOST}:${DD_TRACE_AGENT_PORT}
otlpEndpointOTLP_HTTP_ENDPOINT / OTLP_GRPC_ENDPOINT (by protocol), OTLP_ENDPOINTOTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_ENDPOINT
protocolOTLP_PROTOCOLOTEL_EXPORTER_OTLP_TRACES_PROTOCOL, OTEL_EXPORTER_OTLP_PROTOCOL
serviceNameSERVICEDD_SERVICE, OTEL_SERVICE_NAME
serviceVersionVERSIONDD_VERSION
environmentENVDD_ENV
tagsTAGSDD_TAGS (explicit tags are merged over them)
apiKeyAPI_KEYDD_API_KEY
appKeyAPP_KEYDD_APP_KEY, DD_APPLICATION_KEY
siteSITEDD_SITE
apiUrlAPI_URL-
  • Field Details

    • OTLP_HTTP_PORT

      public static final int OTLP_HTTP_PORT
      Default Agent OTLP/HTTP port.
      See Also:
    • OTLP_GRPC_PORT

      public static final int OTLP_GRPC_PORT
      Default Agent OTLP/gRPC port.
      See Also:
    • AGENT_TRACE_PORT

      public static final int AGENT_TRACE_PORT
      Default Agent trace intake port (serves GET /info).
      See Also:
    • DEFAULT_URL

      public static final String DEFAULT_URL
      Default Datadog Agent trace intake URL (health, ping and serverVersion use its /info).
      See Also:
    • DEFAULT_PROTOCOL

      public static final TracingConfig.Protocol DEFAULT_PROTOCOL
      Default OTLP protocol of this package.
  • Method Details

    • builder

      public static DatadogApmConfig.Builder builder()
      Starts an empty builder (every field at its default).
      Returns:
      a new builder
    • toBuilder

      public DatadogApmConfig.Builder toBuilder()
      Returns a builder with these values.
      Returns:
      builder copy
    • fromEnv

      public static DatadogApmConfig fromEnv()
      Reads the configuration from the process environment.
      Returns:
      the validated configuration
      Throws:
      ConfigException - when a variable holds an invalid value (the message names the variable, never the value)
    • fromEnv

      public static DatadogApmConfig fromEnv(Map<String,String> env)
      Reads the configuration from an explicit variable map (tests).
      Parameters:
      env - variable map
      Returns:
      the validated configuration
    • parseDatadogTags

      public static Map<String,String> parseDatadogTags(String raw)
      Parses Datadog tags (DD_TAGS): key:value pairs separated by commas and/or spaces. Entries without a : or with an empty key are ignored.
      
       DatadogApmConfig.parseDatadogTags("team:sdk, tier:web"); // {team=sdk, tier=web}
       
      Parameters:
      raw - tag text
      Returns:
      tags in input order
    • otlpTracesUrl

      public static String otlpTracesUrl(TracingConfig.Protocol protocol, String endpoint)
      The exporter URL for a protocol and an OTLP endpoint: for http/protobuf an endpoint without a path gets /v1/traces; gRPC endpoints are used as they are.
      Parameters:
      protocol - OTLP protocol
      endpoint - endpoint URL
      Returns:
      the traces URL
    • otlpTracesEndpoint

      public String otlpTracesEndpoint()
      The resolved OTLP traces URL for protocol() (see otlpTracesUrl(codes.grow.packages.datadogapm.tracing.TracingConfig.Protocol, java.lang.String)): otlpEndpoint() when set, else the host of url() with port 4318 + /v1/traces (HTTP) or port 4317 (gRPC).
      Returns:
      the traces URL
    • hasQueryCredentials

      public boolean hasQueryCredentials()
      Whether both the API key and the application key are set (the query API is usable).
      Returns:
      true when DatadogSpansQuery can be created
    • knownSecrets

      public List<String> knownSecrets()
      The credential values to redact from errors and logs.
      Returns:
      secret values
    • validate

      public void validate()
      Checks every field.
      Throws:
      ConfigException - when a rule is violated
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Transport settings for the Agent (url()).
      Returns:
      the transport configuration
    • queryTransportConfig

      public TransportConfig queryTransportConfig()
      Transport settings for the query API (apiUrl()).
      Returns:
      the transport configuration
    • url

      public String url()
      Agent trace intake base URL (GET /info).
      Returns:
      the URL
    • otlpEndpoint

      public Optional<String> otlpEndpoint()
      OTLP endpoint as configured (see otlpTracesEndpoint() for the resolved URL).
      Returns:
      the endpoint, or empty
    • protocol

      public TracingConfig.Protocol protocol()
      OTLP protocol (http/protobuf by default, or grpc).
      Returns:
      the protocol
    • serviceName

      public Optional<String> serviceName()
      service of unified service tagging (resource service.name).
      Returns:
      the service, or empty
    • serviceVersion

      public Optional<String> serviceVersion()
      version of unified service tagging (resource service.version).
      Returns:
      the version, or empty
    • environment

      public Optional<String> environment()
      env of unified service tagging (resource deployment.environment.name).
      Returns:
      the environment, or empty
    • tags

      public Map<String,String> tags()
      Extra resource attributes (DD_TAGS).
      Returns:
      immutable map
    • apiKey

      public Optional<Secret> apiKey()
      Datadog API key (query API only).
      Returns:
      the key, or empty
    • appKey

      public Optional<Secret> appKey()
      Datadog application key with apm_read (query API only).
      Returns:
      the key, or empty
    • site

      public String site()
      Datadog site (default datadoghq.com).
      Returns:
      the site
    • apiUrl

      public String apiUrl()
      Query API base URL (default https://api.<site>).
      Returns:
      the URL
    • connectTimeout

      public Duration connectTimeout()
      Returns the connect timeout.
      Returns:
      the timeout
    • requestTimeout

      public Duration requestTimeout()
      Returns the per-attempt timeout.
      Returns:
      the timeout
    • totalTimeout

      public Duration totalTimeout()
      Returns the total timeout per call including retries.
      Returns:
      the timeout
    • retry

      public RetryPolicy retry()
      Returns the retry policy.
      Returns:
      the policy
    • tls

      public TlsOptions tls()
      Returns the TLS options.
      Returns:
      the options
    • proxy

      public Optional<String> proxy()
      Returns the explicit proxy URL.
      Returns:
      the proxy, or empty
    • headers

      public Map<String,String> headers()
      Returns the extra request headers.
      Returns:
      immutable map
    • userAgentSuffix

      public Optional<String> userAgentSuffix()
      Returns the user agent suffix.
      Returns:
      the suffix, or empty
    • hooks

      public Hooks hooks()
      Returns the hooks.
      Returns:
      the hooks
    • logger

      public Logger logger()
      Returns the logger.
      Returns:
      the logger
    • toString

      public String toString()
      Overrides:
      toString in class Object