Skip to content

feat(telemetry): implement secure telemetry logging with PII protection#3948

Merged
dd-mergequeue[bot] merged 17 commits into
DataDog:mainfrom
kakkoyun:kakkoyun/LANGPLAT-767/improve_telemtery_error_logs
Sep 17, 2025
Merged

feat(telemetry): implement secure telemetry logging with PII protection#3948
dd-mergequeue[bot] merged 17 commits into
DataDog:mainfrom
kakkoyun:kakkoyun/LANGPLAT-767/improve_telemtery_error_logs

Conversation

@kakkoyun

@kakkoyun kakkoyun commented Sep 5, 2025

Copy link
Copy Markdown
Member

Eliminate PII leakage in telemetry data sent to external services by enforcing
strict security controls on telemetry logging with comprehensive static analysis.

Redesigned telemetry Error API to require constant messages only, implemented
SafeError with automatic stack trace redaction, and created mission-critical
static checker rules with bulletproof scoping.

  • Messages: Constant templates only (no dynamic strings/format verbs)
  • Stack traces: Customer code frames replaced with "REDACTED" placeholder
  • Error details: Only error type exposed, never error messages
  • Collections: SafeSlice with explicit type conversions (no %v formatting)
  • Static enforcement: Comprehensive ruleguard rules prevent all violations

SafeError extracts error types and redacts customer stack frames using contrib/
directory for frame classification. API breaking change from telemetrylog.Error(err)

to Error("message", SafeError(err)) ensures constant messages with secure error
details.

Signed-off-by: Kemal Akkoyun [email protected]

What does this PR do?

Motivation

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running ./scripts/lint.sh locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@kakkoyun
kakkoyun marked this pull request as ready for review September 5, 2025 19:56
@kakkoyun
kakkoyun requested review from a team as code owners September 5, 2025 19:56
@kakkoyun
kakkoyun force-pushed the kakkoyun/LANGPLAT-767/improve_telemtery_error_logs branch from b572220 to 38893c1 Compare September 5, 2025 20:20

@bouwkast bouwkast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this looks great thanks a bunch @kakkoyun
I think this will do it, I don't see anything that stands out.

I wasn't actually aware of WithTags being a thing, but they appear fine to me, I would like to follow up on that outside of this PR with the ASM team (I think they implemented it) to just figure out what the expectations are for that.

(don't take this as a go review 😛)

}

func logLocalDiagnosticMessages(name string, feature *libddwaf.Feature) {
logger := telemetryLog.With(telemetry.WithTags([]string{"appsec_config_key:" + name, "log_type:local::diagnostic"}))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my understanding is that the WithTags is something that ASM designed / built into the telemetry logs.

I am actually not very familiar with them, but so far I think they are okay, they fall out of the message (I think) so hopefully they don't impact our deduplication logic.

I'll plan on following up on these though to find out more about how they work - it seems that ASM pushed for this and relies on it entirely as some of their logs don't get sent anywhere else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding clarification here -- the log tags are part of the instrumentation telemetry v2 specification. They are directly sent as tag=value to logs-backend instead of having to avoid having to apply grok parsing backend-side. we are the first to use it in dd-trace-go bc the actual implementation of it is fairly recent but it is fairly used in APM Onboarding even back from an RFC from 2022

Comment thread internal/telemetry/log/log.go
Comment thread internal/telemetry/log/safe.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is a great addition!

Comment thread rules/telemetry_rules.go

//go:build ruleguard

// Package gorules contains security-focused telemetry logging rules for dd-trace-go.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and an analyzer very nice 🚀 🎉

Comment thread internal/telemetry/log/log.go Outdated

@eliottness eliottness left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work but I believe this something missing in the way this will work. You see with the WithStacktrace option, the actual stacktrace is taken after we know this was a new log message which limits the number of total stacktraces per minute by a lot if a same error happens in every customer http requests.

Side note. With this you can basically delete telemetry.WithStacktrace that would make not-redacted stacktraces and replace it with some lazy computing that would call your stacktrace code only when this is a new log message

Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go
}

func logLocalDiagnosticMessages(name string, feature *libddwaf.Feature) {
logger := telemetryLog.With(telemetry.WithTags([]string{"appsec_config_key:" + name, "log_type:local::diagnostic"}))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding clarification here -- the log tags are part of the instrumentation telemetry v2 specification. They are directly sent as tag=value to logs-backend instead of having to avoid having to apply grok parsing backend-side. we are the first to use it in dd-trace-go bc the actual implementation of it is fairly recent but it is fairly used in APM Onboarding even back from an RFC from 2022

Comment thread internal/appsec/emitter/waf/metrics.go
Comment thread internal/telemetry/log/safe.go Outdated
Comment thread internal/telemetry/log/safe.go Outdated

Copy link
Copy Markdown
Contributor

Another side note: You may want to put back a logger in the instrumentation.Instrumentation struct because we cannot do telemetry logging in contribs right now (which is was this PR was supposed to cover I believe)

Comment thread internal/appsec/listener/waf/waf.go Outdated
@kakkoyun
kakkoyun requested review from a team as code owners September 9, 2025 10:51
@kakkoyun
kakkoyun requested a review from liashenko September 9, 2025 10:51
@kakkoyun
kakkoyun force-pushed the kakkoyun/LANGPLAT-767/improve_telemtery_error_logs branch from ff73471 to 0e0f6dd Compare September 10, 2025 12:35
@kakkoyun
kakkoyun marked this pull request as draft September 10, 2025 12:35
@kakkoyun
kakkoyun force-pushed the kakkoyun/LANGPLAT-767/improve_telemtery_error_logs branch from c78168c to 204c621 Compare September 10, 2025 18:45
@kakkoyun
kakkoyun marked this pull request as ready for review September 10, 2025 18:45
@kakkoyun
kakkoyun marked this pull request as draft September 11, 2025 05:57
@kakkoyun
kakkoyun force-pushed the kakkoyun/LANGPLAT-767/improve_telemtery_error_logs branch from a8be574 to f90ba6d Compare September 11, 2025 10:26
@kakkoyun
kakkoyun marked this pull request as ready for review September 11, 2025 10:26
@kakkoyun
kakkoyun requested a review from Copilot September 11, 2025 10:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements secure telemetry logging with comprehensive PII protection for the Datadog Go tracer. The telemetry system now enforces strict security controls through constant-only messages, automatic stack trace redaction, and a new SafeError API that prevents sensitive data exposure in telemetry sent to external services.

  • Redesigned telemetry Error API to require constant messages with structured slog.Attr parameters
  • Implemented SafeError with automatic stack trace redaction for customer code frames
  • Created comprehensive static checker rules to prevent all telemetry security violations

Reviewed Changes

Copilot reviewed 40 out of 42 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scripts/gencontribs/ New code generation tool for extracting third-party libraries from contrib/ structure
rules/telemetry_rules.go Comprehensive ruleguard rules enforcing telemetry security policies
rules/logging_rules.go Updated logging rules removing telemetry-specific constraints
internal/telemetry/log/ Complete redesign with secure Logger API using constant messages and SafeError
internal/telemetry/backend.go New telemetry backend with stack trace redaction and message formatting
internal/stacktrace/ Enhanced with customer code redaction, raw capture, and third-party library detection
Multiple appsec files Migration to new secure telemetry logging API throughout codebase

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/telemetry/log/safe.go
Comment thread internal/stacktrace/stacktrace.go
Comment thread internal/stacktrace/stacktrace.go
@kakkoyun

Copy link
Copy Markdown
Member Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Sep 17, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-09-17 08:09:52 UTC ℹ️ Start processing command /merge


2025-09-17 08:09:58 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 16m (p90).


2025-09-17 08:26:58 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit b143198:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

// prefixTrie is a thread-safe trie data structure optimized for prefix matching.
// It's designed for high-performance concurrent read operations with occasional writes.
//
// Memory vs Performance Trade-offs:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this section, the explanation, and the implementation

Awesome work!

@kakkoyun

Copy link
Copy Markdown
Member Author

/merge

@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Sep 17, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-09-17 09:09:59 UTC ℹ️ Start processing command /merge


2025-09-17 09:10:05 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 16m (p90).


2025-09-17 09:34:30 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue
dd-mergequeue Bot merged commit 0644b52 into DataDog:main Sep 17, 2025
152 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants