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

send traceparent header to ES #1002

Merged

Conversation

stuartnelson3
Copy link
Contributor

Send the traceparent header to elasticsearch, now that ES parses it from incoming requests.

Closes #987

@stuartnelson3 stuartnelson3 requested a review from a team August 10, 2021 09:45
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Looks good!

A couple of things:

  • should we be setting the tracestate header too? Please check with the other agent devs if unsure
  • we also need to propagate the parent transaction's traceparent when there's a non-sampled transaction in the context, or if the span is dropped (max spans per transaction reached). That means we'll need to change the !tx.Sampled() and span.Dropped() cases above. Take a look at apmhttp's client wrapper for reference:
    func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

module/apmelasticsearch/client.go Outdated Show resolved Hide resolved
@apmmachine
Copy link
Contributor

apmmachine commented Aug 10, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-08-11T14:15:38.959+0000

  • Duration: 30 min 38 sec

  • Commit: 7ae9b03

Test stats 🧪

Test Results
Failed 0
Passed 10841
Skipped 268
Total 11109

Trends 🧪

Image of Build Times

Image of Tests

Propagate the parent transaction's traceparent and
tracestate headers when there's a non-sampled
transaction in the context, or if the span is
dropped
assert.Contains(t, headers, apmhttp.TracestateHeader)
}

func TestClientSpanDropped(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axw this and TestClientTransactionUnsampled are copied from apmhttp/client_test.go. They do verify that we're setting the headers when a span is dropped and when a transaction is not sampled, but what do you think about paring them back to just verifying we have the headers? I'm happy either way since this is essentially doubling up on checking the calculation of the headers, vs. just making sure we're setting them.

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 what you have here is good. I do think it's important to check the trace context of the transaction vs. span is used like you have in this test.

@stuartnelson3
Copy link
Contributor Author

/test

@stuartnelson3
Copy link
Contributor Author

jenkins run the tests

if tx == nil || !tx.Sampled() {
apmhttp.SetHeaders(req, traceContext, false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we default to propagating the legacy header?

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 we can skip sending the legacy header. It's only for compatibility with old Elastic APM agents, so not relevant for the Elasticsearch use case where the plan is to extract the traceparent header and use the trace ID in logs.

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

IIANM we should not call SetHeaders when there's no transaction in the context. Otherwise this LGTM

if tx == nil || !tx.Sampled() {
apmhttp.SetHeaders(req, traceContext, false)
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 we can skip sending the legacy header. It's only for compatibility with old Elastic APM agents, so not relevant for the Elasticsearch use case where the plan is to extract the traceparent header and use the trace ID in logs.

module/apmhttp/client.go Show resolved Hide resolved
assert.Contains(t, headers, apmhttp.TracestateHeader)
}

func TestClientSpanDropped(t *testing.T) {
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 what you have here is good. I do think it's important to check the trace context of the transaction vs. span is used like you have in this test.

module/apmelasticsearch/client.go Outdated Show resolved Hide resolved
@stuartnelson3 stuartnelson3 merged commit fbf6fb2 into elastic:master Aug 11, 2021
@stuartnelson3 stuartnelson3 deleted the apmelasticsearch-traceparent branch August 11, 2021 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apmelasticsearch: send traceparent header to Elasticsearch
3 participants