Redaction¶
Credentials never leave the SDK in readable form: not in error messages, hook data, logger output,
toString/debug/JSON forms of configs and secret values. Redaction replaces values with
[REDACTED].
Rules¶
- Sensitive headers (case-insensitive):
authorization,proxy-authorization,cookie,set-cookie, and any name containingtoken,secret,password,api-key,apikey,key,auth,session,signatureorcredential. - Sensitive fields and query parameters (case-insensitive substring):
password,passwd,secret,token,authorization,cookie,api_key,apikey,api-key,access_key,private_key,client_secret,credential,session,signature. - Known secrets: every error message passes through
redactTextwith the secret values the client knows (token, passwords from the config, …); any occurrence of length ≥ 4 is replaced. - Vendor error text is redacted and truncated to 300 characters.
The Secret type¶
Credentials in configuration are wrapped in Secret. Its string, debug and JSON forms print
[REDACTED]; reveal() returns the value when you really need it.
Redaction helpers¶
The helpers are public so your own code (logs, hooks, error reports) can apply the same rules.
| Function | What it does |
|---|---|
redactHeaders(headers) |
copy with sensitive header values replaced |
redactUrl(url) |
URL with sensitive query values replaced (and user info removed) |
redactFields(map, extraKeys?) |
recursive copy of nested maps/lists with sensitive keys replaced |
redactText(text, knownSecrets) |
replaces every known secret value (length ≥ 4) |
import { redactFields, redactHeaders, redactText, redactUrl } from "@grow-codes/datadog-apm";
redactHeaders({ Authorization: "Bearer abc", Accept: "application/json" });
// { authorization: "[REDACTED]", accept: "application/json" }
redactUrl("https://api.example.com/v1?token=abc&page=2");
// "https://api.example.com/v1?token=[REDACTED]&page=2"
redactFields({ user: "ana", password: "x", nested: { apiKey: "y" } });
redactText("login failed for s3cr3t-value", ["s3cr3t-value"]);
// "login failed for [REDACTED]"
use grow_datadog_apm::core::redact::{redact_fields, redact_headers, redact_text, redact_url};
let headers = redact_headers([("Authorization", "Bearer abc"), ("Accept", "application/json")]);
let url = redact_url("https://api.example.com/v1?token=abc&page=2");
let fields = redact_fields(&serde_json::json!({"password": "x", "nested": {"apiKey": "y"}}), &[]);
let text = redact_text("login failed for s3cr3t-value", &["s3cr3t-value"]);
h := datadogapm.RedactHeaderMap(map[string]string{"Authorization": "Bearer abc"})
u := datadogapm.RedactURL("https://api.example.com/v1?token=abc&page=2")
f := datadogapm.RedactFields(map[string]any{"password": "x", "nested": map[string]any{"apiKey": "y"}})
t := datadogapm.RedactText("login failed for s3cr3t-value", []string{"s3cr3t-value"})
// RedactHeaders(http.Header) works on net/http headers.
from grow_datadog_apm import redact_fields, redact_headers, redact_text, redact_url
redact_headers({"Authorization": "Bearer abc", "Accept": "application/json"})
redact_url("https://api.example.com/v1?token=abc&page=2")
redact_fields({"password": "x", "nested": {"apiKey": "y"}})
redact_text("login failed for s3cr3t-value", ["s3cr3t-value"])
import codes.grow.packages.datadogapm.core.Redaction;
Redaction.redactHeaders(Map.of("Authorization", "Bearer abc"));
Redaction.redactUrl("https://api.example.com/v1?token=abc&page=2");
Redaction.redactFields(Map.of("password", "x", "nested", Map.of("apiKey", "y")));
Redaction.redactText("login failed for s3cr3t-value", List.of("s3cr3t-value"));
Logs
Do not log revealed secrets yourself: the SDK can only redact values it knows about.