-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
JavaScript tracing docs refactor #12769
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
Merged
Changes from 48 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
7196311
Renaming distributed tracing, rearranging menu items. Changing tracin…
codyde 1e40d28
Adding better clarity on custom span vs adding attributes
codyde d1f10a1
Language fixes to tracing details
codyde a5cda2d
Adding additional examples and clarity
codyde 3778589
Iterating on redirect configs
codyde 39667b7
Enhancing example content for frontend and backend
codyde 61004bb
Updating example to replace API with job scheduler
codyde eac4137
Cleaning up example content
codyde 8547879
Update docs/platforms/javascript/common/tracing/span-metrics/index.mdx
codyde 6cfe9c3
renaming distributed tracing
codyde 7ae88c8
Moving and combining instrumentaiton section
codyde 470f072
Directory move for instrumentation
codyde 46f985e
reordering span metrics
codyde 5fccdbc
updates to redirects
codyde 00993d8
Merge branch 'codyde/javascript-tracing-refactor' of https://github.c…
codyde 2d8b1f3
Merge branch 'master' into codyde/javascript-tracing-refactor
codyde d86bf66
fixing missing /
codyde 07aca40
removing invalid redirect
codyde 4c01d7f
Adding missing redirects
codyde 91aa869
adding span metrics to explore; setting redirect from metrics
codyde 3216205
Merge branch 'master' into codyde/javascript-tracing-refactor
codyde 02fd7a5
Updating copy across tracing docs for clarify
codyde 6df7b6b
fixing redirect for span metrics
codyde 2640661
Update docs/platforms/javascript/common/tracing/index.mdx
codyde 0440714
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde d082d54
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde 8beca46
Update docs/platforms/javascript/common/tracing/index.mdx
codyde b6c4f13
Update docs/product/tracing/span-metrics/index.mdx
codyde e3f69c6
Update docs/platforms/javascript/common/tracing/span-metrics/index.mdx
codyde 3b05f16
Update docs/platforms/javascript/common/tracing/span-metrics/index.mdx
codyde e0810b3
Update docs/platforms/javascript/common/tracing/span-metrics/index.mdx
codyde 259c299
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde 7c0ba15
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde a89ff3e
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde 8c30c7a
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde 19f6635
Update docs/platforms/javascript/common/tracing/instrumentation/index…
codyde 758a14b
removing product traces docs; move to concepts
codyde 21f6c03
Merge branch 'codyde/javascript-tracing-refactor' of https://github.c…
codyde ef79e3c
Clarity updates in instrumentation docs
codyde befddb4
Adding clarity on attributes and span information
codyde d0b9346
Adding clarity on attributes instead of span metrics
codyde aff36d4
Adding clarity on attributes instead of span metrics
codyde b200fa1
Reordering distributed tracing for faster steps to configure
codyde ac7590d
Simplifying description of distributed tracing
codyde 2a7eb65
Removing profiling from this section
codyde 3c4795b
continued cleanup of instrumentation
codyde 91abaad
Adding sampling docs to tracing section
codyde 7f41731
Merge branch 'master' into codyde/javascript-tracing-refactor
codyde 7486a8e
Update docs/concepts/key-terms/tracing/index.mdx
codyde 8b6d9d5
Update docs/concepts/key-terms/tracing/index.mdx
codyde 2f02a37
Update docs/concepts/key-terms/tracing/index.mdx
codyde 40d021a
Update docs/concepts/key-terms/tracing/index.mdx
codyde 379b71d
Update docs/concepts/key-terms/tracing/index.mdx
codyde 50f1ba8
Update docs/concepts/key-terms/tracing/index.mdx
codyde ffb4cf8
Updates-Dist Tracing-Samples and configs
codyde dc0d9ba
Merge branch 'codyde/javascript-tracing-refactor' of https://github.c…
codyde 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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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,293 @@ | ||
| --- | ||
| title: Span Metrics | ||
| description: "Learn how attaching attributes to spans provides enhanced application performance monitoring and improved debugging." | ||
| sidebar_order: 10 | ||
| --- | ||
|
|
||
| Span metrics enable you to attach user defined attributes to spans, which might include application metrics or important debugging context within your application's traces. This approach provides context-rich performance monitoring by connecting attributes directly to the operations that generate them. | ||
|
|
||
| These attributes allow you to enrich trace spans with attributes that represent various types of measurement data: | ||
|
|
||
| - Performance attributes (memory usage, processing time, latency) | ||
| - Business metrics (transaction value, user engagement rates) | ||
| - Technical indicators (queue depth, cache hit ratios) | ||
| - Debugging context (input parameters, process states) | ||
|
|
||
| By attaching attributes directly to spans, you create a unified view of both the execution path and its associated performance data. | ||
|
|
||
| ```javascript | ||
| // Adding performance metrics to a database span | ||
| // Simple database query with dynamic attributes | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Database Query', | ||
| op: 'db.query' | ||
| }, | ||
| () => { | ||
| // Get active span to set attributes as data becomes available | ||
| const span = Sentry.getActiveSpan(); | ||
|
|
||
| // Execute query and add results to span | ||
| const result = executeQuery('SELECT * FROM users WHERE active = true'); | ||
|
|
||
| // Set attributes with the results data | ||
| if (span) { | ||
| span.setAttribute('db.rows_returned', result.length); | ||
| span.setAttribute('db.execution_time_ms', result.executionTime); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## Benefits of Configuring Span Attributes | ||
|
|
||
| ### Contextual Observability | ||
|
|
||
| Span attributes provide contextual data that connects execution flow with specific metrics that developers care about, or performance measurements. When investigating an issue, you can view both what occurred (the trace) and the performance characteristics in a single view. | ||
|
|
||
| ### Unified Telemetry | ||
|
|
||
| By integrating these attributes into tracing, you can maintain a single telemetry pipeline rather than managing separate systems for traces and metrics, resulting in simplified instrumentation and more efficient monitoring. | ||
|
|
||
| ```javascript | ||
| // Adding business context to a payment processing span | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Process Payment', | ||
| op: 'payment.process', | ||
| attributes: { | ||
| 'payment.amount': 99.99, | ||
| 'payment.currency': 'USD', | ||
| 'payment.method': 'credit_card', | ||
| 'customer.type': 'returning' | ||
| } | ||
| }, | ||
| async () => { | ||
| // Payment processing implementation | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### Accelerated Troubleshooting | ||
|
|
||
| When performance issues arise, these attributes provide the necessary context to quickly identify bottlenecks. For example, when investigating slow checkout processes, you can immediately see which specific component (payment gateway, database query, third-party API) is causing the delay. | ||
|
|
||
| ### Technical-Business Correlation | ||
|
|
||
| Span attributes enable correlation between technical performance data and business outcomes by connecting metrics like response time or error rates directly to business metrics such as conversion rates or revenue. | ||
|
|
||
| ## Implementation Approaches | ||
|
|
||
| There are two primary methods for implementing attributes on spans: | ||
|
|
||
| ### 1. Enhancing Existing Spans | ||
|
|
||
| Augment automatically-created or manually-defined spans with additional attributes: | ||
|
|
||
| ```javascript | ||
| // Adding metrics to an existing file upload span | ||
| const span = Sentry.getActiveSpan(); | ||
| if (span) { | ||
| // User context | ||
| span.setAttribute('user.subscription_tier', 'premium'); | ||
|
|
||
| // Multiple metrics in a single operation | ||
| span.setAttributes({ | ||
| 'memory.heap_used': 1024000, | ||
| 'processing.total_steps': 5 | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ### 2. Creating Dedicated Metric Spans | ||
|
|
||
| Create spans specifically for grouping related attributes or metrics, particularly useful for complex operations: | ||
|
|
||
| ```javascript | ||
| // Creating a span for monitoring external API usage | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Third-Party API Usage', | ||
| op: 'external.api', | ||
| attributes: { | ||
| // Performance metrics | ||
| 'api.response_time_ms': 245, | ||
|
|
||
| // Context data | ||
| 'feature.using_api': 'image_recognition', | ||
| 'user.plan': 'enterprise' | ||
| } | ||
| }, | ||
| async () => { | ||
| // API call implementation | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## Implementation Use Cases | ||
|
|
||
| The following examples demonstrate how attributes can be applied to common application scenarios: | ||
|
|
||
| ### User Interface Performance | ||
|
|
||
| Monitor client-side performance metrics related to user experience: | ||
|
|
||
| ```javascript | ||
| // UI performance monitoring | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Page Interaction', | ||
| op: 'ui.interaction', | ||
| attributes: { | ||
| 'ui.first_input_delay_ms': 24, | ||
| 'ui.time_to_interactive_ms': 320, | ||
| 'ui.frames_dropped': 0, | ||
| 'user.device_type': 'mobile', | ||
| 'feature.being_used': 'image_carousel' | ||
| } | ||
| }, | ||
| async () => { | ||
| // UI interaction handling | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### Database Operation Monitoring | ||
|
|
||
| Track database performance characteristics and their impact on application behavior: | ||
|
|
||
| ```javascript | ||
| // Database query monitoring | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Product Search Query', | ||
| op: 'db.query', | ||
| attributes: { | ||
| 'db.query_type': 'SELECT', | ||
| 'db.table': 'products', | ||
| 'db.execution_time_ms': 145, | ||
| 'db.rows_returned': 87, | ||
| 'db.index_used': 'product_category_idx', | ||
| 'business.search_term': 'winter jacket', | ||
| 'business.search_filters_applied': 3 | ||
| } | ||
| }, | ||
| async () => { | ||
| // Database query execution | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### File Processing Operations | ||
|
|
||
| Monitor file handling operations across your application stack: | ||
|
|
||
| ```javascript | ||
| // File processing monitoring | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Process Uploaded Image', | ||
| op: 'file.process', | ||
| attributes: { | ||
| // Technical metrics | ||
| 'file.size_bytes': 2500000, | ||
| 'file.type': 'image/jpeg', | ||
|
|
||
| // Processing metrics | ||
| 'processing.steps_completed': ['virus_scan', 'resize', 'compress'], | ||
| 'processing.total_time_ms': 850, | ||
|
|
||
| // Context data | ||
| 'feature.using_upload': 'user_avatar', | ||
| 'subscription.allows_hd': true | ||
| } | ||
| }, | ||
| async () => { | ||
| // Image processing implementation | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### External Service Integration | ||
|
|
||
| Monitor performance and reliability of third-party service interactions: | ||
|
|
||
| ```javascript | ||
| // Payment gateway monitoring | ||
| Sentry.startSpan( | ||
| { | ||
| name: 'Payment Gateway', | ||
| op: 'payment.gateway', | ||
| attributes: { | ||
| // Performance metrics | ||
| 'gateway.response_time_ms': 980, | ||
| 'gateway.retry_count': 0, | ||
|
|
||
| // Transaction data | ||
| 'order.total_amount': 159.99, | ||
| 'order.items_count': 3, | ||
|
|
||
| // Service metrics | ||
| 'gateway.fee_amount': 4.50, | ||
| 'gateway.fee_percent': 0.029 | ||
| } | ||
| }, | ||
| async () => { | ||
| // Payment gateway integration | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## Implementation Guidelines | ||
|
|
||
| ### Best Practices | ||
|
|
||
| #### Metric Selection and Design | ||
|
|
||
| Select metrics that provide actionable insights for debugging or performance monitoring. Consider which data points would help diagnose issues or make informed decisions about your application. | ||
|
|
||
| #### Naming Conventions | ||
|
|
||
| Maintain consistent naming patterns following the format `category.metric_name` to ensure metrics are discoverable and understandable across your organization. | ||
|
|
||
| #### Data Type Selection | ||
|
|
||
| Choose appropriate data types for your metrics: | ||
| - Numeric values for measurements (`response_time_ms`: 250) | ||
| - Boolean values for state indicators (`cache.hit`: true) | ||
| - String values for categorical data (`user.subscription`: 'premium') | ||
| - Arrays for multi-value data (`processing.steps_completed`: ['download', 'process', 'upload']) | ||
|
|
||
| #### Performance Considerations | ||
|
|
||
| Be mindful of the performance impact of collecting metrics, especially for high-volume operations: | ||
| - Consider implementing sampling for high-frequency operations | ||
| - Prioritize metrics with the highest analytical value | ||
| - Avoid redundant or closely correlated metrics | ||
|
|
||
| ## Migrating from Standalone Metrics | ||
|
|
||
| If you're currently using Sentry's standalone Metrics product, migrating to span attributes offers several advantages: | ||
|
|
||
| - **Enhanced context**: Attributes are connected directly to the operations that generate them | ||
| - **Implementation efficiency**: A single consistent API for both traces and metrics | ||
| - **Improved correlation**: Direct association between attributes, traces, and errors | ||
|
|
||
| Migration process: | ||
| 1. Identify your current metric instrumentation points | ||
| 2. Locate corresponding spans in your application | ||
| 3. Transfer your metrics to span attributes | ||
| 4. Update any dashboards or alerts to reference the new metric sources | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| For more detailed implementation examples, refer to these guides: | ||
|
|
||
| - [E-Commerce use case](/platforms/javascript/tracing/span-metrics/examples/#e-commerce-transaction-flow) | ||
| - [LLM integration monitoring](/platforms/javascript/tracing/span-metrics/examples/#llm-integration-monitoring) | ||
| - [File upload and processing](/platforms/javascript/tracing/span-metrics/examples/#file-upload-and-processing-pipeline) | ||
| - [Job scheduling and processing](/platforms/javascript/tracing/span-metrics/examples/#job-scheduling-and-processing-pipeline) | ||
|
|
||
| These examples demonstrate how to implement comprehensive attribute tracking across distributed systems, providing end-to-end visibility into application performance and behavior. |
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.