Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add log/slog instrumentation #208

Merged
merged 4 commits into from
Aug 6, 2024
Merged

feat: add log/slog instrumentation #208

merged 4 commits into from
Aug 6, 2024

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Aug 5, 2024

What does this PR do?

Add instrumentation for log/slog. Implemented using dd-trace-go's
log/slog.Handler wrapper to wrap any handler passed to log/slog.New.

This commit does not instrument the default log/slog.Logger. We could
do that, for example, by adding some logic like this to func main() if
log/slog is imported by package main:

slog.SetDefault(
    slog.New(
        slogtrace.WrapHandler(
            slog.Default().Handler(),
        ),
    ),
)

Will leave that as a followup for now.

Motivation

I maintain an app that uses log/slog for logging. I'd like to eventually
instrument the app using Orchestrion, and having trace-log correlation is very
useful for debugging.

Reviewer's Checklist

  • Changed code has unit tests for its functionality.

Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.76%. Comparing base (1123ea0) to head (923daac).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #208   +/-   ##
=======================================
  Coverage   64.76%   64.76%           
=======================================
  Files          76       76           
  Lines        3993     3993           
=======================================
  Hits         2586     2586           
  Misses       1134     1134           
  Partials      273      273           
Flag Coverage Δ
ARM64 47.65% <ø> (ø)
Linux 69.16% <ø> (ø)
Windows 46.53% <ø> (ø)
X64 64.76% <ø> (ø)
generator 42.67% <ø> (ø)
go1.21 55.29% <ø> (ø)
go1.22 51.91% <ø> (ø)
go1.23 53.65% <ø> (+2.01%) ⬆️
integration 46.93% <ø> (ø)
macOS 47.65% <ø> (ø)
unit 40.26% <ø> (+0.77%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Add instrumentation for log/slog. Implemented using dd-trace-go's
log/slog.Handler wrapper to wrap any handler passed to log/slog.New.

This commit does not instrument the default log/slog.Logger. We could
do that, for example, by adding some logic like this to func main() if
log/slog is imported by package main:

	slog.SetDefault(
		slog.New(
			slogtrace.WrapHandler(
				slog.Default().Handler(),
			),
		),
	)

Will leave that as a followup for now.
@nsrip-dd nsrip-dd marked this pull request as ready for review August 6, 2024 01:01
@nsrip-dd nsrip-dd requested a review from a team as a code owner August 6, 2024 01:01
Copy link
Member

@felixge felixge left a comment

Choose a reason for hiding this comment

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

Awesome 🤩 . This looks good to me - but I'm not super familiar with orchestrion internals.

@RomainMuller RomainMuller added this pull request to the merge queue Aug 6, 2024
Merged via the queue into main with commit 745a9ef Aug 6, 2024
24 checks passed
@RomainMuller RomainMuller deleted the nick.ripley/slog branch August 6, 2024 13: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