Skip to content

Commit 19670cc

Browse files
mydeaLms24
andauthored
feat(js): Update JS tracing instrumentation docs (#13229)
--------- Co-authored-by: Lukas Stracke <[email protected]>
1 parent ca2afe4 commit 19670cc

File tree

2 files changed

+25
-89
lines changed

2 files changed

+25
-89
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ With [tracing](/product/insights/overview/), Sentry automatically tracks your so
3030
## Configure
3131

3232
<PlatformSection supported={["javascript"]}>
33-
Enable tracing by configuring the sampling rate for transactions. Set
34-
the sample rate for your transactions by either:
33+
Enable tracing by configuring the sampling rate for transactions. Set the
34+
sample rate for your transactions by either:
3535
</PlatformSection>
3636

3737
<PlatformSection notSupported={["javascript"]}>
@@ -66,14 +66,20 @@ If you leave your sample rate at `1.0`, a transaction will be sent every time a
6666
<PlatformSection notSupported={["javascript.cordova"]}>
6767
## Automatic Instrumentation
6868

69-
See <PlatformLink to="/tracing/instrumentation/automatic-instrumentation">Automatic Instrumentation</PlatformLink> to learn about all the things that the SDK automatically instruments for you.
69+
See <PlatformLink to="/tracing/instrumentation/automatic-instrumentation">Automatic Instrumentation</PlatformLink> to learn about all the things that the SDK automatically instruments for you.
70+
7071
</PlatformSection>
7172

7273
## Custom Instrumentation
7374

7475
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.
7576

76-
See <PlatformLink to="/tracing/span-metrics/">Sending Span Metrics</PlatformLink> to learn how to manually start spans.
77+
- <PlatformLink to="/apis/#tracing">Tracing APIs</PlatformLink>:
78+
Find information about APIs for custom tracing instrumentation
79+
- <PlatformLink to="/tracing/instrumentation/">Instrumentation</PlatformLink>:
80+
Find information about manual instrumentation with the Sentry SDK
81+
- <PlatformLink to="/tracing/span-metrics/">Sending Span Metrics</PlatformLink>:
82+
Learn how to capture metrics on your spans
7783

7884
## Next Steps
7985

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

Lines changed: 15 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To capture transactions and spans customized to your organization's needs, you m
1212

1313
To add custom performance data to your application, you need to add custom instrumentation in the form of spans. Spans are a way to measure the time it takes for a specific action to occur. For example, you can create a span to measure the time it takes for a function to execute.
1414

15+
You can find a list of all tracing APIs in the <PlatformLink to="/apis/#tracing">Tracing API</PlatformLink> section.
16+
1517
To get started, import the SDK.
1618

1719
<PlatformContent includePath="enriching-events/import" />
@@ -106,7 +108,7 @@ To add spans that aren't active, you can create independent spans. This is usefu
106108

107109
By default, any span that is started will be the child of the currently active span. If you want to have a different behavior, you can force spans to be the children of a specific span with the `parentSpan` option:
108110

109-
```js
111+
```javascript
110112
const parentSpan = Sentry.startInactiveSpan({ name: "Parent Span" });
111113
const childSpan = Sentry.startInactiveSpan({ name: "Child Span", parentSpan });
112114

@@ -119,74 +121,12 @@ This option is also available for `startSpan` and `startSpanManual`.
119121
## Utilities To Work With Spans
120122

121123
We expose some helpful utilities that can help you with custom instrumentation.
122-
123-
### `getActiveSpan`
124-
125-
Returns the currently active span.
126-
127-
```javascript
128-
const activeSpan = Sentry.getActiveSpan();
129-
```
130-
131-
### `getRootSpan`
132-
133-
Returns the root span of a given span. If the span is already the root span, it will return the span itself.
134-
135-
```javascript
136-
const activeSpan = Sentry.getActiveSpan();
137-
const rootSpan = activeSpan ? Sentry.getRootSpan(activeSpan) : undefined;
138-
```
139-
140-
### `withActiveSpan`
141-
142-
This method allows you to make a span active for the duration of a callback. You can use this in combination with `startInactiveSpan` to manually associate child spans with the correct parent span:
143-
144-
```javascript
145-
const span = Sentry.startInactiveSpan({ name: "Parent Span" });
146-
147-
Sentry.withActiveSpan(span, () => {
148-
// `span` is now active, any other spans will be children of it
149-
Sentry.startSpan({ name: "Child Span" }, () => {
150-
// Do something
151-
});
152-
});
153-
```
154-
155-
You can also pass `null` to `withActiveSpan` to ensure a span will not have any parent:
156-
157-
```javascript
158-
Sentry.withActiveSpan(null, () => {
159-
// This will not have a parent span, no matter what
160-
Sentry.startSpan({ name: "Parent Span" }, () => {
161-
// Do something
162-
});
163-
});
164-
```
165-
166-
Alternatively you can also use the `parentSpan` option to achieve the same:
167-
168-
```javascript
169-
const span = Sentry.startInactiveSpan({ name: "Parent Span" });
170-
const childSpan = Sentry.startInactiveSpan({
171-
name: "Child Span",
172-
parentSpan: span,
173-
});
174-
```
175-
176-
### `suppressTracing`
177-
178-
Suppresses the creation of sampled spans for the duration of the callback. This is useful when you want to prevent certain spans from being captured. For example, if you do not want to create spans for a given fetch request, you can do:
179-
180-
```javascript
181-
Sentry.suppressTracing(() => {
182-
fetch("https://example.com");
183-
});
184-
```
124+
See <PlatformLink to="/apis/#tracing-utilities">Tracing Utility APIs</PlatformLink> for more information.
185125

186126
<PlatformSection notSupported={['javascript.cordova']}>
187-
### Distributed Tracing
127+
## Distributed Tracing
188128

189-
See <PlatformLink to="/tracing/trace-propagation/custom-instrumentation/">Distributed Tracing</PlatformLink> for details on how to manually set up distributed tracing.
129+
See <PlatformLink to="/tracing/trace-propagation/custom-instrumentation/">Custom Trace Propagation</PlatformLink> for details on how to manually set up distributed tracing.
190130

191131
</PlatformSection>
192132

@@ -227,32 +167,22 @@ if (span) {
227167

228168
### Adding attributes to all spans
229169

230-
To add an attribute to all spans, use the `beforeSendTransaction` callback:
170+
To add an attribute to all spans, use the `beforeSendSpan` callback:
231171

232172
```javascript
233173
Sentry.init({
234174
// dsn, ...
235-
beforeSendTransaction(event) {
236-
237-
// set the attribute on the root span
238-
event.contexts.trace.data = {
239-
...event.contexts.trace.data,
240-
myAttribute: "myValue",
241-
}
242-
243-
// and on all child spans
244-
event.spans.forEach(span => {
245-
span.data = {
246-
...span.data,
247-
myAttribute: "myValue",
248-
}
249-
});
250-
}
175+
beforeSendSpan(span) {
176+
span.data = {
177+
...span.data,
178+
"environment.region": "us-west-2",
179+
};
180+
181+
return span;
182+
},
251183
});
252184
```
253185

254-
255-
256186
### Adding Span Operations ("op")
257187

258188
Spans can have an operation associated with them, which help Sentry identify additional context about the span. For example, database related spans have the `db` span operation associated with them. The Sentry product offers additional controls, visualizations, and filters for spans with known operations.

0 commit comments

Comments
 (0)