Skip to content

Commit b280a2e

Browse files
committed
PR feedback
1 parent 586eb8d commit b280a2e

File tree

1 file changed

+110
-59
lines changed
  • docs/platforms/javascript/common

1 file changed

+110
-59
lines changed

docs/platforms/javascript/common/apis.mdx

Lines changed: 110 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ customCanonicalTag: "/platforms/javascript/apis/"
55
sidebar_order: 3
66
---
77

8-
This page shows all available to-level APIs of the SDK. You can use them like this:
8+
This page shows all available to-level APIs of the SDK. You can use these APIs as the primary way to:
9+
10+
- Configure the SDK after initialization
11+
- Manually capture different types of events
12+
- Enrich events with additional data
13+
- ... and more!
14+
15+
These APIs are functions that you can use as follows - they are all available on the top-level `Sentry` object:
916

1017
```javascript
1118
import * as Sentry from "@sentry/browser";
1219

1320
Sentry.setTag("tag", "value");
1421
```
1522

16-
## Available Options
23+
## Available APIs
1724

18-
<TableOfContents ignoreIds={["available-options"]} />
25+
<TableOfContents ignoreIds={["available-apis"]} />
1926

2027
## Core APIs
2128

@@ -98,16 +105,47 @@ Sentry.setTag("tag", "value");
98105
return `null` to discard the event. Event processors can also return a
99106
promise, but it is recommended to use this only when necessary as it slows
100107
down event processing.
108+
109+
<PlatformCategorySection notSupported={['server', 'serverless']}>
110+
Event processors added via `Sentry.addEventProcessor()` will be applied to all events in your application.
111+
If you want to add an event processor that only applies to certain events, you can also add one to a scope as follows:
112+
</PlatformCategorySection>
113+
114+
<PlatformCategorySection supported={['server', 'serverless']}>
115+
Event processors added via `Sentry.addEventProcessor()` will be applied to all events in your current request.
116+
If you want to add an event processor that only applies to certain events, you can also add one to a scope as follows:
117+
</PlatformCategorySection>
118+
119+
```javascript
120+
Sentry.withScope((scope) => {
121+
scope.addEventProcessor((event) => {
122+
// this will only be applied to events captured within this scope
123+
return event;
124+
});
125+
126+
Sentry.captureException(new Error("test"));
127+
});
128+
```
129+
130+
<Expandable title='What is the difference to `beforeSend` / `beforeSendTransaction`?'>
131+
`beforeSend` and `beforeSendTransaction` are guaranteed to be run last, after all other event processors, (which means they get the final version of the event right before it's sent, hence the name). Event processors added with `addEventProcessor` are run in an undetermined order, which means changes to the event may still be made after the event processor runs.
132+
133+
There can only be a single `beforeSend` / `beforeSendTransaction` processor, but you can add multiple event processors via `addEventProcessor()`.
134+
</Expandable>
101135
</SdkApi>
102136

103137
<SdkApi
104138
name="addIntegration"
105139
signature="function addIntegration(integration: Integration): void"
106140
>
107-
Adds an integration to the SDK. This can be used to conditionally add
108-
integrations after `Sentry.init()` has been called. Note that it is
109-
recommended to pass integrations to `init` instead of calling this method,
110-
where possible.
141+
Adds an integration to the SDK. This can be used to conditionally add
142+
integrations after `Sentry.init()` has been called. Note that it is
143+
recommended to pass integrations to `init` instead of calling this method,
144+
where possible.
145+
146+
See <PlatformLink to="/configuration/integrations">Integrations</PlatformLink> for
147+
more information on how to use integrations.
148+
111149
</SdkApi>
112150

113151
<SdkApi name="lazyLoadIntegration" signature="function lazyLoadIntegration(name: string, scriptNonce?: string): Promise<Integration>" categorySupported={['browser']}>
@@ -126,48 +164,9 @@ Sentry.lazyLoadIntegration("replayIntegration")
126164

127165
If you use a bundler, using e.g. `const { replayIntegration } = await import('@sentry/browser')` is recommended instead.
128166

129-
</SdkApi>
130-
131-
## Scopes
132-
133-
<SdkApi name="getCurrentScope" signature="function getCurrentScope(): Scope">
134-
Returns the current scope. See{" "}
135-
<PlatformLink to="/enriching-events/scopes/">Scopes</PlatformLink> for more
136-
information.
137-
138-
Note that in most cases you should not use this API, but instead use `withScope` to generate and access a local scope. There are no guarantees about the consistency of `getCurrentScope` across different parts of your application, as scope forking may happen under the hood at various points.
139-
140-
</SdkApi>
141-
142-
<SdkApi
143-
name="withScope"
144-
signature="function withScope(callback: (scope: Scope) => void): void"
145-
>
146-
Forks the current scope and calls the callback with the forked scope. See{" "}
147-
<PlatformLink to="/enriching-events/scopes/">Scopes</PlatformLink> for more
148-
information.
149-
</SdkApi>
150-
151-
<SdkApi
152-
name="getIsolationScope"
153-
signature="function getIsolationScope(): Scope"
154-
>
155-
Returns the current isolation scope.
156-
</SdkApi>
157-
158-
<SdkApi
159-
name="withIsolationScope"
160-
signature="function withIsolationScope(callback: (scope: Scope) => void): void"
161-
>
162-
Forks the current isolation scope and calls the callback with the forked
163-
scope. See <PlatformLink to="/enriching-events/scopes/">Scopes</PlatformLink>{" "}
164-
for more information.
165-
</SdkApi>
167+
See <PlatformLink to="/configuration/integrations">Integrations</PlatformLink> for
168+
more information on how to use integrations.
166169

167-
<SdkApi name="getGlobalScope" signature="function getGlobalScope(): Scope">
168-
Returns the global scope. See{" "}
169-
<PlatformLink to="/enriching-events/scopes/">Scopes</PlatformLink> for more
170-
information.
171170
</SdkApi>
172171

173172
## Capturing Events
@@ -183,7 +182,8 @@ Note that in most cases you should not use this API, but instead use `withScope`
183182
name: "exception",
184183
required: true,
185184
type: "unknown",
186-
description: "The exception to capture. For best results, pass an `Error` object but it accepts any kind of value.",
185+
description:
186+
"The exception to capture. For best results, pass an `Error` object but it accepts any kind of value.",
187187
},
188188
{
189189
name: "captureContext",
@@ -458,7 +458,8 @@ const status = await Sentry.startSpan({ name: 'my-span' }, async (span) => {
458458
const status = await doSomething();
459459
return status;
460460
});
461-
```
461+
462+
````
462463
</Expandable>
463464

464465
See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</PlatformLink> for more information on how to work with spans.
@@ -494,7 +495,7 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
494495
const span = Sentry.startInactiveSpan({ name: 'my-span' });
495496
doSomething();
496497
span.end();
497-
```
498+
````
498499
499500
</Expandable>
500501
@@ -621,14 +622,6 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
621622
`browserTracingIntegration` has not been enabled.
622623
</SdkApi>
623624

624-
<SdkApi
625-
name="withActiveSpan"
626-
signature="function withActiveSpan<T>(span: Span | null, callback: () => T): T"
627-
>
628-
Runs the provided callback with the given span as the active span. If `null`
629-
is provided, the callback will have no active span.
630-
</SdkApi>
631-
632625
## Tracing Utilities
633626

634627
These utilities can be used for more advanced tracing use cases.
@@ -656,8 +649,19 @@ These utilities can be used for more advanced tracing use cases.
656649
Get the root span of a span.
657650
</SdkApi>
658651

652+
<SdkApi
653+
name="withActiveSpan"
654+
signature="function withActiveSpan<T>(span: Span | null, callback: () => T): T"
655+
>
656+
Runs the provided callback with the given span as the active span. If `null`
657+
is provided, the callback will have no active span.
658+
</SdkApi>
659+
659660
## Sessions
660661

662+
Sessions allow you to track the release health of your application.
663+
See the <PlatformLink to="/configuration/releases/#sessions">Releases & Health</PlatformLink> page for more information.
664+
661665
<SdkApi name="startSession" signature="function startSession(): void">
662666
Starts a new session.
663667
</SdkApi>
@@ -674,6 +678,52 @@ These utilities can be used for more advanced tracing use cases.
674678
end the session first.
675679
</SdkApi>
676680

681+
## Scopes
682+
683+
See <PlatformLink to="/enriching-events/scopes/">Scopes</PlatformLink> for more information on how to use scopes,
684+
as well as for an explanation of the different types of scopes (current scope, isolation scope, and global scope).
685+
686+
<SdkApi
687+
name="withScope"
688+
signature="function withScope(callback: (scope: Scope) => void): void"
689+
>
690+
Forks the current scope and calls the callback with the forked scope.
691+
</SdkApi>
692+
693+
<SdkApi
694+
name="withIsolationScope"
695+
signature="function withIsolationScope(callback: (scope: Scope) => void): void"
696+
>
697+
Forks the current isolation scope and calls the callback with the forked
698+
scope.
699+
</SdkApi>
700+
701+
<SdkApi name="getCurrentScope" signature="function getCurrentScope(): Scope">
702+
Returns the <PlatformLink to="/enriching-events/scopes/#current-scope">current scope</PlatformLink>.
703+
704+
Note that in most cases you should not use this API, but instead use `withScope` to generate and access a local scope. There are no guarantees about the consistency of `getCurrentScope` across different parts of your application, as scope forking may happen under the hood at various points.
705+
706+
</SdkApi>
707+
708+
<SdkApi
709+
name="getIsolationScope"
710+
signature="function getIsolationScope(): Scope"
711+
>
712+
Returns the current{" "}
713+
<PlatformLink to="/enriching-events/scopes/#isolation-scope">
714+
isolation scope
715+
</PlatformLink>
716+
.
717+
</SdkApi>
718+
719+
<SdkApi name="getGlobalScope" signature="function getGlobalScope(): Scope">
720+
Returns the{" "}
721+
<PlatformLink to="/enriching-events/scopes/#global-scope">
722+
global scope
723+
</PlatformLink>
724+
.
725+
</SdkApi>
726+
677727
## User Feedback
678728

679729
<SdkApi
@@ -851,6 +901,7 @@ These utilities can be used for more advanced tracing use cases.
851901
</SdkApi>
852902

853903
<PlatformCategorySection supported={['server']}>
904+
854905
## Cron Monitoring
855906

856907
<SdkApi

0 commit comments

Comments
 (0)