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: improve tracing #1169

Merged
merged 1 commit into from
Jan 5, 2023
Merged

feat: improve tracing #1169

merged 1 commit into from
Jan 5, 2023

Conversation

alnr
Copy link
Collaborator

@alnr alnr commented Dec 30, 2022

needs ory/x#650

@alnr alnr requested review from zepatrik and hperl as code owners December 30, 2022 08:51
@alnr alnr self-assigned this Dec 30, 2022
@alnr alnr force-pushed the improve-tracing branch 2 times, most recently from 09b53e1 to f6ed553 Compare December 30, 2022 12:17
Copy link
Collaborator

@hperl hperl left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

go.mod Outdated Show resolved Hide resolved
Comment on lines +73 to +81
defer func() {
if res.Err != nil {
span.SetStatus(codes.Error, res.Err.Error())
} else {
span.SetAttributes(attribute.String("membership", res.Membership.String()))
}
span.End()
}()

Copy link
Member

Choose a reason for hiding this comment

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

Since the function has only two returns, why do we need a defer for this? You could also do:

span.SetAttributes(attribute.String("membership", res.Membership.String()))
return result

err := ...
span.SetStatus(codes.Error, res.Err.Error())
return err

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are two possible error returns from the function:

  • <-ctx.Done()
  • <-resultCh returns a struct with the Err field set.

Checking the named return value in the deferred call catches them both. Without that, the branch (if res.Err != nil) would need to move inside the select which is awkward.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if I understand - would this not just be:

	resultCh := make(chan checkgroup.Result)
	go e.checkIsAllowed(ctx, r, restDepth)(ctx, resultCh)
	select {
	case result := <-resultCh:
+              span.SetAttributes(attribute.String("membership", res.Membership.String()))
		return result
	case <-ctx.Done():
+               span.SetStatus(codes.Error, ctx.Err())
		return checkgroup.Result{Err: errors.WithStack(ctx.Err())}
	}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in the top branch, if result.Err is not nil, we would miss that error. Not sure if that can ever happen 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aeneasr do you still want me to make this change? Otherwise this PR is ready to merge.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a bit clonky to read compared to the two-liner, but it does guard against future regressions. It's also just a style choice so I'm fine either way - you decide :)

@alnr alnr force-pushed the improve-tracing branch from f6ed553 to 2587245 Compare January 2, 2023 13:45
@CaptainStandby
Copy link
Contributor

You changed all the license headers (probably automatically). I think this is wrong, as the year of these copyright markings normally reflect the year of first publication.
See also:

We probably should fix the automatic tooling

@alnr
Copy link
Collaborator Author

alnr commented Jan 2, 2023

You changed all the license headers (probably automatically). I think this is wrong, as the year of these copyright markings normally reflect the year of first publication. See also:

We probably should fix the automatic tooling

I did it on purpose (with make format) because the format job failed in CI. You are probably correct, though.

@CaptainStandby
Copy link
Contributor

CaptainStandby commented Jan 2, 2023

I did it on purpose (with make format) because the format job failed in CI. You are probably correct, though.

I have created a PR for fixing this here

@alnr alnr force-pushed the improve-tracing branch from 751faa8 to ea06848 Compare January 3, 2023 11:43
@aeneasr aeneasr merged commit 64dc85e into master Jan 5, 2023
@aeneasr aeneasr deleted the improve-tracing branch January 5, 2023 12:10
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.

4 participants