Skip to content

feat: tracing improvements #4988

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 5 commits into from
Nov 28, 2022
Merged

feat: tracing improvements #4988

merged 5 commits into from
Nov 28, 2022

Conversation

deansheather
Copy link
Member

@deansheather deansheather commented Nov 9, 2022

  • Move the tracing middleware higher up the stack so it can see more, but make sure that it only applies the backend API routes
  • Add tracing.RunWithoutSpan which runs the given function with a noop span attached to the context. This is used in a few places to avoid capturing logs as events in the span when the span already had all of the information contained in the log.

@deansheather deansheather requested a review from coadler November 9, 2022 21:16
@github-actions
Copy link

This Pull Request is becoming stale. In order to minimize WIP, prevent merge conflicts and keep the tracker readable, I'm going close to this PR in 3 days if there isn't more activity.

@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 17, 2022
@deansheather deansheather removed the stale This issue is like stale bread. label Nov 17, 2022
@deansheather deansheather marked this pull request as ready for review November 17, 2022 14:44
httpmw.Recover(api.Logger),
tracing.Middleware(api.TracerProvider),
Copy link
Member

Choose a reason for hiding this comment

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

This will trace every static HTTP file... is that ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a filter within the middleware itself (and a test) to ensure that this is skipped on non-API routes.


sw, ok := rw.(*tracing.StatusWriter)
if !ok {
panic(fmt.Sprintf("ResponseWriter not a *tracing.StatusWriter; got %T", rw))
Copy link
Member

Choose a reason for hiding this comment

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

It's runtime, right? Isn't it risky to panic here? I understand that you assume that it will be recovered.

Copy link
Member Author

Choose a reason for hiding this comment

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

The response writer will always be a *tracing.StatusWriter, so I think it's fine for us to panic here as this is a developer error. We panic in a other places due to developer errors as well, like the middleware context value stuff also in the httpmw package.

We also already do this exact panic in the tracing middleware too

Copy link
Member

Choose a reason for hiding this comment

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

I admit that I'm not a fan of it, but I understand why it's safe here 👍

@deansheather deansheather enabled auto-merge (squash) November 23, 2022 15:20
@deansheather deansheather merged commit 15f8967 into main Nov 28, 2022
@deansheather deansheather deleted the dean/tracing-improvements branch November 28, 2022 21:22
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants