Skip to content

Commit d0b9346

Browse files
committed
Adding clarity on attributes instead of span metrics
1 parent befddb4 commit d0b9346

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

docs/concepts/key-terms/tracing/span-metrics.mdx

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,55 @@
11
---
22
title: Span Metrics
3-
description: "Learn how span metrics provide enhanced application performance monitoring by attaching attributes to trace spans."
3+
description: "Learn how attaching attributes to spans provides enhanced application performance monitoring and improved debugging."
44
sidebar_order: 10
55
---
66

7-
Span metrics enable you to attach metrics and important debugging context to your application's traces. This approach provides context-rich performance monitoring by connecting metrics directly to the operations that generate them.
7+
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.
88

9-
## What Are Span Metrics?
9+
These attributes allow you to enrich trace spans with attributes that represent various types of measurement data:
1010

11-
Span metrics allow you to enrich trace spans with various types of measurement data:
12-
13-
- Performance metrics (memory usage, processing time, latency)
11+
- Performance attributes (memory usage, processing time, latency)
1412
- Business metrics (transaction value, user engagement rates)
1513
- Technical indicators (queue depth, cache hit ratios)
1614
- Debugging context (input parameters, process states)
1715

18-
By attaching metrics directly to spans, you create a unified view of both the execution path and its associated performance data.
16+
By attaching attributes directly to spans, you create a unified view of both the execution path and its associated performance data.
1917

2018
```javascript
2119
// Adding performance metrics to a database span
22-
const span = Sentry.getActiveSpan();
23-
if (span) {
24-
span.setAttribute('db.rows_returned', 42);
25-
span.setAttribute('db.execution_time_ms', 18);
26-
}
20+
// Simple database query with dynamic attributes
21+
Sentry.startSpan(
22+
{
23+
name: 'Database Query',
24+
op: 'db.query'
25+
},
26+
() => {
27+
// Get active span to set attributes as data becomes available
28+
const span = Sentry.getActiveSpan();
29+
30+
// Execute query and add results to span
31+
const result = executeQuery('SELECT * FROM users WHERE active = true');
32+
33+
// Set attributes with the results data
34+
if (span) {
35+
span.setAttribute('db.rows_returned', result.length);
36+
span.setAttribute('db.execution_time_ms', result.executionTime);
37+
}
38+
39+
return result;
40+
}
41+
);
2742
```
2843

29-
## Benefits of Span Metrics
44+
## Benefits of Configuring Span Attributes
3045

3146
### Contextual Observability
3247

33-
Span metrics provide contextual data that connects execution flow with performance measurements. When investigating an issue, you can view both what occurred (the trace) and the performance characteristics (the metrics) in a single view.
48+
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.
3449

3550
### Unified Telemetry
3651

37-
By integrating metrics with 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.
52+
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.
3853

3954
```javascript
4055
// Adding business context to a payment processing span
@@ -57,44 +72,38 @@ Sentry.startSpan(
5772

5873
### Accelerated Troubleshooting
5974

60-
When performance issues arise, span metrics 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.
75+
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.
6176

6277
### Technical-Business Correlation
6378

64-
Span metrics 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.
79+
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.
6580

6681
## Implementation Approaches
6782

68-
There are two primary methods for implementing span metrics:
83+
There are two primary methods for implementing attributes on spans:
6984

7085
### 1. Enhancing Existing Spans
7186

72-
Augment automatically-created or manually-defined spans with additional metric attributes:
87+
Augment automatically-created or manually-defined spans with additional attributes:
7388

7489
```javascript
7590
// Adding metrics to an existing file upload span
7691
const span = Sentry.getActiveSpan();
7792
if (span) {
78-
// Performance metrics
79-
span.setAttribute('file.size_bytes', 15728640); // 15MB
80-
span.setAttribute('upload.time_ms', 3500);
81-
8293
// User context
8394
span.setAttribute('user.subscription_tier', 'premium');
84-
span.setAttribute('upload.type', 'profile_photo');
8595

8696
// Multiple metrics in a single operation
8797
span.setAttributes({
8898
'memory.heap_used': 1024000,
89-
'processing.steps_completed': 3,
9099
'processing.total_steps': 5
91100
});
92101
}
93102
```
94103

95104
### 2. Creating Dedicated Metric Spans
96105

97-
Create spans specifically for grouping related metrics, particularly useful for complex operations:
106+
Create spans specifically for grouping related attributes or metrics, particularly useful for complex operations:
98107

99108
```javascript
100109
// Creating a span for monitoring external API usage
@@ -105,11 +114,6 @@ Sentry.startSpan(
105114
attributes: {
106115
// Performance metrics
107116
'api.response_time_ms': 245,
108-
'api.rate_limit_remaining': 95,
109-
110-
// Resource usage tracking
111-
'api.calls_this_period': 1250,
112-
'api.cost_per_call': 0.001,
113117

114118
// Context data
115119
'feature.using_api': 'image_recognition',
@@ -124,7 +128,7 @@ Sentry.startSpan(
124128

125129
## Implementation Use Cases
126130

127-
The following examples demonstrate how span metrics can be applied to common application scenarios:
131+
The following examples demonstrate how attributes can be applied to common application scenarios:
128132

129133
### User Interface Performance
130134

@@ -238,15 +242,6 @@ Sentry.startSpan(
238242

239243
## Implementation Guidelines
240244

241-
### Getting Started
242-
243-
To implement span metrics in your application:
244-
245-
1. Ensure you have [properly configured tracing](/product/tracing/) in your application
246-
2. Identify key operations where performance or business metrics would provide valuable insights
247-
3. Determine whether to enhance existing spans or create dedicated metric spans
248-
4. Implement metrics iteratively, focusing on high-value areas first
249-
250245
### Best Practices
251246

252247
#### Metric Selection and Design
@@ -274,11 +269,11 @@ Be mindful of the performance impact of collecting metrics, especially for high-
274269

275270
## Migrating from Standalone Metrics
276271

277-
If you're currently using Sentry's standalone Metrics product, migrating to span metrics offers several advantages:
272+
If you're currently using Sentry's standalone Metrics product, migrating to span attributes offers several advantages:
278273

279-
- **Enhanced context**: Metrics are connected directly to the operations that generate them
274+
- **Enhanced context**: Attributes are connected directly to the operations that generate them
280275
- **Implementation efficiency**: A single consistent API for both traces and metrics
281-
- **Improved correlation**: Direct association between metrics, traces, and errors
276+
- **Improved correlation**: Direct association between attributes, traces, and errors
282277

283278
Migration process:
284279
1. Identify your current metric instrumentation points
@@ -290,9 +285,9 @@ Migration process:
290285

291286
For more detailed implementation examples, refer to these guides:
292287

293-
- [E-commerce transaction flow](/platforms/javascript/tracing/span-metrics/examples/#e-commerce-transaction-flow)
294-
- [File upload and processing](/platforms/javascript/tracing/span-metrics/examples/#file-upload-and-processing-pipeline)
288+
- [E-Commerce use case](/platforms/javascript/tracing/span-metrics/examples/#e-commerce-transaction-flow)
295289
- [LLM integration monitoring](/platforms/javascript/tracing/span-metrics/examples/#llm-integration-monitoring)
290+
- [File upload and processing](/platforms/javascript/tracing/span-metrics/examples/#file-upload-and-processing-pipeline)
296291
- [Job scheduling and processing](/platforms/javascript/tracing/span-metrics/examples/#job-scheduling-and-processing-pipeline)
297292

298-
These examples demonstrate how to implement comprehensive span metrics across distributed systems, providing end-to-end visibility into application performance and behavior.
293+
These examples demonstrate how to implement comprehensive attribute tracking across distributed systems, providing end-to-end visibility into application performance and behavior.

0 commit comments

Comments
 (0)