Skip to content

[public-api] Use context logger #16686

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 19 commits into from
Mar 15, 2023
Merged

[public-api] Use context logger #16686

merged 19 commits into from
Mar 15, 2023

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Mar 6, 2023

Description

Adds structured log fields to logs to provide more context on the request/resource/user.

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-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

/hold

@easyCZ
Copy link
Member Author

easyCZ commented Mar 7, 2023

/werft run

👍 started the job as gitpod-build-mp-papi-log-context.6
(with .werft/ from main)

@easyCZ
Copy link
Member Author

easyCZ commented Mar 7, 2023

/werft run

👍 started the job as gitpod-build-mp-papi-log-context.7
(with .werft/ from main)

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-mp-papi-log-context.8 because the annotations in the pull request description changed
(with .werft/ from main)

Base automatically changed from mp/log-context to main March 9, 2023 09:27
@easyCZ easyCZ force-pushed the mp/papi-log-context branch from a0c701f to fb9b0a8 Compare March 14, 2023 12:33
@roboquat roboquat added size/L and removed size/XL labels Mar 14, 2023
@easyCZ easyCZ marked this pull request as ready for review March 14, 2023 12:41
@easyCZ easyCZ requested a review from a team March 14, 2023 12:41
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Mar 14, 2023
@@ -38,6 +40,9 @@ func (s *UserService) GetAuthenticatedUser(ctx context.Context, req *connect.Req
if err != nil {
return nil, proxy.ConvertError(err)
}
log.AddFields(ctx, logrus.Fields{
"user.id": user.ID,
Copy link
Member

Choose a reason for hiding this comment

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

w.r.t to log-shapes: so far we follow this format, which is the same across logs and traces, in TS and Go (in most places 🙃 ).
Not particularly attached to that specific format, but would be great to stay consistent within the app. Plus the existing format is imprinted into quite some 🧠s already 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the . format means it auto-unpicks them as nested properties of these structures, so they get treated more as JSON, rather than as plain strings

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, in a log viewer you see it as "user": { "id": val } which means you group the properties of a user together

Copy link
Member

@geropl geropl Mar 15, 2023

Choose a reason for hiding this comment

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

I get that there are benefits to either side. I just want us to stay consistent, so I don't have to recall multiple formats.

Do you see any possibility we can achieve both? Like, fill multiple fields? 🤷
Also, in theory happy to adjust it everywhere. But I guess that's not worth the effort.

Copy link
Member Author

Choose a reason for hiding this comment

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

With this change, the logging in public-api is "standardised" to the . format. I don't really see much value in duplicating the fields currently. We can update server to use a similar format as well

@easyCZ easyCZ force-pushed the mp/papi-log-context branch from 9b01e3d to c245a88 Compare March 15, 2023 09:27
func validateTeamID(id string) (uuid.UUID, error) {
func validateTeamID(ctx context.Context, id string) (uuid.UUID, error) {
log.AddFields(ctx, logrus.Fields{
"team.id": id,
Copy link
Member

Choose a reason for hiding this comment

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

func validateWorkspaceID(id string) (string, error) {
func validateWorkspaceID(ctx context.Context, id string) (string, error) {
log.AddFields(ctx, logrus.Fields{
"workspace.id": id,
Copy link
Member

Choose a reason for hiding this comment

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

func validateProjectID(id string) (uuid.UUID, error) {
func validateProjectID(ctx context.Context, id string) (uuid.UUID, error) {
log.AddFields(ctx, logrus.Fields{
"project.id": id,
Copy link
Member

Choose a reason for hiding this comment

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

func validatePersonalAccessTokenID(id string) (uuid.UUID, error) {
func validatePersonalAccessTokenID(ctx context.Context, id string) (uuid.UUID, error) {
log.AddFields(ctx, logrus.Fields{
"pat.id": id,
Copy link
Member

Choose a reason for hiding this comment

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

logger.WithField("headers", req.Header()).Debugf("Handling request for %s", req.Spec().Procedure)
}
log.AddFields(ctx, logrus.Fields{
"request.protocol": "connect",
Copy link
Member

@geropl geropl Mar 15, 2023

Choose a reason for hiding this comment

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

Similarly, it would be great to have a "standardized" way to log these things across the app.
But as we don't have anything here, yet, fine with this.

@easyCZ easyCZ force-pushed the mp/papi-log-context branch from c245a88 to b92b44e Compare March 15, 2023 10:07
@easyCZ
Copy link
Member Author

easyCZ commented Mar 15, 2023

Spoke sync. In this PR, I've changed it to use the current format. Subsequent PR will propose changing the format of the log fields such that we benefit from the log viewer representation of fields. This allows us to land the context logging itself here.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

👍

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-mp-papi-log-context.17 because the annotations in the pull request description changed
(with .werft/ from main)

@easyCZ
Copy link
Member Author

easyCZ commented Mar 15, 2023

/unhold

@roboquat roboquat merged commit 59ff034 into main Mar 15, 2023
@roboquat roboquat deleted the mp/papi-log-context branch March 15, 2023 12:52
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/L team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants