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

nrslog.WithTransactionFromContext does not work after slog.With #986

Open
moenth opened this issue Nov 19, 2024 · 1 comment
Open

nrslog.WithTransactionFromContext does not work after slog.With #986

moenth opened this issue Nov 19, 2024 · 1 comment
Assignees
Labels

Comments

@moenth
Copy link

moenth commented Nov 19, 2024

Description

When creating a slog.Logger using nrslog.WithTransactionFromContext transaction contexts stops being propagated after calling With on the resulting logger. This is because TransactionFromContextHandler does not implement its own WithAttrs and WithGroup functions which means they are delegated to the underlying NRHandler. Thus TransactionFromContextHandler is removed from the handler stack after calling either of these functions.

Steps to Reproduce

handler := nrslog.TextHandler(app, os.Stdout, &slog.HandlerOptions{})
logger := slog.New(nrslog.WithTransactionFromContext(handler))
appLogger := logger.With(slog.String("component", "app"))

tx := app.StartTransaction("test")
ctx := newrelic.NewContext(context.Background(), tx)

logger.InfoContext(ctx, "has transaction context")
appLogger.InfoContext(ctx, "does not have transaction context")

Expected Behavior

Transaction context is propagated after using slog.With.

NR Diag results

Your Environment

Reproduction case

Additional context

@moenth moenth added the bug label Nov 19, 2024
@iamemilio iamemilio self-assigned this Nov 19, 2024
@iamemilio
Copy link
Contributor

iamemilio commented Nov 19, 2024

Thank you for reporting this issue, we will ticket and address this ASAP 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants