Skip to content

[logging] Enable storing/extracing of logger from context #16658

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

Merged
merged 8 commits into from
Mar 9, 2023

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Mar 3, 2023

Description

This adds helpers to:

Why?
With the logger on the context, we gain the ability to have request scoped fields on the logger. This means that we can add more fields to the existing context and these will be logged when we actually use the context logger to log.

To better illustrate this:

  1. Request arrives at a server
  2. The request first runs through a middleware, the middleware attaches the (request ID, path, params, ...)
  3. The handler gets invoked. The handler first checks if an experiment is enabled, and attaches that value to the context logger through fields
  4. The handler returns an error
  5. The middleware picks up the error, and logs it. When this happens, the log also contains the attached information about the experiment not being present, as well as (request ID, etc..)

I will update the public api to use the context logger in subsequent PR

Related Issue(s)

Fixes #

How to test

Release Notes

NONE

Documentation

Build Options:

  • /werft with-github-actions
    Experimental feature to run the build with GitHub Actions (and not in Werft).
  • leeway-no-cache
    leeway-target=components:all
  • /werft no-test
    Run Leeway with --dont-test
Publish Options
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer Options
  • with-ee-license
  • with-slow-database
  • with-dedicated-emulation
  • with-ws-manager-mk2
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated

Preview Environment Options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

@easyCZ easyCZ requested review from a team March 3, 2023 13:59
@roboquat roboquat added size/M and removed size/S labels Mar 3, 2023
@roboquat roboquat added size/S and removed size/M labels Mar 3, 2023
@roboquat roboquat added size/M and removed size/S labels Mar 3, 2023
@easyCZ
Copy link
Member Author

easyCZ commented Mar 3, 2023

The go.mod diff is silly, but it's because common-go/log is used by all packages.

/hold for discussion, if needed

Copy link
Contributor

@mads-hartmann mads-hartmann left a comment

Choose a reason for hiding this comment

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

From an instrumentation perspective this seems like an excellent addition! 🎉 Even though it's only 3 lines of code, and all it does is delegate to another library, I would have loved a tiny test of it - if it's not too much trouble to add that would be lovely, but I'll approve and leave that decision with you ☺️

@easyCZ
Copy link
Member Author

easyCZ commented Mar 6, 2023

@mads-hartmann added a test. Thanks!

@roboquat roboquat added size/L and removed size/M labels Mar 6, 2023
@akosyakov
Copy link
Member

Just to clarify it for myself:

  • it allows to hook our logrus logger with additional fields in grpc middleware
  • it is not used by default, but there will be follow up PRs to integrate

?

@easyCZ
Copy link
Member Author

easyCZ commented Mar 7, 2023

@akosyakov Yes. It uses the context to attach a request-scoped logger & fields to it. This means that any fields we add are part of that request lifecycle.

Yes, not yet used by services. I've a follow-up PR which adds it to public-api to demonstrate the usage (not yet complete).

This then means we can magically have extra context on the log lines. One of the most powerful parts of this is when we attach the trace ID on the log context, and then we can lookup all logs for a given request, even across services (because the tracing ID is propagated)

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

no objections from my side

@easyCZ
Copy link
Member Author

easyCZ commented Mar 9, 2023

/unhold

@roboquat roboquat merged commit 13b3b01 into main Mar 9, 2023
@roboquat roboquat deleted the mp/log-context branch March 9, 2023 09:27
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.

6 participants