Package codes.grow.packages.datadogapm
Class DatadogApmConfig
java.lang.Object
codes.grow.packages.datadogapm.DatadogApmConfig
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.
| Field | GROW_DATADOG_APM_* | Vendor variables |
|---|---|---|
| url | URL | DD_TRACE_AGENT_URL, else http://${DD_AGENT_HOST}:${DD_TRACE_AGENT_PORT} |
| otlpEndpoint | OTLP_HTTP_ENDPOINT / OTLP_GRPC_ENDPOINT (by protocol), OTLP_ENDPOINT | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_ENDPOINT |
| protocol | OTLP_PROTOCOL | OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, OTEL_EXPORTER_OTLP_PROTOCOL |
| serviceName | SERVICE | DD_SERVICE, OTEL_SERVICE_NAME |
| serviceVersion | VERSION | DD_VERSION |
| environment | ENV | DD_ENV |
| tags | TAGS | DD_TAGS (explicit tags are merged over them) |
| apiKey | API_KEY | DD_API_KEY |
| appKey | APP_KEY | DD_APP_KEY, DD_APPLICATION_KEY |
| site | SITE | DD_SITE |
| apiUrl | API_URL | - |
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault Agent trace intake port (servesGET /info).static final TracingConfig.ProtocolDefault OTLP protocol of this package.static final StringDefault Datadog Agent trace intake URL (health, ping and serverVersion use its /info).static final intDefault Agent OTLP/gRPC port.static final intDefault Agent OTLP/HTTP port. -
Method Summary
Modifier and TypeMethodDescriptionapiKey()Datadog API key (query API only).apiUrl()Query API base URL (defaulthttps://api.<site>).appKey()Datadog application key withapm_read(query API only).static DatadogApmConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the connect timeout.envof unified service tagging (resourcedeployment.environment.name).static DatadogApmConfigfromEnv()Reads the configuration from the process environment.static DatadogApmConfigReads the configuration from an explicit variable map (tests).booleanWhether both the API key and the application key are set (the query API is usable).headers()Returns the extra request headers.hooks()Returns the hooks.The credential values to redact from errors and logs.logger()Returns the logger.OTLP endpoint as configured (seeotlpTracesEndpoint()for the resolved URL).The resolved OTLP traces URL forprotocol()(seeotlpTracesUrl(codes.grow.packages.datadogapm.tracing.TracingConfig.Protocol, java.lang.String)):otlpEndpoint()when set, else the host ofurl()with port 4318 +/v1/traces(HTTP) or port 4317 (gRPC).static StringotlpTracesUrl(TracingConfig.Protocol protocol, String endpoint) The exporter URL for a protocol and an OTLP endpoint: forhttp/protobufan endpoint without a path gets/v1/traces; gRPC endpoints are used as they are.parseDatadogTags(String raw) Parses Datadog tags (DD_TAGS):key:valuepairs separated by commas and/or spaces.protocol()OTLP protocol (http/protobufby default, orgrpc).proxy()Returns the explicit proxy URL.Transport settings for the query API (apiUrl()).Returns the per-attempt timeout.retry()Returns the retry policy.serviceof unified service tagging (resourceservice.name).versionof unified service tagging (resourceservice.version).site()Datadog site (defaultdatadoghq.com).tags()Extra resource attributes (DD_TAGS).tls()Returns the TLS options.Returns a builder with these values.toString()Returns the total timeout per call including retries.Transport settings for the Agent (url()).url()Agent trace intake base URL (GET /info).Returns the user agent suffix.voidvalidate()Checks every field.
-
Field Details
-
OTLP_HTTP_PORT
public static final int OTLP_HTTP_PORTDefault Agent OTLP/HTTP port.- See Also:
-
OTLP_GRPC_PORT
public static final int OTLP_GRPC_PORTDefault Agent OTLP/gRPC port.- See Also:
-
AGENT_TRACE_PORT
public static final int AGENT_TRACE_PORTDefault Agent trace intake port (servesGET /info).- See Also:
-
DEFAULT_URL
Default Datadog Agent trace intake URL (health, ping and serverVersion use its /info).- See Also:
-
DEFAULT_PROTOCOL
Default OTLP protocol of this package.
-
-
Method Details
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new builder
-
toBuilder
Returns a builder with these values.- Returns:
- builder copy
-
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
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
parseDatadogTags
Parses Datadog tags (DD_TAGS):key:valuepairs 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
The exporter URL for a protocol and an OTLP endpoint: forhttp/protobufan endpoint without a path gets/v1/traces; gRPC endpoints are used as they are.- Parameters:
protocol- OTLP protocolendpoint- endpoint URL- Returns:
- the traces URL
-
otlpTracesEndpoint
The resolved OTLP traces URL forprotocol()(seeotlpTracesUrl(codes.grow.packages.datadogapm.tracing.TracingConfig.Protocol, java.lang.String)):otlpEndpoint()when set, else the host ofurl()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
DatadogSpansQuerycan be created
-
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
Transport settings for the Agent (url()).- Returns:
- the transport configuration
-
queryTransportConfig
Transport settings for the query API (apiUrl()).- Returns:
- the transport configuration
-
url
Agent trace intake base URL (GET /info).- Returns:
- the URL
-
otlpEndpoint
OTLP endpoint as configured (seeotlpTracesEndpoint()for the resolved URL).- Returns:
- the endpoint, or empty
-
protocol
OTLP protocol (http/protobufby default, orgrpc).- Returns:
- the protocol
-
serviceName
serviceof unified service tagging (resourceservice.name).- Returns:
- the service, or empty
-
serviceVersion
versionof unified service tagging (resourceservice.version).- Returns:
- the version, or empty
-
environment
envof unified service tagging (resourcedeployment.environment.name).- Returns:
- the environment, or empty
-
tags
Extra resource attributes (DD_TAGS).- Returns:
- immutable map
-
apiKey
Datadog API key (query API only).- Returns:
- the key, or empty
-
appKey
Datadog application key withapm_read(query API only).- Returns:
- the key, or empty
-
site
Datadog site (defaultdatadoghq.com).- Returns:
- the site
-
apiUrl
Query API base URL (defaulthttps://api.<site>).- Returns:
- the URL
-
connectTimeout
Returns the connect timeout.- Returns:
- the timeout
-
requestTimeout
Returns the per-attempt timeout.- Returns:
- the timeout
-
totalTimeout
Returns the total timeout per call including retries.- Returns:
- the timeout
-
retry
Returns the retry policy.- Returns:
- the policy
-
tls
Returns the TLS options.- Returns:
- the options
-
proxy
Returns the explicit proxy URL.- Returns:
- the proxy, or empty
-
headers
Returns the extra request headers.- Returns:
- immutable map
-
userAgentSuffix
Returns the user agent suffix.- Returns:
- the suffix, or empty
-
hooks
Returns the hooks.- Returns:
- the hooks
-
logger
Returns the logger.- Returns:
- the logger
-
toString
-