Skip to content

feat(tracing): Handle incoming tracestate data, allow for third-party data - #3275

Merged
lobsterkatie merged 13 commits into
kmclb-dynamic-sampling-data-in-envelopesfrom
kmclb-handle-third-party-tracestate
Feb 27, 2021
Merged

feat(tracing): Handle incoming tracestate data, allow for third-party data#3275
lobsterkatie merged 13 commits into
kmclb-dynamic-sampling-data-in-envelopesfrom
kmclb-handle-third-party-tracestate

Conversation

@lobsterkatie

@lobsterkatielobsterkatie commented Feb 23, 2021

Copy link
Copy Markdown
Member

This builds on previous dynamic sampling/tracestate PRs by (as the title says), consuming incoming tracestate headers and allowing for non-sentry data in both those and outgoing tracestate headers.

This should complete the initial implementation of tracestate on the JavaScript side.

Lingering issues to be dealt with in future:

  • Because Buffer is mentioned in utils/string.ts, webpack will include the entire contents of node's Buffer module in your bundle when you include @sentry/browser or any of its derivatives in said bundle. (Rollup is smart enough to exclude it from our CDN bundles.) Before we GA this, we need to figure out a way around that. Holding off for now since all of the build tooling is changing in v7, and this likely won't GA until after v7 is released. (As to our dogfooding, @HazAT suggested seeing how much of an impact it actually has there before spending time dealing with it.)

  • This initial proof of concept doesn't include any user data, which the final version will need to.

  • This also doesn't handle weird edge cases in terms of third-party data in the headers (blank values, for instance), as detailed in the official spec.

@github-actions

github-actionsBot commented Feb 23, 2021

Copy link
Copy Markdown
Contributor

size-limit report

PathSize
@sentry/browser - CDN Bundle (gzipped)26.88 KB (-0.01% 🔽)
@sentry/browser - Webpack27.81 KB (0%)
@sentry/react - Webpack27.83 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped)34.59 KB (+1.02% 🔺)

@lobsterkatie
lobsterkatieforce-pushed the kmclb-handle-third-party-tracestate branch from 01f2b1c to b808fccCompareFebruary 23, 2021 20:58
@lobsterkatie
lobsterkatieforce-pushed the kmclb-handle-third-party-tracestate branch from 4a57c05 to fbd3c0fCompareFebruary 24, 2021 18:16
@lobsterkatie
lobsterkatieforce-pushed the kmclb-handle-third-party-tracestate branch from fbd3c0f to 06e8d3bCompareFebruary 24, 2021 18:29
@lobsterkatie

Copy link
Copy Markdown
MemberAuthor

The linting error is solved in a follow-up cleanup PR to come once this is merged into the feature branch.

@lobsterkatie
lobsterkatie marked this pull request as ready for review February 24, 2021 18:47

@HazATHazAT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, skimmed over it at it makes sense

Comment threadpackages/serverless/src/awslambda.ts
const sentrytraceData = sentrytraceValue ? extractSentrytraceData(sentrytraceValue) : undefined;
const tracestateData = tracestateValue ? extractTracestateData(tracestateValue) : undefined;

if (sentrytraceData || tracestateData?.sentry || tracestateData?.thirdparty) {

@kamilogorekkamilogorekFeb 26, 2021

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.

tracestateData?.thirdparty is useless here, as it will never be reached due to the first sentrytraceData check already shorting it with its truthiness.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

But sentrytraceData isn't guaranteed to be truthy - if the sentry-trace<meta> tag isn't there, or if the value is somehow malformed, you could have tracestate data without having sentry-trace data. Similarly, if we have a tracesatate value in which there's no sentry portion (or the sentry portion is malformed), then we could have third-party tracestate data without having sentry tracestate data. So I think we need all three checks, since the existence of each value is independent of the existence of the others.

Comment threadpackages/tracing/src/utils.ts Outdated
Comment threadpackages/tracing/src/utils.ts Outdated

// remove the commas after the split so we don't end up with `xxx=yyy,,zzz=qqq` (double commas) when we put them
// back together
[before, after] = header.split(sentryEntry).map(s => s.replace(/^,*|,*$/g, ''));

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.

Suggested change
[before,after]=header.split(sentryEntry).map(s=>s.replace(/^,*|,*$/g,''));
[before,after]=header.split(sentryEntry).map(s=>s.replace(/,/g,''));

This should be good enough I guess. We don't allow for commas anywhere in the middle of a value anyway.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Actually, no. That's what I had originally, but if the header comes in with a value like

x=y,sentry=blah,a=b,c=d

then getting rid of all commas gets rid of the comma between a=b and c=d, which isn't what we want.

Comment threadpackages/tracing/src/utils.ts Outdated
Comment threadpackages/tracing/src/utils.ts Outdated
@lobsterkatie
lobsterkatie merged commit 4cf7262 into kmclb-dynamic-sampling-data-in-envelopesFeb 27, 2021
@lobsterkatie
lobsterkatie deleted the kmclb-handle-third-party-tracestate branch February 27, 2021 02:22
lobsterkatie added a commit that referenced this pull request Aug 24, 2021
This is the result of rebasing the feature branch for the initial implementation of `tracestate` header handling (which had grown very stale) on top of current `master`. That branch is going to get deleted, so for posterity, it included the following PRs (oldest -> newest):
feat(tracing): Add dynamic sampling correlation context data to envelope header (#3062)
chore(utils): Split browser/node compatibility utils into separate module (#3123)
ref(tracing): Prework for initial `tracestate` implementation (#3242)
feat(tracing): Add `tracestate` header to outgoing requests (#3092)
ref(tracing): Rework tracestate internals to allow for third-party data (#3266)
feat(tracing): Handle incoming tracestate data, allow for third-party data (#3275)
chore(tracing): Various small fixes to first `tracestate` implementation (#3291)
fix(tracing): Use `Request.headers.append` correctly (#3311)
feat(tracing): Add user data to tracestate header (#3343)
chore(various): Small fixes (#3368)
fix(build): Prevent Node's `Buffer` module from being included in browser bundles (#3372)
fix(tracing): Remove undefined tracestate data rather than setting it to `null` (#3373)
More detail in the PR description.
lobsterkatie added a commit that referenced this pull request Aug 30, 2021
This is the result of rebasing the feature branch for the initial implementation of `tracestate` header handling (which had grown very stale) on top of current `master`. That branch is going to get deleted, so for posterity, it included the following PRs (oldest -> newest):
feat(tracing): Add dynamic sampling correlation context data to envelope header (#3062)
chore(utils): Split browser/node compatibility utils into separate module (#3123)
ref(tracing): Prework for initial `tracestate` implementation (#3242)
feat(tracing): Add `tracestate` header to outgoing requests (#3092)
ref(tracing): Rework tracestate internals to allow for third-party data (#3266)
feat(tracing): Handle incoming tracestate data, allow for third-party data (#3275)
chore(tracing): Various small fixes to first `tracestate` implementation (#3291)
fix(tracing): Use `Request.headers.append` correctly (#3311)
feat(tracing): Add user data to tracestate header (#3343)
chore(various): Small fixes (#3368)
fix(build): Prevent Node's `Buffer` module from being included in browser bundles (#3372)
fix(tracing): Remove undefined tracestate data rather than setting it to `null` (#3373)
More detail in the PR description.
lobsterkatie added a commit that referenced this pull request Aug 31, 2021
This is the result of rebasing the feature branch for the initial implementation of `tracestate` header handling (which had grown very stale) on top of current `master`. That branch is going to get deleted, so for posterity, it included the following PRs (oldest -> newest):
feat(tracing): Add dynamic sampling correlation context data to envelope header (#3062)
chore(utils): Split browser/node compatibility utils into separate module (#3123)
ref(tracing): Prework for initial `tracestate` implementation (#3242)
feat(tracing): Add `tracestate` header to outgoing requests (#3092)
ref(tracing): Rework tracestate internals to allow for third-party data (#3266)
feat(tracing): Handle incoming tracestate data, allow for third-party data (#3275)
chore(tracing): Various small fixes to first `tracestate` implementation (#3291)
fix(tracing): Use `Request.headers.append` correctly (#3311)
feat(tracing): Add user data to tracestate header (#3343)
chore(various): Small fixes (#3368)
fix(build): Prevent Node's `Buffer` module from being included in browser bundles (#3372)
fix(tracing): Remove undefined tracestate data rather than setting it to `null` (#3373)
More detail in the PR description.
lobsterkatie added a commit that referenced this pull request Sep 15, 2021
This is the result of rebasing the feature branch for the initial implementation of `tracestate` header handling (which had grown very stale) on top of current `master`. That branch is going to get deleted, so for posterity, it included the following PRs (oldest -> newest):
feat(tracing): Add dynamic sampling correlation context data to envelope header (#3062)
chore(utils): Split browser/node compatibility utils into separate module (#3123)
ref(tracing): Prework for initial `tracestate` implementation (#3242)
feat(tracing): Add `tracestate` header to outgoing requests (#3092)
ref(tracing): Rework tracestate internals to allow for third-party data (#3266)
feat(tracing): Handle incoming tracestate data, allow for third-party data (#3275)
chore(tracing): Various small fixes to first `tracestate` implementation (#3291)
fix(tracing): Use `Request.headers.append` correctly (#3311)
feat(tracing): Add user data to tracestate header (#3343)
chore(various): Small fixes (#3368)
fix(build): Prevent Node's `Buffer` module from being included in browser bundles (#3372)
fix(tracing): Remove undefined tracestate data rather than setting it to `null` (#3373)
More detail in the PR description.
Sign up for freeto 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.

3 participants

@lobsterkatie@HazAT@kamilogorek