feat(internal/log,telemetry): add SDK error-reporting API for Error Tracking#4997
feat(internal/log,telemetry): add SDK error-reporting API for Error Tracking#4997darccio wants to merge 2 commits into
Conversation
…racking Introduce a centralized, PII-safe pipeline that forwards SDK-originated errors from `internal/log.Error` to instrumentation telemetry (→ Error Tracking) without changing existing local log output. ## What changed **Auto-forward sink** (`internal/log/log.go`): - `SetErrorTelemetrySink(f)` installs a forwarding hook; called before the local aggregation lock so telemetry is notified on every non-rate-limited `Error` call. - `atomic.Pointer` ensures lock-free concurrent access. **Sink registration** (`internal/telemetry/log/forward.go`): - `init()` registers `forwardError` with `log.SetErrorTelemetrySink`. - Uses the raw format string as the constant telemetry message (never interpolated); type-switches args to attach only `error` values, each scrubbed through `NewSafeError`. - Always attaches a redacted stacktrace via `WithStacktrace()`. **Policy table** (`internal/telemetry/log/policy.go`): - Single source of truth for per-template actions: `report` (default), `downgrade` (→ warn), or `exclude`. - Pre-seeded with agent-connectivity and user-misconfiguration templates. **Explicit helpers** (`internal/telemetry/log/helpers.go`): - `ReportError(msg, err, opts...)` — for swallowed-error branches. - `ReportPanic(recovered, msg)` — for `recover()` sites. - Both enforce the constant-message contract and policy table. **`constantlogmsg` analyzer** (`internal/telemetry/log/analyzer/`): - `go/analysis` pass that rejects non-constant first arguments on `log.Error`, `log.Warn`, `ReportError`, and `ReportPanic`. - Standalone `cmd/main.go` runnable as `go vet -vettool`. - Makefile target `make lint/errlog`. **`MIGRATION-CONTRACT.md`**: canonical before/after for each of the five call-site patterns Prompt 2 (automated migration) will encounter. No existing log output is changed. No import cycle is introduced. All tests pass under `-race`.
| var policyTable = map[string]policyAction{ | ||
| // ── Agent / network connectivity ──────────────────────────────────────── | ||
| // These reflect user environment issues, not SDK bugs. | ||
| "failure sending traces (attempt %d of %d): %v": policyExclude, |
There was a problem hiding this comment.
🚫 [golangci] reported by reviewdog 🐶
File is not properly formatted (gofmt)
|
BenchmarksBenchmark execution time: 2026-07-09 15:54:50 Comparing candidate commit a9d8023 in PR branch Found 5 performance improvements and 0 performance regressions! Performance is the same for 321 metrics, 0 unstable metrics, 1 flaky benchmarks without significant changes.
|
|
We should remove these files and make the new analyzer includes the functionality https://github.com/DataDog/dd-trace-go/blob/main/rules/telemetry_rules.go and https://github.com/DataDog/dd-trace-go/blob/main/rules/logging_rules.go |
… telemetrylog.{Debug,Warn,Error}
Extends DefaultFuncs to check all three telemetry log functions (and their
Logger method counterparts) in addition to the existing ReportError/ReportPanic
helpers. A single FuncSpec per name covers both call styles because resolveFunc
maps both pkg-level and method calls to the same (pkgPath, name) key via the
type checker.
Adds a skipPkgs mechanism (DefaultSkipPkgs, New variadic param) so the analyzer
does not flag the internal/telemetry/log package's own delegation calls — e.g.
func Error(message string,...){ defaultLogger.Load().Error(message,...) }.
Adds TestAnalyzerSkip to verify that listed packages are silently ignored even
when they contain variable-message calls.
This brings constantlogmsg to feature parity with the telemetryLogConstantMessage
ruleguard rule in rules/telemetry_rules.go, making it possible to drop that rule
once this analyzer is wired into all CI paths.
Summary
internal/log.Errorso every non-rate-limited call is mirrored to instrumentation telemetry. The format string is the constant dedup key; variadicerrorargs are scrubbed viaNewSafeError; a redacted stack trace is always attached. No change to local log output.internal/telemetry/log/policy.go): single place to classify format templates asreport/downgrade(→ warn) /exclude. Pre-seeded with agent-connectivity and user-misconfiguration noise.internal/telemetry/log/helpers.go):ReportError(msg, err, opts...)for swallowed errors;ReportPanic(recovered, msg)forrecover()sites. Both enforce the constant-message contract.constantlogmsganalyzer (internal/telemetry/log/analyzer/):go vet-compatible pass that rejects non-constant message arguments. Standalone binary forgo vet -vettool;make lint/errlogtarget added.Test plan
go build ./...— no compile errorsgo vet ./internal/log/... ./internal/telemetry/log/...— cleango test ./internal/log/... ./internal/telemetry/log/... -count=1 -race— all green (17 new tests)make lint/errlog— no violations in existing codebaseinternal/logdoes not importinternal/telemetry/log)TestErrorLocalOutputUnchanged)Reviewer notes
init()inforward.go; it is active whenever any code importsinternal/telemetry/log. Existing uses oflog.Errorrequire no changes — the auto-forward handles them. Non-constant first arguments will be flagged by the new analyzer.policyTableinpolicy.gois intentionally sparse. Prompt 2 (migration) will populate it as call sites are classified.internalimport restriction) and aNew([]FuncSpec)constructor for test-scoped configuration.Related epic: APMLP-1503