-
Notifications
You must be signed in to change notification settings - Fork 569
feat(api): Add Scope.set_attribute
#5256
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
Merged
+281
−13
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
270be59
ref: Make logs, metrics go via scope
sentrivana c46c32d
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana 9be698f
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana ddb5838
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana 329ea2c
typing fixes
sentrivana 6c1897a
giving up on typing dispatches
sentrivana 8ffc78a
span_id is not an attribute anymore
sentrivana 2405282
move format_attributes to utils
sentrivana a0a603b
attr list values
sentrivana a2fee7c
.
sentrivana 87537f0
add link
sentrivana 8c32833
remove custom trace_id, span_id setting
sentrivana 3747c5f
rename, fix
sentrivana 4dc5dd8
.
sentrivana 6acb510
simplify
sentrivana 2bf0f3a
.
sentrivana 52bcfee
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana c83d76c
.
sentrivana a62d90b
first attrs, then before_send
sentrivana 649c3ad
dont pass opts around
sentrivana 3fffa7f
simplify dispatcher
sentrivana 7ccbd5a
no support for array attributes yet
sentrivana d2cbf74
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana 3814f3b
feat: Add scope.set_attribute
sentrivana 9d8b3d2
put preserialization back
sentrivana e92c9d3
dont override
sentrivana 0b25f46
preserialize after template, parameters
sentrivana 3eac621
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana ef5f9fb
fix
sentrivana a56ff9b
Merge branch 'ivana/make-logs-and-metrics-go-via-scope' into ivana/sc…
sentrivana 4ac20db
use format_attr in other places too
sentrivana 4b8047a
.
sentrivana 7154196
keyboard
sentrivana 603da41
Merge branch 'master' into ivana/make-logs-and-metrics-go-via-scope
sentrivana 5ba6bcb
Merge branch 'ivana/make-logs-and-metrics-go-via-scope' into ivana/sc…
sentrivana cea7d21
i am very smart
sentrivana 1609dec
Merge branch 'master' into ivana/scope-set-attributes
sentrivana 5aec76c
merge botched
sentrivana 641214c
issues
sentrivana a3714b0
add missing 3.7 decorators in logs tests
sentrivana 5ad9df4
docstrings
sentrivana 7c3da6e
.
sentrivana b858bec
apply global attrs last, conditionally
sentrivana 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
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 |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import sentry_sdk | ||
|
|
||
| from tests.test_metrics import envelopes_to_metrics | ||
|
|
||
|
|
||
| def test_scope_precedence(sentry_init, capture_envelopes): | ||
| # Order of precedence, from most important to least: | ||
| # 1. telemetry attributes (directly supplying attributes on creation or using set_attribute) | ||
| # 2. current scope attributes | ||
| # 3. isolation scope attributes | ||
| # 4. global scope attributes | ||
| sentry_init() | ||
|
|
||
| envelopes = capture_envelopes() | ||
|
|
||
| global_scope = sentry_sdk.get_global_scope() | ||
| global_scope.set_attribute("global.attribute", "global") | ||
| global_scope.set_attribute("overwritten.attribute", "global") | ||
|
|
||
| isolation_scope = sentry_sdk.get_isolation_scope() | ||
| isolation_scope.set_attribute("isolation.attribute", "isolation") | ||
| isolation_scope.set_attribute("overwritten.attribute", "isolation") | ||
|
|
||
| current_scope = sentry_sdk.get_current_scope() | ||
| current_scope.set_attribute("current.attribute", "current") | ||
| current_scope.set_attribute("overwritten.attribute", "current") | ||
|
|
||
| sentry_sdk.metrics.count("test", 1) | ||
| sentry_sdk.get_client().flush() | ||
|
|
||
| metrics = envelopes_to_metrics(envelopes) | ||
| (metric,) = metrics | ||
|
|
||
| assert metric["attributes"]["global.attribute"] == "global" | ||
| assert metric["attributes"]["isolation.attribute"] == "isolation" | ||
| assert metric["attributes"]["current.attribute"] == "current" | ||
|
|
||
| assert metric["attributes"]["overwritten.attribute"] == "current" | ||
|
|
||
|
|
||
| def test_telemetry_precedence(sentry_init, capture_envelopes): | ||
| # Order of precedence, from most important to least: | ||
| # 1. telemetry attributes (directly supplying attributes on creation or using set_attribute) | ||
| # 2. current scope attributes | ||
| # 3. isolation scope attributes | ||
| # 4. global scope attributes | ||
| sentry_init() | ||
|
|
||
| envelopes = capture_envelopes() | ||
|
|
||
| global_scope = sentry_sdk.get_global_scope() | ||
| global_scope.set_attribute("global.attribute", "global") | ||
| global_scope.set_attribute("overwritten.attribute", "global") | ||
|
|
||
| isolation_scope = sentry_sdk.get_isolation_scope() | ||
| isolation_scope.set_attribute("isolation.attribute", "isolation") | ||
| isolation_scope.set_attribute("overwritten.attribute", "isolation") | ||
|
|
||
| current_scope = sentry_sdk.get_current_scope() | ||
| current_scope.set_attribute("current.attribute", "current") | ||
| current_scope.set_attribute("overwritten.attribute", "current") | ||
|
|
||
| sentry_sdk.metrics.count( | ||
| "test", | ||
| 1, | ||
| attributes={ | ||
| "telemetry.attribute": "telemetry", | ||
| "overwritten.attribute": "telemetry", | ||
| }, | ||
| ) | ||
|
|
||
| sentry_sdk.get_client().flush() | ||
|
|
||
| metrics = envelopes_to_metrics(envelopes) | ||
| (metric,) = metrics | ||
|
|
||
| assert metric["attributes"]["global.attribute"] == "global" | ||
| assert metric["attributes"]["isolation.attribute"] == "isolation" | ||
| assert metric["attributes"]["current.attribute"] == "current" | ||
| assert metric["attributes"]["telemetry.attribute"] == "telemetry" | ||
|
|
||
| assert metric["attributes"]["overwritten.attribute"] == "telemetry" | ||
|
|
||
|
|
||
| def test_attribute_out_of_scope(sentry_init, capture_envelopes): | ||
| sentry_init() | ||
|
|
||
| envelopes = capture_envelopes() | ||
|
|
||
| with sentry_sdk.new_scope() as scope: | ||
| scope.set_attribute("outofscope.attribute", "out of scope") | ||
|
|
||
| sentry_sdk.metrics.count("test", 1) | ||
|
|
||
| sentry_sdk.get_client().flush() | ||
|
|
||
| metrics = envelopes_to_metrics(envelopes) | ||
| (metric,) = metrics | ||
|
|
||
| assert "outofscope.attribute" not in metric["attributes"] | ||
|
|
||
|
|
||
| def test_remove_attribute(sentry_init, capture_envelopes): | ||
| sentry_init() | ||
|
|
||
| envelopes = capture_envelopes() | ||
|
|
||
| with sentry_sdk.new_scope() as scope: | ||
| scope.set_attribute("some.attribute", 123) | ||
| scope.remove_attribute("some.attribute") | ||
|
|
||
| sentry_sdk.metrics.count("test", 1) | ||
|
|
||
| sentry_sdk.get_client().flush() | ||
|
|
||
| metrics = envelopes_to_metrics(envelopes) | ||
| (metric,) = metrics | ||
|
|
||
| assert "some.attribute" not in metric["attributes"] |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.