-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(dart, flutter): Add Attributes page #18779
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
Open
inventarSarah
wants to merge
4
commits into
master
Choose a base branch
from
smi/attributes/dart-flutter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
117 changes: 117 additions & 0 deletions
117
docs/platforms/dart/common/enriching-events/attributes/index.mdx
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,117 @@ | ||
| --- | ||
| title: Attributes | ||
| description: "Attributes automatically enrich your telemetry with typed key-value data. Use them to add business context that you can then filter and search in Sentry." | ||
| --- | ||
|
|
||
| <AvailableSince version="9.9.0" /> | ||
|
|
||
| **Attributes** are key-value pairs you can attach to your telemetry (like <PlatformLink to="/tracing/instrumentation/custom-instrumentation/">spans</PlatformLink> (SDK version `9.23.0`+), <PlatformLink to="/logs">logs</PlatformLink>, and <PlatformLink to="/metrics">metrics</PlatformLink>). | ||
|
|
||
| Common uses include subscription tier, feature flags, or any business context that helps you filter and query your telemetry. | ||
|
|
||
| Each attribute value is created with a typed `SentryAttribute` factory: | ||
|
|
||
| | Factory | Dart Type | | ||
|
Collaborator
Author
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. I'm considering removing this and instead add a link to the Streamed Spans page (or API docs if it's in there) - wdyt? |
||
| | -------------------------------- | -------------- | | ||
| | `SentryAttribute.string(v)` | `String` | | ||
| | `SentryAttribute.int(v)` | `int` | | ||
| | `SentryAttribute.bool(v)` | `bool` | | ||
| | `SentryAttribute.double(v)` | `double` | | ||
| | `SentryAttribute.stringArray(v)` | `List<String>` | | ||
| | `SentryAttribute.intArray(v)` | `List<int>` | | ||
| | `SentryAttribute.boolArray(v)` | `List<bool>` | | ||
| | `SentryAttribute.doubleArray(v)` | `List<double>` | | ||
|
|
||
| <Alert level="info"> | ||
|
|
||
| Attributes on spans require <PlatformLink to="/tracing/streamed-spans">stream mode</PlatformLink>. In stream mode, spans have no contexts, data, or tags — everything is a typed attribute, so `setData` and `setTag` are replaced by `setAttribute` and `setAttributes`. | ||
|
|
||
| Attributes on logs and metrics don't require stream mode and work by default. | ||
|
|
||
| </Alert> | ||
|
|
||
| ## Add Attributes to the Current Scope | ||
|
|
||
| Use `Sentry.setAttributes` to attach attributes to the current scope. This is the easiest way to enrich everything at once: | ||
|
|
||
| ```dart | ||
| Sentry.setAttributes({ | ||
| 'org_id': SentryAttribute.string(user.orgId), | ||
| 'user_tier': SentryAttribute.string(user.tier), | ||
| 'service': SentryAttribute.string('checkout'), | ||
| }); | ||
| ``` | ||
|
|
||
| ## Setting Attributes on Individual Telemetry | ||
|
|
||
| You can also attach attributes to a single span, log, or metric directly, which is useful when the data only makes sense for that one item. | ||
|
|
||
| ### Spans | ||
|
|
||
| In stream mode, you can set attributes when starting a span: | ||
|
|
||
| ```dart | ||
| await Sentry.startSpan( | ||
| 'process-order', | ||
| (_) async { | ||
| await processOrder(); | ||
| }, | ||
| attributes: { | ||
| 'sentry.op': SentryAttribute.string('queue.process'), | ||
| 'order.id': SentryAttribute.string('abc-123'), | ||
| 'order.item_count': SentryAttribute.int(5), | ||
| 'order.priority': SentryAttribute.bool(true), | ||
| }, | ||
| ); | ||
| ``` | ||
|
|
||
| Or add them to an already running span with `setAttribute` or `setAttributes`. Use `removeAttribute` to remove an attribute: | ||
|
|
||
| ```dart | ||
| await Sentry.startSpan('handle-request', (span) async { | ||
| span.setAttribute( | ||
| 'http.response.status_code', | ||
| SentryAttribute.int(200), | ||
| ); | ||
|
|
||
| span.setAttributes({ | ||
| 'http.route': SentryAttribute.string('/api/users'), | ||
| 'user.id': SentryAttribute.string('user-42'), | ||
| }); | ||
|
|
||
| await handleRequest(); | ||
| }); | ||
| ``` | ||
|
|
||
| See <PlatformLink to="/tracing/streamed-spans/#add-attributes">Add Attributes</PlatformLink> for more on span attributes. | ||
|
|
||
| ### Logs | ||
|
|
||
| Pass attributes to any `Sentry.logger` call: | ||
|
|
||
| ```dart | ||
| Sentry.logger.info('User ${user.username} added ${product.name} to cart.', attributes: { | ||
| 'user': SentryAttribute.string(user.username), | ||
| 'product': SentryAttribute.string(product.name), | ||
| }); | ||
| ``` | ||
|
|
||
| See <PlatformLink to ="/logs">Logs</PlatformLink> for more. | ||
|
|
||
| ### Metrics | ||
|
|
||
| Pass attributes in the `attributes` parameter of any metric. Each metric has a 2KB size limit for attributes: | ||
|
|
||
| ```dart | ||
| Sentry.metrics.count( | ||
| 'api_calls', | ||
| 1, | ||
| attributes: { | ||
| 'endpoint': SentryAttribute.string('/api/orders'), | ||
| 'user_tier': SentryAttribute.string('pro'), | ||
| 'region': SentryAttribute.string('us-west'), | ||
| }, | ||
| ); | ||
| ``` | ||
|
|
||
| See <PlatformLink to="/metrics">Metrics</PlatformLink> for more. | ||
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
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.
Bug: The
<AvailableSince>tag incorrectly states version9.9.0. Using attributes for logs or metrics requires SDK version9.23.0, creating a documentation conflict.Severity: MEDIUM
Suggested Fix
Update the
<AvailableSince version="9.9.0" />tag to reflect the correct minimum required version. Based on the context, the most restrictive and correct version appears to be9.23.0for using attributes with logs or metrics. Align the version number with the requirements stated in other parts of the documentation.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.