Skip to content

Configuration

DatadogApmConfig holds every setting of a client. It is immutable after construction, validated when it is built (invalid values raise a CONFIG error) and its string/debug form redacts every credential. The settings of Datadog APM itself (endpoint, credentials and other service fields) are listed under Service settings; the settings every Grow Codes SDK shares follow under Common settings.

Service settings

Setting Default Environment variables (precedence order)
url — Agent trace intake (/info for health, ping, serverVersion) http://127.0.0.1:8126 GROW_DATADOG_APM_URL, DD_TRACE_AGENT_URL, http://${DD_AGENT_HOST}:${DD_TRACE_AGENT_PORT}
otlpEndpoint — Agent OTLP receiver host of url + :4318 (HTTP, /v1/traces appended) / :4317 (gRPC) GROW_DATADOG_APM_OTLP_HTTP_ENDPOINT / GROW_DATADOG_APM_OTLP_GRPC_ENDPOINT (by protocol), GROW_DATADOG_APM_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_ENDPOINT
protocol — OTLP protocol http/protobuf GROW_DATADOG_APM_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, OTEL_EXPORTER_OTLP_PROTOCOL
serviceName — Datadog service none (required by initTracing) GROW_DATADOG_APM_SERVICE, DD_SERVICE, OTEL_SERVICE_NAME
serviceVersion — Datadog version none GROW_DATADOG_APM_VERSION, DD_VERSION
environment — Datadog env none GROW_DATADOG_APM_ENV, DD_ENV
tags — extra resource attributes (key:value, comma or space separated) none GROW_DATADOG_APM_TAGS, DD_TAGS
apiKey — API key, query API only (secret) none GROW_DATADOG_APM_API_KEY, DD_API_KEY
appKey — application key with apm_read, query API only (secret) none GROW_DATADOG_APM_APP_KEY, DD_APP_KEY, DD_APPLICATION_KEY
site — Datadog site datadoghq.com GROW_DATADOG_APM_SITE, DD_SITE
apiUrl — query API base URL https://api.<site> GROW_DATADOG_APM_API_URL

The Agent needs no credentials (it holds DD_API_KEY itself); apiKey and appKey are needed only by DatadogSpansQuery and are always redacted. More on each function is on the Functions page.

Common settings

Setting Default Environment variable
connectTimeout — connection setup 10 s GROW_DATADOG_APM_CONNECT_TIMEOUT
requestTimeout — per attempt (headers + body) 30 s GROW_DATADOG_APM_REQUEST_TIMEOUT
totalTimeout — whole call incl. retries and backoff 120 s GROW_DATADOG_APM_TOTAL_TIMEOUT
retry — retry policy (below) 3 retries GROW_DATADOG_APM_MAX_RETRIES
tls.caCertPath / tls.caCertPem — extra CA none GROW_DATADOG_APM_CA_CERT (path)
tls.clientCertPath + tls.clientKeyPath — mutual TLS none GROW_DATADOG_APM_CLIENT_CERT, GROW_DATADOG_APM_CLIENT_KEY
tls.insecureSkipVerify — tests only, logs a warning once false GROW_DATADOG_APM_INSECURE_SKIP_VERIFY
proxy — proxy URL none (environment proxies are ignored) GROW_DATADOG_APM_PROXY
headers — extra request headers {} —
userAgentSuffix — appended to the User-Agent none —
hooks — request/response callbacks (Hooks) none —
logger — diagnostic logger (Hooks) silent —

Every request sends User-Agent: grow-codes-datadog-apm/<version> (<language>).

From the environment

fromEnv resolves each setting with this precedence:

  1. the value passed in code (overrides),
  2. GROW_DATADOG_APM_<NAME>,
  3. the vendor variables of Datadog APM (see Functions), in their documented order,
  4. the default.

Parsing rules:

  • Durations accept integer milliseconds (1500) or Go-style units: 500ms, 10s, 2m, 1h, combinations such as 1m30s.
  • Booleans accept true/false, 1/0, yes/no, on/off (any case).
  • An empty variable counts as unset.
  • A present but invalid value raises a CONFIG error that names the variable, never its value.
import { DatadogApmClient, DatadogApmConfig } from "@grow-codes/datadog-apm";

// Environment only
const client = DatadogApmClient.fromEnv();

// Environment with explicit overrides (explicit values win)
const config = DatadogApmConfig.fromEnv({ requestTimeoutMs: 5_000 });

// Everything in code
const explicit = new DatadogApmConfig({
  url: "http://datadog-agent.internal:8126",
  serviceName: "checkout",
  environment: "prod",
  apiKey: process.env.DD_API_KEY,
  appKey: process.env.DD_APP_KEY,
  site: "datadoghq.eu",
  connectTimeoutMs: 5_000,
  requestTimeoutMs: 15_000,
  totalTimeoutMs: 60_000,
  retry: { maxRetries: 5, initialBackoffMs: 200 },
  tls: { caCertPath: "/etc/ssl/internal-ca.pem" },
  proxy: "http://proxy.internal:3128",
  headers: { "x-team": "payments" },
  userAgentSuffix: "my-app/1.4",
});
const custom = new DatadogApmClient(explicit);
console.log(String(explicit)); // apiKey and appKey shown as [REDACTED]
use std::time::Duration;
use grow_datadog_apm::{DatadogApmClient, DatadogApmConfig, RetryPolicy};

// Environment only
let client = DatadogApmClient::from_env()?;

// Environment with explicit overrides (explicit values win)
let config = DatadogApmConfig::builder()
    .request_timeout(Duration::from_secs(5))
    .build_from_env()?;

// Everything in code
let explicit = DatadogApmConfig::builder()
    .url("http://datadog-agent.internal:8126")
    .service_name("checkout")
    .environment("prod")
    .api_key(std::env::var("DD_API_KEY").unwrap_or_default())
    .app_key(std::env::var("DD_APP_KEY").unwrap_or_default())
    .site("datadoghq.eu")
    .connect_timeout(Duration::from_secs(5))
    .request_timeout(Duration::from_secs(15))
    .total_timeout(Duration::from_secs(60))
    .retry(RetryPolicy::default().with_max_retries(5))
    .ca_cert_path("/etc/ssl/internal-ca.pem")
    .proxy("http://proxy.internal:3128")
    .header("x-team", "payments")
    .user_agent_suffix("my-app/1.4")
    .build()?;
let custom = DatadogApmClient::new(explicit)?;
println!("{:?}", custom.config()); // api_key and app_key shown as [REDACTED]
// Environment only
client, err := datadogapm.NewClientFromEnv()

// Everything in code: zero values mean "use the default"
cfg := datadogapm.Config{
    CommonConfig: datadogapm.CommonConfig{
        URL:             "http://datadog-agent.internal:8126",
        ConnectTimeout:  5 * time.Second,
        RequestTimeout:  15 * time.Second,
        TotalTimeout:    time.Minute,
        Retry:           &datadogapm.RetryPolicy{MaxRetries: 5, InitialBackoff: 200 * time.Millisecond},
        TLS:             datadogapm.TLSConfig{CACertPath: "/etc/ssl/internal-ca.pem"},
        Proxy:           "http://proxy.internal:3128",
        Headers:         map[string]string{"x-team": "payments"},
        UserAgentSuffix: "my-app/1.4",
    },
    ServiceName: "checkout",
    Environment: "prod",
    APIKey:      datadogapm.NewSecret(os.Getenv("DD_API_KEY")),
    AppKey:      datadogapm.NewSecret(os.Getenv("DD_APP_KEY")),
    Site:        "datadoghq.eu",
}
if err := cfg.Validate(); err != nil {
    log.Fatal(err) // errors.Is(err, datadogapm.ErrConfig)
}
custom, err := datadogapm.NewClient(cfg)

// Environment with explicit overrides (explicit values win; nil env = process environment)
merged, err := datadogapm.ConfigFromEnvWith(datadogapm.Config{
    CommonConfig: datadogapm.CommonConfig{RequestTimeout: 5 * time.Second},
}, nil)
fmt.Println(merged) // APIKey and AppKey shown as [REDACTED]
import os
from grow_datadog_apm import RetryPolicy, TlsConfig, DatadogApmClient, DatadogApmConfig

# Environment only
client = DatadogApmClient.from_env()

# Environment with explicit overrides (explicit values win)
config = DatadogApmConfig.from_env(request_timeout=5.0)

# Everything in code: durations are float seconds (datetime.timedelta also works)
explicit = DatadogApmConfig(
    url="http://datadog-agent.internal:8126",
    service_name="checkout",
    environment="prod",
    api_key=os.environ.get("DD_API_KEY"),
    app_key=os.environ.get("DD_APP_KEY"),
    site="datadoghq.eu",
    connect_timeout=5.0,
    request_timeout=15.0,
    total_timeout=60.0,
    retry=RetryPolicy(max_retries=5, initial_backoff=0.2),
    tls=TlsConfig(ca_cert_path="/etc/ssl/internal-ca.pem"),
    proxy="http://proxy.internal:3128",
    headers={"x-team": "payments"},
    user_agent_suffix="my-app/1.4",
)
custom = DatadogApmClient(explicit)
print(repr(explicit))  # api_key and app_key shown as [REDACTED]
import java.time.Duration;
import codes.grow.packages.datadogapm.DatadogApmClient;
import codes.grow.packages.datadogapm.DatadogApmConfig;
import codes.grow.packages.datadogapm.core.RetryPolicy;

// Environment only
DatadogApmClient client = DatadogApmClient.fromEnv();

// Everything in code
DatadogApmConfig config = DatadogApmConfig.builder()
    .url("http://datadog-agent.internal:8126")
    .serviceName("checkout")
    .environment("prod")
    .apiKey(System.getenv("DD_API_KEY"))
    .appKey(System.getenv("DD_APP_KEY"))
    .site("datadoghq.eu")
    .connectTimeout(Duration.ofSeconds(5))
    .requestTimeout(Duration.ofSeconds(15))
    .totalTimeout(Duration.ofMinutes(1))
    .retry(RetryPolicy.builder().maxRetries(5).initialBackoff(Duration.ofMillis(200)).build())
    .proxy("http://proxy.internal:3128")
    .header("x-team", "payments")
    .userAgentSuffix("my-app/1.4")
    .build();
DatadogApmClient custom = DatadogApmClient.create(config);
System.out.println(config); // apiKey and appKey shown as [REDACTED]

Retry policy

Field Default Meaning
maxRetries 3 retries after the first attempt (so up to 4 attempts)
initialBackoff 100 ms backoff cap of the first retry
maxBackoff 10 s cap of every backoff
multiplier 2 growth of the cap per retry
maxRetryAfter 60 s longest server-requested Retry-After the client waits for

Backoff for retry n (0-based) is full jitter: a random wait between 0 and min(maxBackoff, initialBackoff × multiplier^n).

Requests are retried on HTTP 429, 408, 502, 503, 504 and on network errors. Idempotent requests (GET HEAD OPTIONS PUT DELETE, or marked idempotent) are also retried on HTTP 500. Other requests (for example POST) are retried only on 429 and on connection errors that happened before the request was sent, never after an uncertain send.

On 429 and 503 the client honours Retry-After (seconds or HTTP date) and waits max(retryAfter, backoff). When that wait exceeds maxRetryAfter or the remaining totalTimeout, it stops at once with RATE_LIMITED/UNAVAILABLE and sets retryAfter on the error. Set maxRetries to 0 to turn retries off.

Timeouts and cancellation

  • connectTimeout bounds connection setup, requestTimeout each attempt, totalTimeout the whole call including backoff sleeps. An exhausted timeout raises TIMEOUT.
  • Cancellation is honoured during requests and backoff sleeps and raises CANCELLED: TypeScript { signal } (AbortSignal), Rust dropping the future, Go ctx, Python cancel= (CancelToken) or task cancellation, Java …Async futures (cancel(true)).

TLS and proxies

  • Add a private CA with tls.caCertPath (or the PEM text in tls.caCertPem).
  • Mutual TLS needs tls.clientCertPath and tls.clientKeyPath together.
  • tls.insecureSkipVerify disables certificate checks. Use it for local tests only; the client logs a warning once.
  • HTTP_PROXY/HTTPS_PROXY are ignored so that credentials never leave through an unexpected proxy. Set proxy (or GROW_DATADOG_APM_PROXY) to use one.