Skip to content

Commit 02fd7a5

Browse files
committed
Updating copy across tracing docs for clarify
1 parent 3216205 commit 02fd7a5

File tree

5 files changed

+167
-60
lines changed

5 files changed

+167
-60
lines changed

docs/platforms/javascript/common/tracing/index.mdx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ description: "Learn how to enable tracing in your app."
44
sidebar_order: 4000
55
---
66

7-
With [tracing](/product/insights/overview/), Sentry tracks your software performance, measuring metrics like throughput and latency, and displaying the impact of errors across multiple systems. Sentry captures distributed traces consisting of transactions and spans, which measure individual services and individual operations within those services. Learn more about our model in [Distributed Tracing](/product/sentry-basics/tracing/distributed-tracing/).
8-
9-
<PlatformSection notSupported={["javascript.bun", "javascript.deno", "javascript.cloudflare", "javascript.cordova", "javascript.capacitor"]}>
10-
You can additionally <PlatformLink to="/profiling">set up Profiling</PlatformLink> to get even more detailed tracing information like stack traces and flame graphs.
11-
</PlatformSection>
7+
With [tracing](/product/insights/overview/), Sentry automatically tracks your software performance across your application services, measuring metrics like throughput and latency, and displaying the impact of errors across multiple systems.
128

139
<PlatformCategorySection supported={["server", "serverless"]}>
1410
<Alert>
@@ -34,24 +30,33 @@ With [tracing](/product/insights/overview/), Sentry tracks your software perform
3430
## Configure
3531

3632
<PlatformSection supported={["javascript"]}>
37-
First, enable tracing and configure the sampling rate for transactions. Set
33+
Enable tracing by configuring the sampling rate for transactions. Set
3834
the sample rate for your transactions by either:
3935
</PlatformSection>
4036

4137
<PlatformSection notSupported={["javascript"]}>
42-
First, configure the sampling rate for transactions. Set the sample rate for
43-
your transactions by either:
38+
Enable tracing by setting the sample rate for your transactions.
4439
</PlatformSection>
4540

46-
- Setting a uniform sample rate for all transactions using the <PlatformIdentifier name="traces-sample-rate" /> option in your SDK config to a number between `0` and `1`. (For example, to send 20% of transactions, set <PlatformIdentifier name="traces-sample-rate" /> to `0.2`.)
47-
- Controlling the sample rate based on the transaction itself and the context in which it's captured, by providing a function to the <PlatformIdentifier name="traces-sampler" /> config option.
41+
<PlatformContent includePath="performance/configure-sample-rate" />
4842

49-
The two options are meant to be mutually exclusive. If you set both, <PlatformIdentifier name="traces-sampler" /> will take precedence.
43+
- You can set a uniform sample rate for all transactions using the <PlatformIdentifier name="traces-sample-rate" /> option in your SDK config to a number between `0` and `1`. (For example, to send 20% of transactions, set <PlatformIdentifier name="traces-sample-rate" /> to `0.2`.)
44+
- For more granular control over sampling, you can set the sample rate based on the transaction itself and the context in which it's captured, by providing a function to the <PlatformIdentifier name="traces-sampler" /> config option.
5045

51-
<PlatformContent includePath="performance/configure-sample-rate" />
46+
The two options are mutually exclusive. If both are set, <PlatformIdentifier name="traces-sampler" /> will take precedence.
5247

5348
Learn more about tracing <PlatformLink to="/configuration/options/#tracing-options">options</PlatformLink>, how to use the <PlatformLink to="/configuration/sampling/#setting-a-sampling-function">tracesSampler</PlatformLink> function, or how to <PlatformLink to="/configuration/sampling/#sampling-transaction-events">sample transactions</PlatformLink>.
5449

50+
## Distributed Tracing
51+
52+
Sentry captures distributed traces consisting of transactions and spans, which measure individual services and individual operations within those services. Learn more about our model in [Distributed Tracing](/product/sentry-basics/tracing/distributed-tracing/).
53+
54+
55+
<PlatformSection notSupported={["javascript.bun", "javascript.deno", "javascript.cloudflare", "javascript.cordova", "javascript.capacitor"]}>
56+
## Enhancing Trace Data with Profiling
57+
You can additionally <PlatformLink to="/profiling">set up Profiling</PlatformLink> to get even more detailed tracing information like stack traces and flame graphs.
58+
</PlatformSection>
59+
5560
## Verify
5661

5762
<PlatformSection supported={["javascript"]} notSupported={["javascript.cordova"]}>
@@ -74,7 +79,7 @@ If you leave your sample rate at `1.0`, a transaction will be sent every time a
7479

7580
You can also manually start spans to instrument specific parts of your code. This is useful when you want to measure the performance of a specific operation or function.
7681

77-
See <PlatformLink to="/tracing/instrumentation/custom-instrumentation">Custom Instrumentation</PlatformLink> to learn how to manually start spans.
82+
See <PlatformLink to="/tracing/span-metrics/">Sending Span Metrics</PlatformLink> to learn how to manually start spans.
7883

7984
## Next Steps
8085

docs/platforms/javascript/common/tracing/span-metrics/examples.mdx

Lines changed: 141 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Instrumentation Examples
2+
title: Example Instrumentation
33
description: "Examples of using span metrics to debug performance issues and monitor application behavior across frontend and backend services."
44
sidebar_order: 10
55
---
@@ -26,21 +26,55 @@ Sentry.startSpan(
2626
name: 'Client File Upload',
2727
op: 'file.upload.client',
2828
attributes: {
29-
// Client-side file preparation
29+
// Static details available at the start
3030
'file.size_bytes': 15728640, // 15MB
3131
'file.type': 'image/jpeg',
3232
'file.name': 'user-profile.jpg',
33-
34-
// Client processing metrics
35-
'client.compression_applied': true,
36-
37-
// Upload progress tracking
38-
'upload.retry_count': 0,
39-
'upload.total_time_ms': 3500
33+
'client.compression_applied': true
4034
}
4135
},
4236
async () => {
43-
// Client-side upload implementation
37+
// Get the current active span to update during upload
38+
const span = Sentry.getActiveSpan();
39+
40+
try {
41+
// Begin upload process
42+
const uploader = new FileUploader(file);
43+
44+
// Update progress as upload proceeds
45+
uploader.on('progress', (progressEvent) => {
46+
if (span) {
47+
span.setAttribute('upload.percent_complete', progressEvent.percent);
48+
span.setAttribute('upload.bytes_transferred', progressEvent.loaded);
49+
}
50+
});
51+
52+
uploader.on('retry', (retryCount) => {
53+
if (span) {
54+
span.setAttribute('upload.retry_count', retryCount);
55+
}
56+
});
57+
58+
const result = await uploader.start();
59+
60+
// Set final attributes after completion
61+
if (span) {
62+
span.setAttribute('upload.total_time_ms', result.totalTime);
63+
span.setAttribute('upload.success', true);
64+
span.setAttribute('upload.server_file_id', result.fileId);
65+
}
66+
67+
return result;
68+
} catch (error) {
69+
// Record failure information
70+
if (span) {
71+
span.setAttribute('upload.success', false);
72+
span.setAttribute('upload.error_type', error.name);
73+
span.setAttribute('upload.error_message', error.message);
74+
span.setStatus({ code: 'ERROR' });
75+
}
76+
throw error;
77+
}
4478
}
4579
);
4680
```
@@ -94,21 +128,53 @@ Sentry.startSpan(
94128
name: 'LLM Client Interaction',
95129
op: 'ai.client',
96130
attributes: {
97-
// User interaction metrics
131+
// Initial metrics available at request time
98132
'input.char_count': 280,
99133
'input.language': 'en',
100-
'input.type': 'question',
101-
102-
// UI performance
103-
'ui.time_to_first_token_ms': 245,
104-
'ui.total_request_time_ms': 3250,
105-
106-
// Stream handling
107-
'stream.rendering_mode': 'markdown'
134+
'input.type': 'question'
108135
}
109136
},
110137
async () => {
111-
// Client-side LLM handling
138+
const span = Sentry.getActiveSpan();
139+
const startTime = performance.now();
140+
141+
// Begin streaming response from LLM API
142+
const stream = await llmClient.createCompletion({
143+
prompt: userInput,
144+
stream: true
145+
});
146+
147+
// Record time to first token when received
148+
let firstTokenReceived = false;
149+
let tokensReceived = 0;
150+
151+
for await (const chunk of stream) {
152+
tokensReceived++;
153+
154+
// Record time to first token
155+
if (!firstTokenReceived && chunk.content) {
156+
firstTokenReceived = true;
157+
const timeToFirstToken = performance.now() - startTime;
158+
159+
if (span) {
160+
span.setAttribute('ui.time_to_first_token_ms', timeToFirstToken);
161+
}
162+
}
163+
164+
// Process and render the chunk
165+
renderChunkToUI(chunk);
166+
}
167+
168+
// Record final metrics after stream completes
169+
const totalRequestTime = performance.now() - startTime;
170+
171+
if (span) {
172+
span.setAttribute('ui.total_request_time_ms', totalRequestTime);
173+
span.setAttribute('stream.rendering_mode', 'markdown');
174+
span.setAttribute('stream.tokens_received', tokensReceived);
175+
span.setAttribute('user.perceived_latency_ms',
176+
firstTokenReceived ? totalRequestTime - span.getAttribute('ui.time_to_first_token_ms') : totalRequestTime);
177+
}
112178
}
113179
);
114180
```
@@ -121,27 +187,67 @@ Sentry.startSpan(
121187
name: 'LLM API Processing',
122188
op: 'ai.server',
123189
attributes: {
124-
// Model configuration
190+
// Model configuration - known at start
125191
'llm.model': 'claude-3-5-sonnet-20241022',
126192
'llm.temperature': 0.5,
127-
'llm.max_tokens': 4096,
193+
'llm.max_tokens': 4096
194+
}
195+
},
196+
async () => {
197+
const span = Sentry.getActiveSpan();
198+
const startTime = Date.now();
199+
200+
// Record queue time if applicable
201+
if (requestQueuedAt) {
202+
const queueTime = startTime - requestQueuedAt;
203+
if (span) {
204+
span.setAttribute('llm.queue_time_ms', queueTime);
205+
}
206+
}
207+
208+
try {
209+
// Check rate limits before processing
210+
const rateLimits = await getRateLimits();
211+
if (span) {
212+
span.setAttribute('llm.rate_limit_remaining', rateLimits.remaining);
213+
}
128214

129-
// Token usage metrics
130-
'llm.prompt_tokens': 425,
131-
'llm.completion_tokens': 632,
132-
'llm.total_tokens': 1057,
215+
// Make the actual API call to the LLM provider
216+
const response = await llmProvider.generateCompletion({
217+
model: 'claude-3-5-sonnet-20241022',
218+
prompt: preparedPrompt,
219+
temperature: 0.5,
220+
max_tokens: 4096
221+
});
133222

134-
// Performance tracking
135-
'llm.api_latency_ms': 2800,
136-
'llm.queue_time_ms': 150,
223+
// Record token usage and performance metrics
224+
if (span) {
225+
span.setAttribute('llm.prompt_tokens', response.usage.prompt_tokens);
226+
span.setAttribute('llm.completion_tokens', response.usage.completion_tokens);
227+
span.setAttribute('llm.total_tokens', response.usage.total_tokens);
228+
span.setAttribute('llm.api_latency_ms', Date.now() - startTime);
229+
230+
// Calculate and record cost based on token usage
231+
const cost = calculateCost(
232+
response.usage.prompt_tokens,
233+
response.usage.completion_tokens,
234+
'claude-3-5-sonnet-20241022'
235+
);
236+
span.setAttribute('llm.cost_usd', cost);
237+
}
137238

138-
// Cost tracking
139-
'llm.cost_usd': 0.076,
140-
'llm.rate_limit_remaining': 95
239+
return response;
240+
} catch (error) {
241+
// Record error details
242+
if (span) {
243+
span.setAttribute('error', true);
244+
span.setAttribute('error.type', error.name);
245+
span.setAttribute('error.message', error.message);
246+
span.setAttribute('error.is_rate_limit', error.code === 'rate_limit_exceeded');
247+
span.setStatus({ code: 'ERROR' });
248+
}
249+
throw error;
141250
}
142-
},
143-
async () => {
144-
// Server-side LLM processing
145251
}
146252
);
147253
```

docs/platforms/javascript/common/tracing/span-metrics/index.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
2-
title: Span Metrics
3-
description: "Learn how to add custom metrics to your spans for enhanced performance monitoring and debugging."
2+
title: Sending Span Metrics
3+
description: "Learn how to add and send custom metrics to your spans for performance monitoring and debugging."
44
sidebar_order: 10
55
---
66

77
<Alert>
88

9-
To use span metrics effectively, you must first <PlatformLink to="/tracing/">set up tracing</PlatformLink> in your application.
9+
To use span metrics, you must first <PlatformLink to="/tracing/">configure tracing</PlatformLink> in your application.
1010

1111
</Alert>
1212

13-
Span metrics allow you to track custom performance data and debugging information within your application's traces. There are two main approaches to instrumenting metrics:
13+
Span metrics allow you to extend the default metrics that are collected by tracing and track custom performance data and debugging information within your application's traces. There are two main approaches to instrumenting metrics:
1414

15-
1. Adding metrics to existing spans
16-
2. Creating dedicated spans with custom metrics
15+
1. [Adding metrics to existing spans](#adding-metrics-to-existing-spans)
16+
2. [Creating dedicated spans with custom metrics](#creating-dedicated-metric-spans)
1717

1818
## Adding Metrics to Existing Spans
1919

docs/platforms/javascript/common/tracing/span-metrics/performance-metrics.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Performance Metrics
2+
title: Sending Performance Metrics
33
description: "Learn how to attach performance metrics to your transactions."
44
sidebar_order: 20
55
notSupported:

redirects.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,7 @@ const userDocsRedirects = [
10131013
{
10141014
source: '/platforms/javascript/guides/:guide/tracing/instrumentation/custom-instrumentation/:path*',
10151015
destination: '/platforms/javascript/guides/:guide/tracing/instrumentation/:path*',
1016-
},
1017-
{
1018-
source: '/platforms/javascript/tracing/instrumentation/:path*',
1019-
destination: '/platforms/javascript/tracing/span-metrics/performance-metrics/:path*',
1020-
},
1016+
}
10211017
];
10221018

10231019
/**

0 commit comments

Comments
 (0)