-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(python): update docs under Configuration for stream mode #18510
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -252,6 +252,45 @@ This function is called with a transaction event object, and can return a modifi | |||||
|
|
||||||
| </SdkOption> | ||||||
|
|
||||||
| <SdkOption name="_experiments.before_send_span" type='function' defaultValue='None' availableSince='2.62.0'> | ||||||
|
|
||||||
| <Alert> | ||||||
|
|
||||||
| Only available in <PlatformLink to="/tracing/new-spans">stream mode</PlatformLink>. | ||||||
|
|
||||||
| </Alert> | ||||||
|
|
||||||
| This function is called with a span event object and can return a modified span object. Use it, for example, to manually strip PII from spans or filter data from spans before they're sent to Sentry. It can only work with attributes set at span start time. Attributes added later during the span's lifetime are **not available**. | ||||||
|
|
||||||
| Note that `before_send_span` can only modify span data, meaning you cannot use it to drop spans. Use [`ignore_spans`](#_experiments.ignore_spans) to drop spans. | ||||||
|
|
||||||
| <Expandable title="Examples"> | ||||||
|
|
||||||
| ```python {tabTitle:Stream Mode} | ||||||
| import sentry_sdk | ||||||
|
|
||||||
| def before_send_span(span, hint): | ||||||
| # Runs once per span, as it's flushed. | ||||||
| # Only attributes set at span-creation time are available here. | ||||||
| span["attributes"].update({ | ||||||
| "component_version": "2.0.0", | ||||||
| "deployment_stage": "production", | ||||||
| }) | ||||||
| return span | ||||||
|
|
||||||
| sentry_sdk.init( | ||||||
| # ... | ||||||
| _experiments={ | ||||||
| "trace_lifecycle": "stream", | ||||||
| "before_send_span": before_send_span, | ||||||
| }, | ||||||
| ) | ||||||
| ``` | ||||||
|
|
||||||
| </Expandable> | ||||||
|
|
||||||
| </SdkOption> | ||||||
|
|
||||||
| <SdkOption name="before_breadcrumb" type='function' defaultValue='None'> | ||||||
|
|
||||||
| This function is called with a breadcrumb object before the breadcrumb is added to the scope. When nothing is returned from the function, the breadcrumb is dropped. To pass the breadcrumb through, return the first argument, which contains the breadcrumb object. | ||||||
|
|
@@ -356,7 +395,7 @@ sentry_sdk.init( | |||||
|
|
||||||
| <SdkOption name="traces_sample_rate" type='float' defaultValue='None'> | ||||||
|
|
||||||
| A number between `0` and `1`, controlling the percentage chance a given transaction will be sent to Sentry. (`0` represents 0% while `1` represents 100%.) Applies equally to all transactions created in the app. Either this or `traces_sampler` must be defined to enable tracing. | ||||||
| A number between `0` and `1`, controlling the percentage chance a given transaction (or service span in stream mode) will be sent to Sentry. (`0` represents 0% while `1` represents 100%.) Applies equally to all transactions and spans created in the app. Either this or `traces_sampler` must be defined to enable tracing. | ||||||
|
|
||||||
| If `traces_sample_rate` is `0`, this means that no new traces will be created. However, if you have another service (for example a JS frontend) that makes requests to your service that include trace information, those traces will be continued and thus transactions will be sent to Sentry. | ||||||
|
|
||||||
|
|
@@ -366,6 +405,70 @@ If you want to disable all tracing you need to set `traces_sample_rate=None`. In | |||||
|
|
||||||
| <PlatformContent includePath="/performance/traces-sampler-config-option" /> | ||||||
|
|
||||||
| <SdkOption name="_experiments.trace_lifecycle" type='string' defaultValue='"static"' availableSince='2.62.0'> | ||||||
|
|
||||||
| Controls how spans are sent to Sentry: | ||||||
|
|
||||||
| - In transaction mode (`"static"`, the default), all spans are collected in memory and sent to Sentry as a single transaction once the root span ends. | ||||||
| - In <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink> (`"stream"`), spans are sent in batches as they finish. | ||||||
|
|
||||||
| </SdkOption> | ||||||
|
|
||||||
| <SdkOption name="_experiments.ignore_spans" type='list[str | Pattern | dict]' defaultValue='[]' availableSince='2.62.0'> | ||||||
|
|
||||||
| <Alert> | ||||||
|
|
||||||
| Only available in <PlatformLink to="/tracing/new-spans">stream mode</PlatformLink>. | ||||||
|
|
||||||
| </Alert> | ||||||
|
|
||||||
| A list of strings, compiled regular expressions, or dictionaries that shouldn't be sent to Sentry. When using strings, a span name containing the string will be filtered out. For exact or more complex pattern matching, use compiled regular expressions instead. You can also provide a dictionary with `name` and/or `attributes` keys to match on multiple conditions. At least one key must be provided. | ||||||
|
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.
Suggested change
|
||||||
|
|
||||||
| If the dropped span is a service span, its children are dropped too. If it's a child span, only that span is dropped and its children are reparented to the nearest ancestor. | ||||||
| By default, no spans are ignored. | ||||||
|
|
||||||
| `ignoreSpans` is evaluated at span start, so only the span name and attributes available at that point are taken into account. Any name updates or additional attributes added while the span is active won't influence whether the span is dropped. | ||||||
|
|
||||||
| <Expandable title="Examples"> | ||||||
|
|
||||||
| ```python | ||||||
| import re | ||||||
| import sentry_sdk | ||||||
|
|
||||||
| sentry_sdk.init( | ||||||
| _experiments={ | ||||||
| "trace_lifecycle": "stream", | ||||||
| "ignore_spans": [ | ||||||
| # String match against span name | ||||||
| "/health", | ||||||
|
|
||||||
| # Regex match against span name | ||||||
| re.compile(r"/flow/.*"), | ||||||
|
|
||||||
| # Match by attributes (all must match) | ||||||
| { | ||||||
| "attributes": { | ||||||
| "service.id": "15def9a", | ||||||
| "flow.pipeline": "legacy", | ||||||
| } | ||||||
| }, | ||||||
|
|
||||||
| # Match by name and attributes | ||||||
| { | ||||||
| "name": re.compile(r"/flow/.*"), | ||||||
| "attributes": { | ||||||
| "service.id": re.compile(r".*\.facade"), | ||||||
| }, | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
| ) | ||||||
| ``` | ||||||
|
|
||||||
| </Expandable> | ||||||
|
|
||||||
| </SdkOption> | ||||||
|
|
||||||
| <SdkOption name="trace_propagation_targets" type='list' defaultValue="['.*']"> | ||||||
|
|
||||||
| An optional property that controls which downstream services receive tracing data, in the form of a `sentry-trace` and a `baggage` header attached to any outgoing HTTP requests. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,9 +45,19 @@ You can use the <PlatformIdentifier name="event-scrubber" /> configuration param | |||||||||
|
|
||||||||||
| <PlatformContent includePath="configuration/event-scrubber" /> | ||||||||||
|
|
||||||||||
| ### <PlatformIdentifier name="before-send" /> & <PlatformIdentifier name="before-send-transaction" /> | ||||||||||
| ### <PlatformIdentifier name="before-send" />, <PlatformIdentifier name="before-send-transaction" />, & <PlatformIdentifier name="before-send-span" /> | ||||||||||
|
|
||||||||||
| The SDK provides a <PlatformIdentifier name="before-send" /> hook, which is invoked before an error or message event is sent and can be used to modify event data to remove sensitive information. The SDK also provide a <PlatformIdentifier name="before-send-transaction" /> hook which does the same thing for transactions. We recommend using <PlatformIdentifier name="before-send" /> and <PlatformIdentifier name="before-send-transaction" /> in the SDK to **scrub any data before it is sent**, to ensure that sensitive data never leaves the local environment. | ||||||||||
| The SDK provides a <PlatformIdentifier name="before-send" /> hook, which is invoked before an error or message event is sent and can be used to modify event data to remove sensitive information. The SDK also provides a <PlatformIdentifier name="before-send-transaction" /> hook, that does the same thing for transactions, and a <PlatformIdentifier name="before-send-span" /> hook, that does the same thing for service spans in <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink>. We recommend using these hooks in the SDK to **scrub any data before it is sent**, to ensure that sensitive data never leaves the local environment. | ||||||||||
|
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. All spans pass through
Suggested change
|
||||||||||
|
|
||||||||||
| <Alert> | ||||||||||
|
|
||||||||||
| <PlatformIdentifier name="before-send-transaction" /> runs after the entire | ||||||||||
| transaction finishes, which means it has access to all data set during the | ||||||||||
| span's lifetime. In contrast, <PlatformIdentifier name="before-send-span" /> can | ||||||||||
| only work with attributes set at span start time. Attributes added later during | ||||||||||
| the span's lifetime aren't available. | ||||||||||
|
Comment on lines
+56
to
+58
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. Not true, you can remove the sentence 😄
Suggested change
|
||||||||||
|
|
||||||||||
| </Alert> | ||||||||||
|
|
||||||||||
| <PlatformContent includePath="configuration/before-send/" /> | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ```python | ||
| import sentry_sdk | ||
|
|
||
| def postprocess_span(span, hint): | ||
| attributes_to_sanitize = [ | ||
| "http.request.header.custom-auth", | ||
| "http.request.header.custom-user-id", | ||
| ] | ||
| for attribute in attributes_to_sanitize: | ||
| if span["attributes"].get(attribute): | ||
| span["attributes"][attribute] = "[Sanitized]" | ||
| return span | ||
|
|
||
| sentry_sdk.init( | ||
| _experiments={ | ||
| "trace_lifecycle": "stream", | ||
| "before_send_span": postprocess_span, | ||
| }, | ||
| ) | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ```python | ||
| ```python {tabTitle:Transaction Mode(Default)} | ||
| sentry_sdk.set_tag("birthday", checksum_or_hash("08/12/1990")) | ||
| ``` | ||
|
|
||
| ```python {tabTitle:Stream Mode} | ||
| sentry_sdk.set_attribute("birthday", checksum_or_hash("08/12/1990")) | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| ```python | ||
| ```python {tabTitle:Transaction Mode(Default)} | ||
| sentry_sdk.set_user({"id": user.id}) | ||
|
|
||
| # or | ||
|
|
||
| sentry_sdk.set_user({"username": user.username}) | ||
| ``` | ||
|
|
||
| ```python {tabTitle:Stream Mode} | ||
| sentry_sdk.set_attribute({"user.id": user.id}) | ||
|
|
||
| # or | ||
|
|
||
| sentry_sdk.set_attribute({"user.username": user.username}) | ||
| ``` |
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.
🐓