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

Return tracing header in Rack/Rails HTTP response to support passing trace information via JS apps #16

Merged
merged 3 commits into from
Dec 12, 2018

Conversation

LarsFronius
Copy link
Contributor

In our case, we have a Rails application, that the user has the first interaction with. This is where the trace is started. From here a Javascript app in the browser takes over any further interaction and calls different API subsystems. In order to pass the tracing information to these API subsystems and continue the original trace, this PR introduces responding with the X-Amzn-Trace-Id header in the Rack/Rails response.

I had noticed that e.g. https://github.com/aws/aws-xray-sdk-go is responding with the X-Amzn-Trace-Id header by default once the http middleware is configured, which makes my think it's wanted default behaviour.

Looking forward to hearing your feedback about whether this being the right approach. I am also wondering if it's worth making this configurable in any way or can be default behaviour as observed in the Go SDK.

Best, Lars

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

@LarsFronius LarsFronius changed the title Returns tracing header in Rack/Rails HTTP response to support passing trace information via JS apps Return tracing header in Rack/Rails HTTP response to support passing trace information via JS apps Nov 30, 2018
@haotianw465
Copy link
Contributor

haotianw465 commented Dec 7, 2018

Thank you for the contribution. You are correct the trace header should be returned on the response header by default. This is a miss on Ruby SDK. The standard of returning trace header is actually only returning the trace id portion. Parent id is not necessary and the SDK should not expose sampling rate to external caller. See the Go SDK implementation https://github.com/aws/aws-xray-sdk-go/blob/master/xray/handler.go#L134-L138

@haotianw465 haotianw465 added the bug label Dec 7, 2018
@haotianw465 haotianw465 self-requested a review December 7, 2018 19:50
@LarsFronius
Copy link
Contributor Author

Incorporated your feedback in a subsequent commit @haotianw465 👍

@@ -49,6 +49,8 @@ def call(env)
resp_meta[:content_length] = len
end
segment.merge_http_response response: resp_meta
trace_header = {TRACE_HEADER => TraceHeader.from_entity(entity: XRay.recorder.current_segment).root_string}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick. Why passing XRay.recorder.current_segment instead of segment?

Copy link
Contributor Author

@LarsFronius LarsFronius Dec 10, 2018

Choose a reason for hiding this comment

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

I think I have written XRay.recorder.current_segment too many times to retrieve the current segment, that I didn't realize I actually have a segment object available in this scope. 🤔 Muscle memory, haha. Good catch and corrected! 🙂

@haotianw465 haotianw465 merged commit 24b478e into aws:master Dec 12, 2018
@LarsFronius LarsFronius deleted the return-trace-header branch December 12, 2018 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants