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

fix: replace segment name from env on BeginSegment #304

Merged
merged 2 commits into from
Jun 2, 2021

Conversation

nicolascb
Copy link
Contributor

It is not clear from the official documentation that this variable is used only in HTTP situations:

Environment variables

You can use environment variables to configure the X-Ray SDK for Go. The SDK supports the following variables.

    AWS_XRAY_TRACING_NAME – Set the service name that the SDK uses for segments.

This PR applies the same logic so that the segment name is replaced by the environment variable AWS_XRAY_TRACING_NAME.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@nicolascb
Copy link
Contributor Author

That makes sense? @bhautikpip

@nicolascb nicolascb marked this pull request as draft May 31, 2021 12:43
@nicolascb nicolascb marked this pull request as ready for review May 31, 2021 12:45
@bhautikpip
Copy link
Contributor

Yes, I think this check will be useful when we directly call xray.BeginSegment() API and for other middlewares like http and fasthttp handler we are checking this env var in xray.NewFixedSegmentNamer method. So I think for parity with other checks this would be a good change to add.

@bhautikpip
Copy link
Contributor

Should we remove the check from here

if fName := os.Getenv("AWS_XRAY_TRACING_NAME"); fName != "" {
and keep it only at xray.BeginSegment() method ? I think in the case of http handler if customer has used AWS_XRAY_TRACING_NAME then the same condition will be evaluated twice.

@nicolascb
Copy link
Contributor Author

Should we remove the check from here

if fName := os.Getenv("AWS_XRAY_TRACING_NAME"); fName != "" {

and keep it only at xray.BeginSegment() method ? I think in the case of http handler if customer has used AWS_XRAY_TRACING_NAME then the same condition will be evaluated twice.

Sorry @bhautikpip, but I did not understand.

If you remove this condition, what about situations where we don't use xray.BeginSegment?

As in this example:
image

@bhautikpip
Copy link
Contributor

So basically xray.Handler method calls xray.NewSegmentFromHeader (https://github.com/aws/aws-xray-sdk-go/blob/master/xray/handler.go#L94) method and that method calls xray.BeginSegmentWithSampling (

func BeginSegmentWithSampling(ctx context.Context, name string, r *http.Request, traceHeader *header.Header) (context.Context, *Segment) {
). so basically middlewares like http end up calling BeginSegmentWithSampling method so if we keep this condition inside BeginSegmentWithSampling then we can remove this condition inside NewFixedSegmentNamer. Hope this makes sense!

@nicolascb
Copy link
Contributor Author

@bhautikpip Yes you are right.

I will work on it, thanks for the review

@nicolascb
Copy link
Contributor Author

Done de8e0b9 @bhautikpip

@bhautikpip bhautikpip self-requested a review June 2, 2021 18:41
Copy link
Contributor

@bhautikpip bhautikpip left a comment

Choose a reason for hiding this comment

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

LGTM :)

@bhautikpip bhautikpip merged commit 97520b3 into aws:master Jun 2, 2021
@nicolascb nicolascb deleted the fix/begin-segment-name branch June 2, 2021 18:56
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.

2 participants