Skip to content

add traceContinuationStrategy config option; add Span Links API#2692

Merged
trentm merged 11 commits intomainfrom
trentm/span-links
May 16, 2022
Merged

add traceContinuationStrategy config option; add Span Links API#2692
trentm merged 11 commits intomainfrom
trentm/span-links

Conversation

@trentm
Copy link
Copy Markdown
Member

@trentm trentm commented May 13, 2022

This adds a 'links' option to createTransaction and createSpan APIs
for specifying span links.
apm.startSpan('name', { links: [ ... ] })
https://github.com/elastic/apm/blob/main/specs/agents/span-links.md
Span links support is added to the OTel Bridge as well:
tracer.startSpan('name', { links: [ ... ] })

This adds a traceContinutationStrategy configuration option to allow
some control over how the APM Agent uses incoming trace-context headers
for context propagation.
https://github.com/elastic/apm/blob/main/specs/agents/trace-continuation.md

This also fixes a whitespace parsing issue in TraceState.

Closes: #2592
Closes: #2673
Closes: #2554
Obsoletes: #2555

checklist

  • tests pass
  • changelog

This adds a `traceContinutationStrategy` configuration option to allow
some control over how the APM Agent uses incoming trace-context headers
for context propagation. The default 'continue_always' value results in
the current behaviour of using 'traceparent' and 'tracestate' per the
W3C spec. A value of 'restart_always' will result in incoming
'traceparent' and 'tracestate' headers being *ignored*. This can be
useful for a service that is receiving problematic tracing headers from
an upstream service that is unmonitored (without root transactions in
ES, the APM UI has limitations) or otherwise out of the user's control
(sampling rate may not be what the user wants).

This is currently *experimental* while a design for
`trace_continuation_strategy` is being discussed at
elastic/apm#286. This currently implements a
*subset* of the proposed design there -- `restart_external` is not yet
implemented.
@trentm trentm self-assigned this May 13, 2022
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label May 13, 2022
@ghost
Copy link
Copy Markdown

ghost commented May 13, 2022

💚 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: 2022-05-13T05:08:33.785+0000

  • Duration: 20 min 10 sec

Test stats 🧪

Test Results
Failed 0
Passed 256695
Skipped 0
Total 256695

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@trentm trentm marked this pull request as ready for review May 13, 2022 05:04
@trentm trentm requested a review from astorm May 13, 2022 05:04
Copy link
Copy Markdown
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

Does what is says and aligns with the spec -- no objections to anything in the implementation. Approving.

Comment thread docs/index.asciidoc

:type-string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type[<string>]
:type-string-array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type[<string[]>]
:type-array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array[<Array>]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question -- did not having the Array type here break something or is this just a bit of "fix it as we go" maintenance? (no objection, just curious)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had asked Brandon about how to add it and then requested review before I remembered to do that step. Nothing breaks, but the links <Array> rendering in the docs (e.g. at https://apm-agent-nodejs_2692.docs-preview.app.elstc.co/guide/en/apm/agent/nodejs/master/agent-api.html#apm-start-transaction) doesn't look as nice without it.

Comment on lines +24 to +28
// Decide whether to use trace-context headers, if any, for a
// distributed trace.
const traceparent = req.headers.traceparent || req.headers['elastic-apm-traceparent']
const tracestate = req.headers.tracestate
const trans = agent.startTransaction(null, null, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just noting that the change from var to const will block scope these variables, but it doesn't look like they were accessed outside this block so 👍

@trentm trentm merged commit 01154f3 into main May 16, 2022
@trentm trentm deleted the trentm/span-links branch May 16, 2022 23:47
astorm pushed a commit that referenced this pull request May 19, 2022
This adds a 'links' option to `createTransaction` and `createSpan` APIs
for specifying span links.
    apm.startSpan('name', { links: [ ... ] })
https://github.com/elastic/apm/blob/main/specs/agents/span-links.md
Span links support is added to the OTel Bridge as well:
    tracer.startSpan('name', { links: [ ... ] })

This adds a `traceContinutationStrategy` configuration option to allow
some control over how the APM Agent uses incoming trace-context headers
for context propagation.
https://github.com/elastic/apm/blob/main/specs/agents/trace-continuation.md

This also fixes a whitespace parsing issue in TraceState.

Closes: #2592
Closes: #2673
Closes: #2554
Obsoletes: #2555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-nodejs Make available for APM Agents project planning.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[META 643] Implement Span Links API [META 604] Implement trace_continuation_strategy Override sampled state from traceparent header

3 participants