Skip to content

feat(contrib/zap): add log/trace correlation for uber-go/zap#4610

Closed
highlyavailable wants to merge 15 commits into
DataDog:mainfrom
highlyavailable:feat/contrib-zap-log-correlation
Closed

feat(contrib/zap): add log/trace correlation for uber-go/zap#4610
highlyavailable wants to merge 15 commits into
DataDog:mainfrom
highlyavailable:feat/contrib-zap-log-correlation

Conversation

@highlyavailable

@highlyavailable highlyavailable commented Mar 27, 2026

Copy link
Copy Markdown

What does this PR do?

Adds a new contrib package at contrib/go.uber.org/zap that provides log/trace correlation for uber-go/zap. Just the single helper TraceFields(ctx context.Context) []zap.Field which pulls DD trace and span IDs from the context and returns them as zap fields.

Usage:

logger.Info("completed request", ddzap.TraceFields(ctx)...)

Zap's zapcore.Core.Write() doesn't take context.Context, wrapping the core didn't seem like an option, but I am happy to get your feedback if you can think of a better implementation.

I added support for both 128-bit and 64-bit trace ID formats via DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED.

Motivation

go.uber.org/zap is one of the most widely used structured loggers in Go and there's currently no Datadog logging integration for it. This closes that gap, following the same patterns used by the existing zerolog and logrus contribs.

@highlyavailable
highlyavailable requested review from a team as code owners March 27, 2026 02:22
@darccio

darccio commented Mar 27, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@darccio

darccio commented Mar 27, 2026

Copy link
Copy Markdown
Member

@highlyavailable Thanks for contributing it! It'd be great if you can add an orchestrion.yml definition file to allow you to use Orchestrion too. If it's too much, we can take care of that.

@codecov

codecov Bot commented Mar 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.50%. Comparing base (3b88d5b) to head (308415e).

Additional details and impacted files
Files with missing lines Coverage Δ
ddtrace/tracer/option.go 84.96% <ø> (-2.18%) ⬇️
instrumentation/packages.go 7.81% <ø> (-1.57%) ⬇️

... and 279 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@darccio

darccio commented Mar 27, 2026

Copy link
Copy Markdown
Member

@highlyavailable Check the CI checks, as there are some failing.

@highlyavailable
highlyavailable requested a review from a team as a code owner March 27, 2026 13:48
highlyavailable and others added 4 commits March 27, 2026 07:56
Add PackageGoUberOrgZap constant and PackageInfo entry to prepare
for the upcoming uber-go/zap logging contrib integration.
Add contrib/go.uber.org/zap with a TraceFields helper that extracts
Datadog trace and span IDs from context and returns them as zap fields.
Supports both 128-bit and 64-bit trace ID formats.

Usage: logger.Info("msg", ddzap.TraceFields(ctx)...)
Add go.uber.org/zap to the contribIntegrations map in tracer/option.go
so it shows up in startup diagnostics. Also add the package to
supported_integrations.md and update go.work.sum.
Adds an orchestrion.yml that marks go.uber.org/zap as imported when
Orchestrion auto-instrumentation is active. Full automatic context
injection isn't possible since zap's zapcore.Core.Write() doesn't
accept context.Context, but integration discovery is handled.
@highlyavailable
highlyavailable force-pushed the feat/contrib-zap-log-correlation branch from 9895fa7 to 6a25ead Compare March 27, 2026 13:56
@highlyavailable

highlyavailable commented Mar 27, 2026

Copy link
Copy Markdown
Author

@highlyavailable Thanks for contributing it! It'd be great if you can add an orchestrion.yml definition file to allow you to use Orchestrion too. If it's too much, we can take care of that.

Hi @darccio, I added a commit with an orchestrion.yml file. I tried to follow other examples in the repo.

@highlyavailable Check the CI checks, as there are some failing.

Made some updates for the failing CI checks, waiting on the approval now 👍

@darccio

darccio commented Mar 27, 2026

Copy link
Copy Markdown
Member

@highlyavailable Thanks. I'll let @DataDog/apm-idm-go to discuss the implementation design.

About the orchestrion.yml, I think we need to investigate a bit more, because your implementation requires targeting the arguments of any logging method - like Info - and prepending TraceFields(ctx) and the ctx value should be captured from the function or introduced by a //dd:span directive on the function.

@darccio

darccio commented Mar 27, 2026

Copy link
Copy Markdown
Member

BTW, we had another implementation in progress #4241 cc @quinna-h

Was failing CI jobs, after reading through their logs I think I need to set the integration count (56 → 57) and register
DD_TRACE_ZAP_ANALYTICS_ENABLED as a supported config
@highlyavailable
highlyavailable requested a review from a team as a code owner April 6, 2026 00:26
@highlyavailable

Copy link
Copy Markdown
Author

Hi @darccio. Just pushed an update to tests and config which should take care of the failing CI.

For orchestrion.yml, what’s in there right now is just wiring up integration telemetry. I wasn’t really sure about the best way to handle actual trace injection given zap’s constraints, so would really appreciate any guidance on how you (or others) all think that should be done.

Also saw the overlap with #4241, main difference is I went with TraceFields(ctx) []zap.Field returning raw fields instead of wrapping the logger, since that felt more in line with how zap is usually used (IME). I left out the WrapCore wrapper for now since it wasn’t doing anything yet.

That said, I’m very open to aligning with #4241 or reshaping the API if you have a preferred direction, happy to adjust and thank you for the feedback so far

@darccio

darccio commented Apr 14, 2026

Copy link
Copy Markdown
Member

@highlyavailable I'll check this again soon.

@highlyavailable highlyavailable changed the title contrib(zap): add log/trace correlation for uber-go/zap feat(contrib/zap): add log/trace correlation for uber-go/zap Apr 16, 2026
@highlyavailable

Copy link
Copy Markdown
Author

@darccio sorry it looks like I missed a few static CI checks, I fixed the PR title and updated indirect dependencies in contrib/go.uber.org/zap. Should be good to go.

@darccio darccio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@darccio

darccio commented Apr 16, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rarguelloF rarguelloF self-assigned this Apr 16, 2026
@highlyavailable

Copy link
Copy Markdown
Author

Hey @darccio, I believe the generate job is timing out because my orchestrion.yml is triggering the generator to try to add contrib/go.uber.org/zap/v2 to orchestrion/all, but those files aren't committed yet.

I am not sure about the right way to handle that... should I run ./scripts/generate.sh locally and commit the orchestrion/all changes? Or is there something specific expected there for a new integration?

@darccio

darccio commented Apr 17, 2026

Copy link
Copy Markdown
Member

@highlyavailable Yes, you should run make generate and make fix-modules locally. Our generate job is a check that these commands' expected changes are present in the branch.

All the details are explained in our CONTRIBUTING.md, although I noticed that we don't explain make generate although it's covered.

@highlyavailable

highlyavailable commented May 10, 2026

Copy link
Copy Markdown
Author

Hey @darccio. The 2 red CI checks are System Tests and all-jobs-are-green, and I'm pretty sure they're just a fork-PR artifact rather than anything with the diff.

The System Tests matrix jobs get skipped on fork PRs (the gate around system-tests.yml:58 requires head.repo.full_name == 'DataDog/dd-trace-go'), but the system-tests-done aggregator at the bottom of the file treats skipped as failure, so it always goes red.

Looking at the ruleset though, the actual required check is devflow/mergegate, and that one's been pending on this PR for a while. It passed cleanly on #4657 (a similar fork PR) even though System Tests was red there too, so I don't think the red checks are the real blocker. Any chance you could give devflow a nudge, or let me know if there's something I should do on my end to get it to evaluate?

Happy to send a separate PR against the workflow to make the aggregator treat skipped as success

@darccio

darccio commented May 18, 2026

Copy link
Copy Markdown
Member

@highlyavailable I'm going to check this tomorrow.

@datadog-datadog-prod-us1-2

This comment has been minimized.

@rarguelloF

Copy link
Copy Markdown
Contributor

Closing this PR as we are continuing the work in this PR: #4729 to have a zap integration with Orchestrion support.

Thanks @highlyavailable for your contribution!

@rarguelloF rarguelloF closed this May 19, 2026
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