Skip to content

Commit 9e6858a

Browse files
committed
Merge remote-tracking branch 'origin/master' into lforst-tanstack-start
2 parents 01fc2ef + a5ba2eb commit 9e6858a

File tree

82 files changed

+2708
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2708
-472
lines changed

develop-docs/frontend/network-requests.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Reusable queries like this can be placed in `/sentry/actionsCreators`.
142142
There are many situations where your query data becomes out of date and needs to be updated or refetched. This is usually because of some user input (e.g. creating/deleting/editing a record). If you already know what the new data should look like, you can (and should) immediately update the cache using the query client:
143143

144144
```tsx
145-
import {setQueryData, queryClient} from 'utils/queryClient'
145+
import {setQueryData, useQueryClient} from 'utils/queryClient'
146146

147147
const queryClient = useQueryClient();
148148

docs/concepts/key-terms/tracing/distributed-tracing.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Distributed Tracing
3-
sidebar_order: 10
3+
sidebar_order: 20
44
description: With distributed tracing, you can track software performance and measure throughput & latency, while seeing the impact of errors across multiple systems.
55
---
66

docs/concepts/key-terms/tracing/index.mdx

+65-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,73 @@ sidebar_order: 70
44
description: "Learn more about the tracing features Sentry offers to help you track your software performance across multiple systems."
55
---
66

7-
[Distributed tracing](/product/sentry-basics/tracing/distributed-tracing/) provides a connected view of related errors and transactions by capturing interactions among your software systems. With tracing, Sentry tracks your software performance and displays the impact of errors across multiple systems. Tracing issues back through services connects your front-end to your back-end.
7+
## What's Tracing?
88

9-
The [Trace View](/product/sentry-basics/tracing/trace-view/) allows you to drill down into the details of a single trace and traverse every transaction in that trace. This accelerates your ability to debug slow services, identify related errors, and root out other bottlenecks.
9+
Tracing involves capturing the timing and flow of requests and operations as they happen in your application. This powerful debugging tool helps you identify which link in a sequence of events may be causing a problem, such as slow performance.
1010

11-
The [Trace Explorer](/product/explore/traces/) allows you to explore traces by querying [span properties](/concepts/search/searchable-properties/spans/). This helps you find relevant distributed traces that will give you more information to debug and optimize your code.
11+
![An illustrated image of the anatomy of a trace, showing 8 span blocks cascading in a waterfall pattern.](./img/The-anatomy-of-a-trace.png)
12+
13+
### What's Distributed Tracing?
14+
15+
Distributed tracing provides a unified view of how a single request moves from the frontend to the backend and beyond. This is particularly useful in modern applications, which are often composed of multiple separate services working together. To get a distributed view of your application, instrument Sentry in both your frontend and your backend.
16+
17+
With [distributed tracing](/concepts/key-terms/tracing/distributed-tracing/), you can identify performance bottlenecks that are affecting your application across different services and platforms. You can then use Sentry tools such as the [Trace Explorer](/product/explore/traces/) or [Trace View](/concepts/key-terms/tracing/trace-view/) page to dig deeper and find the root cause of the problem. Distributed tracing is particularly helpful for identifying problems that take place between multiple services that you can't debug using console logs, such as race conditions, [N+1 queries](/product/issues/issue-details/performance-issues/n-one-queries/), and [caching issues](/product/insights/caches/).
18+
19+
### What's a Trace?
20+
21+
A trace is a record of a series of connected events and operations coming from your application. Each trace has a string of globally unique characters called a trace ID that's passed between frontend and backend services. The trace ID connects all the actions that take place, starting from the moment a user performs an action on the frontend, all the way through to the actions this triggers across your application and services. Each trace is composed of multiple spans.
22+
23+
### What's a Span?
24+
25+
A span is a named, timed operation that represents a part of the application workflow. The data captured for each span provides granular insights into specific tasks, like API requests or database queries. Multiple spans are pieced together to create a trace, providing a comprehensive overview of how your application works. This makes it easier to troubleshoot and analyze performance issues.
26+
27+
### What are Span Attributes and Metrics?
28+
29+
Span attributes and metrics are key pieces of information that are captured for each span. Attributes are key-value pairs that provide additional context about the span, such as the name of the operation or the user ID. Metrics are numerical values that measure the performance of the span, such as the duration of the operation or the number of database queries.
30+
31+
### What's a Transaction?
32+
33+
In Sentry, a "transaction" is a specific unit that represents any event that your application sends to Sentry, like loading a web page or processing an API call. Each transaction is made up of one or more spans. Transactions have a unique transaction ID and include the associated child spans that capture the operation’s entire process from start to finish.
34+
35+
## How to Use Tracing in Sentry
36+
37+
If you instrument Sentry for a single part of your app (just the frontend for example), looking at a trace will provide useful context for debugging issues within that app or service. But to get the most out of tracing in Sentry, you'll need to instrument the frontend, the backend, and any services in-between with Sentry's SDK. Once this is done, there are several places where you can view and interact with tracing data:
38+
39+
### Traces to Trace View
40+
41+
You can view all the traces in your organization by going to the [Traces](https://sentry.io/orgredirect/organizations/:orgslug/traces/) page in Sentry. You'll see a chart and a list of traces letting you know how long each trace took to complete and the number of spans it contains.
42+
43+
![A view of the Sentry Traces page showing traces and spans](./img/Traces-page.png)
44+
45+
If you want more information, click on any trace ID. This will take you to the [Trace View](/concepts/key-terms/tracing/trace-view/) page, which provides a more detailed view of the trace and its spans. Here, you'll see a waterfall view of the spans in the trace, which will show you how much time each service and operation took to complete, and may give you an indicator of where a problem may originate.
46+
47+
![A detailed view of the Senty Traces page showing an expaned trace and spans](./img/Trace-view-page.png)
48+
49+
Alternatively, you can use the search bar to look for spans by name, project, or other criteria. You can also use the tags section to filter spans by specific tags. Learn more about the Sentry [Trace Explorer](/product/explore/traces/).
50+
51+
![An illustrated image of the anatomy of a trace, showing 8 span blocks cascading in a waterfall pattern.](./img/Traces-details-page.png)
52+
53+
### Performance to Trace View
54+
55+
Depending on the size and volume of your app, you may have a lot of traces to sort through. The [Insights](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/) page in Sentry is a good place to get a high-level, aggregated view of your application's performance and focus in on the traces you care about. You'll see a list of transactions for specific pages, endpoints and parts of your application. Clicking on the transaction ID will take you to the Trace View page for that transaction. Learn more about using Sentry's [Insights](/product/insights/).
56+
57+
![An overview of the Performance page in Sentry.](./img/Performance-page.png)
58+
59+
## How Tracing Can Help You Debug
60+
61+
Sentry’s tracing lets you follow each request across various services, databases, and functions. This makes it easier to find exactly when and where an error occurred or a performance bottleneck started. Below, you'll find some real-world scenarios where tracing saved the day.
62+
63+
### Debug Slowdowns Across Your Integrations
64+
65+
When debugging integrations or a microservice architecture, you'll likely run into issues where the root cause is tricky to discover, especially when it's a performance issue. At Sentry, we make sure to add spans whenever we’re working with external services, like Slack. Because of this, when our users started experiencing a 4-second delay in receiving Sentry alerts via Slack, we were able to go to the [Trace View](/concepts/key-terms/tracing/trace-view/) and quickly narrow down which task was causing the slowdown and deploy a fix quickly. Read more about the details of [debugging Sentry’s Slack Integration](https://blog.sentry.io/debugging-a-slack-integration-with-sentrys-trace-view/).
66+
67+
### Improve Core Web Vitals
68+
69+
While everyone is sharing Lighthouse scores, we all know that the true determination of healthy web vitals is when your actual users are using your application in their authentic environments. Sentry offers real insights and analysis of your application in the real world, and while tracing can be leveraged to reactively solve issues, you can also use it to proactively discover opportunities to improve your application performance. In fact, this blog post describes [how you can improve performance before your web page even loads](https://blog.sentry.io/how-to-make-your-web-page-faster-before-it-even-loads/).
70+
71+
### Debug New Code Bases Faster
72+
73+
Tracing can even give you the power to debug unfamiliar codebases. Although this benefit is not often discussed, a lot of time can be saved when debugging applications instrumented with Tracing, even if the codebase is completely new to you. Being able to trace actual user journeys throughout your application and see what happens across your entire stack contextualizes issues without even needing to recreate the issue locally. Read about other ways [tracing helps developers debug various issues](https://blog.sentry.io/everyone-needs-to-know-how-to-trace/).
1274

1375
## Learn More
1476

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
---
2+
title: Span Metrics
3+
description: "Learn how attaching attributes to spans provides enhanced application performance monitoring and improved debugging."
4+
sidebar_order: 10
5+
---
6+
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.
8+
9+
These attributes allow you to enrich trace spans with attributes that represent various types of measurement data:
10+
11+
- Performance attributes (memory usage, processing time, latency)
12+
- Business metrics (transaction value, user engagement rates)
13+
- Technical indicators (queue depth, cache hit ratios)
14+
- Debugging context (input parameters, process states)
15+
16+
By attaching attributes directly to spans, you create a unified view of both the execution path and its associated performance data.
17+
18+
```javascript
19+
// Adding performance metrics to a database span
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+
);
42+
```
43+
44+
## Benefits of Configuring Span Attributes
45+
46+
### Contextual Observability
47+
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.
49+
50+
### Unified Telemetry
51+
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.
53+
54+
```javascript
55+
// Adding business context to a payment processing span
56+
Sentry.startSpan(
57+
{
58+
name: 'Process Payment',
59+
op: 'payment.process',
60+
attributes: {
61+
'payment.amount': 99.99,
62+
'payment.currency': 'USD',
63+
'payment.method': 'credit_card',
64+
'customer.type': 'returning'
65+
}
66+
},
67+
async () => {
68+
// Payment processing implementation
69+
}
70+
);
71+
```
72+
73+
### Accelerated Troubleshooting
74+
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.
76+
77+
### Technical-Business Correlation
78+
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.
80+
81+
## Implementation Approaches
82+
83+
There are two primary methods for implementing attributes on spans:
84+
85+
### 1. Enhancing Existing Spans
86+
87+
Augment automatically-created or manually-defined spans with additional attributes:
88+
89+
```javascript
90+
// Adding metrics to an existing file upload span
91+
const span = Sentry.getActiveSpan();
92+
if (span) {
93+
// User context
94+
span.setAttribute('user.subscription_tier', 'premium');
95+
96+
// Multiple metrics in a single operation
97+
span.setAttributes({
98+
'memory.heap_used': 1024000,
99+
'processing.total_steps': 5
100+
});
101+
}
102+
```
103+
104+
### 2. Creating Dedicated Metric Spans
105+
106+
Create spans specifically for grouping related attributes or metrics, particularly useful for complex operations:
107+
108+
```javascript
109+
// Creating a span for monitoring external API usage
110+
Sentry.startSpan(
111+
{
112+
name: 'Third-Party API Usage',
113+
op: 'external.api',
114+
attributes: {
115+
// Performance metrics
116+
'api.response_time_ms': 245,
117+
118+
// Context data
119+
'feature.using_api': 'image_recognition',
120+
'user.plan': 'enterprise'
121+
}
122+
},
123+
async () => {
124+
// API call implementation
125+
}
126+
);
127+
```
128+
129+
## Implementation Use Cases
130+
131+
The following examples demonstrate how attributes can be applied to common application scenarios:
132+
133+
### User Interface Performance
134+
135+
Monitor client-side performance metrics related to user experience:
136+
137+
```javascript
138+
// UI performance monitoring
139+
Sentry.startSpan(
140+
{
141+
name: 'Page Interaction',
142+
op: 'ui.interaction',
143+
attributes: {
144+
'ui.first_input_delay_ms': 24,
145+
'ui.time_to_interactive_ms': 320,
146+
'ui.frames_dropped': 0,
147+
'user.device_type': 'mobile',
148+
'feature.being_used': 'image_carousel'
149+
}
150+
},
151+
async () => {
152+
// UI interaction handling
153+
}
154+
);
155+
```
156+
157+
### Database Operation Monitoring
158+
159+
Track database performance characteristics and their impact on application behavior:
160+
161+
```javascript
162+
// Database query monitoring
163+
Sentry.startSpan(
164+
{
165+
name: 'Product Search Query',
166+
op: 'db.query',
167+
attributes: {
168+
'db.query_type': 'SELECT',
169+
'db.table': 'products',
170+
'db.execution_time_ms': 145,
171+
'db.rows_returned': 87,
172+
'db.index_used': 'product_category_idx',
173+
'business.search_term': 'winter jacket',
174+
'business.search_filters_applied': 3
175+
}
176+
},
177+
async () => {
178+
// Database query execution
179+
}
180+
);
181+
```
182+
183+
### File Processing Operations
184+
185+
Monitor file handling operations across your application stack:
186+
187+
```javascript
188+
// File processing monitoring
189+
Sentry.startSpan(
190+
{
191+
name: 'Process Uploaded Image',
192+
op: 'file.process',
193+
attributes: {
194+
// Technical metrics
195+
'file.size_bytes': 2500000,
196+
'file.type': 'image/jpeg',
197+
198+
// Processing metrics
199+
'processing.steps_completed': ['virus_scan', 'resize', 'compress'],
200+
'processing.total_time_ms': 850,
201+
202+
// Context data
203+
'feature.using_upload': 'user_avatar',
204+
'subscription.allows_hd': true
205+
}
206+
},
207+
async () => {
208+
// Image processing implementation
209+
}
210+
);
211+
```
212+
213+
### External Service Integration
214+
215+
Monitor performance and reliability of third-party service interactions:
216+
217+
```javascript
218+
// Payment gateway monitoring
219+
Sentry.startSpan(
220+
{
221+
name: 'Payment Gateway',
222+
op: 'payment.gateway',
223+
attributes: {
224+
// Performance metrics
225+
'gateway.response_time_ms': 980,
226+
'gateway.retry_count': 0,
227+
228+
// Transaction data
229+
'order.total_amount': 159.99,
230+
'order.items_count': 3,
231+
232+
// Service metrics
233+
'gateway.fee_amount': 4.50,
234+
'gateway.fee_percent': 0.029
235+
}
236+
},
237+
async () => {
238+
// Payment gateway integration
239+
}
240+
);
241+
```
242+
243+
## Implementation Guidelines
244+
245+
### Best Practices
246+
247+
#### Metric Selection and Design
248+
249+
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.
250+
251+
#### Naming Conventions
252+
253+
Maintain consistent naming patterns following the format `category.metric_name` to ensure metrics are discoverable and understandable across your organization.
254+
255+
#### Data Type Selection
256+
257+
Choose appropriate data types for your metrics:
258+
- Numeric values for measurements (`response_time_ms`: 250)
259+
- Boolean values for state indicators (`cache.hit`: true)
260+
- String values for categorical data (`user.subscription`: 'premium')
261+
- Arrays for multi-value data (`processing.steps_completed`: ['download', 'process', 'upload'])
262+
263+
#### Performance Considerations
264+
265+
Be mindful of the performance impact of collecting metrics, especially for high-volume operations:
266+
- Consider implementing sampling for high-frequency operations
267+
- Prioritize metrics with the highest analytical value
268+
- Avoid redundant or closely correlated metrics
269+
270+
## Migrating from Standalone Metrics
271+
272+
If you're currently using Sentry's standalone Metrics product, migrating to span attributes offers several advantages:
273+
274+
- **Enhanced context**: Attributes are connected directly to the operations that generate them
275+
- **Implementation efficiency**: A single consistent API for both traces and metrics
276+
- **Improved correlation**: Direct association between attributes, traces, and errors
277+
278+
Migration process:
279+
1. Identify your current metric instrumentation points
280+
2. Locate corresponding spans in your application
281+
3. Transfer your metrics to span attributes
282+
4. Update any dashboards or alerts to reference the new metric sources
283+
284+
## Additional Resources
285+
286+
For more detailed implementation examples, refer to these guides:
287+
288+
- [E-Commerce use case](/platforms/javascript/tracing/span-metrics/examples/#e-commerce-transaction-flow)
289+
- [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)
291+
- [Job scheduling and processing](/platforms/javascript/tracing/span-metrics/examples/#job-scheduling-and-processing-pipeline)
292+
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)