-
-
Notifications
You must be signed in to change notification settings - Fork 540
fix(tracing): Never send transactions if tracing is disabled #1328
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81d5a17
bail immediately in start_transaction and transaction.finish if traci…
lobsterkatie 92b99f4
allow traces_sample_rate to be 0 without it disabling tracing, disall…
lobsterkatie 2cde78d
handle the case of no transaction being created in CaptureExceptions …
lobsterkatie 58f68bd
warn rather than set sampling decision if tracing is disabled
lobsterkatie 1bf2da8
move use of parent_sampled value to method setting sampling decision
lobsterkatie a10fd1e
fix parsing of parent_sampled from sentry-trace value
lobsterkatie 525efb0
add and fix tests
lobsterkatie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,23 +17,23 @@ def call(env) | |
| scope.set_rack_env(env) | ||
|
|
||
| transaction = start_transaction(env, scope) | ||
| scope.set_span(transaction) | ||
| transaction ? scope.set_span(transaction) : nil | ||
|
|
||
| begin | ||
| response = @app.call(env) | ||
| rescue Sentry::Error | ||
| finish_transaction(transaction, 500) | ||
| transaction ? finish_transaction(transaction, 500) : nil | ||
|
lobsterkatie marked this conversation as resolved.
|
||
| raise # Don't capture Sentry errors | ||
| rescue Exception => e | ||
| capture_exception(e) | ||
| finish_transaction(transaction, 500) | ||
| transaction ? finish_transaction(transaction, 500) : nil | ||
| raise | ||
| end | ||
|
|
||
| exception = collect_exception(env) | ||
| capture_exception(exception) if exception | ||
|
|
||
| finish_transaction(transaction, response[0]) | ||
| transaction ? finish_transaction(transaction, response[0]) : nil | ||
|
|
||
| response | ||
| end | ||
|
|
@@ -54,13 +54,20 @@ def capture_exception(exception) | |
| end | ||
|
|
||
| def start_transaction(env, scope) | ||
| return unless Sentry.configuration.tracing_enabled? | ||
|
|
||
| sentry_trace = env["HTTP_SENTRY_TRACE"] | ||
| transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, name: scope.transaction_name, op: transaction_op) if sentry_trace | ||
| transaction || Sentry.start_transaction(name: scope.transaction_name, op: transaction_op) | ||
| options = {name: scope.transaction_name, op: transaction_op} | ||
|
|
||
| # if tracing is disabled, these will both return nil | ||
| transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, will adopt it in my PR 👍 |
||
| Sentry.start_transaction(transaction: transaction, **options) | ||
| end | ||
|
|
||
|
|
||
| def finish_transaction(transaction, status_code) | ||
| return unless transaction | ||
|
|
||
| transaction.set_http_status(status_code) | ||
| transaction.finish | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't need the return value from this line, it's not necessary to return the
nil. this should do the work tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is that formulation more idiomatic for Ruby? As someone coming from Python and JS/TS, having the condition after the action made my brain hurt a little, which is why I went with the ternary in the end. But if the
do x if ypattern is the accepted way, that's good to know. 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is a common practice in Ruby 😂 we're weirdos 😉