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

Dynamic Sampling Context Continuation / Baggage #1869

Merged
merged 21 commits into from
Oct 3, 2022

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Aug 16, 2022

This PR adds support for the first part of our Dynamic Sampling product, i.e.

  • parsing incoming W3C Baggage headers and adding them as a Baggage object on the transaction
  • adding this baggage header to other outgoing HTTP requests in our net/http patch
  • converting the sentry-* items in the baggage to a DSC (Dynamic Sampling Context) and attaching them to outgoing envelope headers in the trace field

now contains #1898 and #1902

closes #1835

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2022

Codecov Report

Base: 98.38% // Head: 98.46% // Increases project coverage by +0.08% 🎉

Coverage data is based on head (a558764) compared to base (d83b29c).
Patch coverage: 99.75% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1869      +/-   ##
==========================================
+ Coverage   98.38%   98.46%   +0.08%     
==========================================
  Files         148      150       +2     
  Lines        8893     9240     +347     
==========================================
+ Hits         8749     9098     +349     
+ Misses        144      142       -2     
Impacted Files Coverage Δ
sentry-ruby/lib/sentry/event.rb 98.76% <ø> (ø)
sentry-ruby/lib/sentry/rake.rb 65.00% <0.00%> (ø)
...entry-delayed_job/lib/sentry/delayed_job/plugin.rb 100.00% <100.00%> (ø)
sentry-delayed_job/spec/sentry/delayed_job_spec.rb 100.00% <100.00%> (ø)
sentry-rails/lib/sentry/rails/action_cable.rb 100.00% <100.00%> (ø)
sentry-rails/lib/sentry/rails/active_job.rb 100.00% <100.00%> (ø)
...entry-rails/lib/sentry/rails/capture_exceptions.rb 100.00% <100.00%> (+3.57%) ⬆️
...y-rails/lib/sentry/rails/controller_transaction.rb 100.00% <100.00%> (ø)
...entry-rails/spec/sentry/rails/action_cable_spec.rb 100.00% <100.00%> (ø)
sentry-rails/spec/sentry/rails/activejob_spec.rb 99.38% <100.00%> (+<0.01%) ⬆️
... and 28 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sl0thentr0py sl0thentr0py mentioned this pull request Aug 18, 2022
@sl0thentr0py sl0thentr0py changed the title Dynamic Sampling Context Continuation / Baggage WIP Dynamic Sampling Context Continuation / Baggage Aug 19, 2022
sentry-ruby/lib/sentry/baggage.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/baggage.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/span.rb Outdated Show resolved Hide resolved
@sl0thentr0py sl0thentr0py marked this pull request as ready for review September 8, 2022 13:30
sentry-ruby/lib/sentry/baggage.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/baggage.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/span.rb Outdated Show resolved Hide resolved
sentry-ruby/lib/sentry/client.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Do we want to release this in the next minor release?

sentry-ruby/lib/sentry/transport.rb Show resolved Hide resolved
@sl0thentr0py
Copy link
Member Author

@st0012 for releasing this, we need 2 more PRs, so maybe let's merge them all together. They're independent as features, but should go out together ideally.

@sl0thentr0py sl0thentr0py force-pushed the neel/baggage-dsc-continuation branch 2 times, most recently from 75bcad6 to 522f0f2 Compare September 15, 2022 12:10
@sl0thentr0py
Copy link
Member Author

I'm making this a draft again so we don't merge it accidentally

@sl0thentr0py sl0thentr0py marked this pull request as draft September 15, 2022 12:32
@sl0thentr0py
Copy link
Member Author

@st0012 after some discussion, we decided to remove all third party handling since that was mostly unused logic.

Creates new `Baggage` entries when the ruby SDK is the `head SDK`, i.e the first SDK that originates a distributed trace.
The new `Baggage` entry is created when `get_baggage` is first called, either
* when the first outgoing HTTP request is made
* the first transaction finishes and the envelope is sent to sentry
@sl0thentr0py
Copy link
Member Author

sl0thentr0py commented Sep 28, 2022

E2E testing documentation

JS as head SDK / continuation

relevant frontend request headers (baggage)

GET /ds/items HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:3000/ds_js_head
sentry-trace: 9821e65c92894d60ab9b05e69d84e218-994f1602ff45d966-1
baggage: sentry-environment=development,sentry-release=foobar,sentry-public_key=d16ae2d36f9249849c7964e9a3a8a608,sentry-trace_id=9821e65c92894d60ab9b05e69d84e218,sentry-sample_rate=1

Outgoing trace envelope header (dynamic sampling context)

[5] pry(#<Sentry::HTTPTransport>)> envelope.headers[:trace]
=> {"environment"=>"development", "release"=>"foobar", "public_key"=>"d16ae2d36f9249849c7964e9a3a8a608", "trace_id"=>"9821e65c92894d60ab9b05e69d84e218", "sample_rate"=>"1"}

correct source annotation in transaction_info

[8] pry(#<Sentry::HTTPTransport>)> envelope.items.first.payload[:transaction_info]
=> {:source=>:view}

Backend-backend propagation of baggage


Rails as head SDK

meta tags on rails template

<meta name="sentry-trace" content="43906b36c4e84d97b310908dfa323ca0-534d009e7d378188-1">
<meta name="baggage" content="sentry-trace_id=43906b36c4e84d97b310908dfa323ca0,sentry-sample_rate=1.0,sentry-environment=development,sentry-release=test-sessions-2022-09-28+14%3A34%3A02+UTC,sentry-public_key=2fb45f003d054a7ea47feb45898f7649">

outgoing request from browser continues that trace

GET /ds/items HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:3000/ds_rails_head
sentry-trace: 43906b36c4e84d97b310908dfa323ca0-adc949650e49f6da-1
baggage: sentry-trace_id=43906b36c4e84d97b310908dfa323ca0,sentry-sample_rate=1.0,sentry-environment=development,sentry-release=test-sessions-2022-09-28%2B14%3A34%3A02%2BUTC,sentry-public_key=2fb45f003d054a7ea47feb45898f7649

envelope from browser transaction has correct trace header

"trace":{"trace_id":"43906b36c4e84d97b310908dfa323ca0","sample_rate":"1.0","environment":"development","release":"test-sessions-2022-09-28+14:34:02+UTC","public_key":"2fb45f003d054a7ea47feb45898f7649"}}

final flask request also has correct baggage header

sentry-trace_id=43906b36c4e84d97b310908dfa323ca0,sentry-sample_rate=1.0,sentry-environment=development,sentry-release=test-sessions-2022-09-28%2B14%3A34%3A02%2BUTC,sentry-public_key=2fb45f003d054a7ea47feb45898f7649

@sl0thentr0py sl0thentr0py modified the milestones: 5.5.0, Dynamic Sampling Sep 28, 2022
@sl0thentr0py
Copy link
Member Author

ok @st0012 I've tested this E2E properly in all scenarios, everything seems to work 🎉

Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

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

Just a couple of question for me to understand. The tests I just skimmed over because my brain is already porridge, but everything looks ok (because it also looks very similar to the python implementation.)

sentry-rails/lib/sentry/rails/action_cable.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/client.rb Show resolved Hide resolved
sentry-ruby/lib/sentry/transaction.rb Show resolved Hide resolved
@sl0thentr0py sl0thentr0py marked this pull request as ready for review September 30, 2022 09:15
@st0012
Copy link
Collaborator

st0012 commented Sep 30, 2022

@sl0thentr0py Should we make this PR ready for review?

@sl0thentr0py sl0thentr0py merged commit c79aa34 into master Oct 3, 2022
@sl0thentr0py sl0thentr0py deleted the neel/baggage-dsc-continuation branch October 3, 2022 12:27
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.

feat(tracing) [DSC] Dynamic Sampling Context continuation
4 participants