Skip to content

contrib/log/slog: avoid logging 0 value trace/span IDs#2994

Merged
darccio merged 2 commits into
DataDog:mainfrom
rliebz:slog-no-zero-ids
Jan 22, 2025
Merged

contrib/log/slog: avoid logging 0 value trace/span IDs#2994
darccio merged 2 commits into
DataDog:mainfrom
rliebz:slog-no-zero-ids

Conversation

@rliebz

@rliebz rliebz commented Nov 26, 2024

Copy link
Copy Markdown
Contributor

If the tracer is started but explicitly deactivated, there will be a span on the context, but the span ID and trace ID will be set to 0. Adding this information to log outputs seems like unintentional noise (although it's certainly possible there's a use case I'm not aware of), so I figured disabling it would be preferred.

The change to explicitly add tracer.WithTraceEnabled(true) was so that the test would be resilient to folks who might have DD_TRACE_ENABLED set explicitly, which is true on my machine.

What does this PR do?

Removes dd.trace_id=0 and dd.span_id=0 values from logs when the tracer is disabled.

Motivation

I was actually using a closed-source implementation of a log/slog handler from before this package was available. I swapped this version into our test suite to compare behavior, and figured this was probably something that could be upstreamed.

It's unclear to me that there would be value in including these zero values in the logs.

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.
  • 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!

@rliebz
rliebz requested review from a team as code owners November 26, 2024 20:24

@rarguelloF rarguelloF 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.

LGTM, thanks for the contribution! @rliebz

If the tracer is started but explicitly deactivated, there will be a
span on the context, but the span ID and trace ID will be set to 0.
Adding this information to log outputs seems like unintentional noise
(although it's certainly possible there's a use case I'm not aware of),
so I figured disabling it would be preferred.

The change to explicitly add `tracer.WithTraceEnabled(true)` was so that
the test would be resilient to folks who might have `DD_TRACE_ENABLED`
set explicitly, which is true on my machine.
@rliebz

rliebz commented Jan 21, 2025

Copy link
Copy Markdown
Contributor Author

Test conflicts resolved, should be good to go

@darccio
darccio merged commit 753f98c into DataDog:main Jan 22, 2025
@rliebz
rliebz deleted the slog-no-zero-ids branch February 3, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants