@@ -5,17 +5,24 @@ customCanonicalTag: "/platforms/javascript/apis/"
5
5
sidebar_order : 3
6
6
---
7
7
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:
9
16
10
17
``` javascript
11
18
import * as Sentry from " @sentry/browser" ;
12
19
13
20
Sentry .setTag (" tag" , " value" );
14
21
```
15
22
16
- ## Available Options
23
+ ## Available APIs
17
24
18
- <TableOfContents ignoreIds = { [" available-options " ]} />
25
+ <TableOfContents ignoreIds = { [" available-apis " ]} />
19
26
20
27
## Core APIs
21
28
@@ -98,16 +105,47 @@ Sentry.setTag("tag", "value");
98
105
return ` null ` to discard the event. Event processors can also return a
99
106
promise, but it is recommended to use this only when necessary as it slows
100
107
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 >
101
135
</SdkApi >
102
136
103
137
<SdkApi
104
138
name = " addIntegration"
105
139
signature = " function addIntegration(integration: Integration): void"
106
140
>
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
+
111
149
</SdkApi >
112
150
113
151
<SdkApi name = " lazyLoadIntegration" signature = " function lazyLoadIntegration(name: string, scriptNonce?: string): Promise<Integration>" categorySupported = { [' browser' ]} >
@@ -126,48 +164,9 @@ Sentry.lazyLoadIntegration("replayIntegration")
126
164
127
165
If you use a bundler, using e.g. ` const { replayIntegration } = await import('@sentry/browser') ` is recommended instead.
128
166
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.
166
169
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.
171
170
</SdkApi >
172
171
173
172
## Capturing Events
@@ -183,7 +182,8 @@ Note that in most cases you should not use this API, but instead use `withScope`
183
182
name: " exception" ,
184
183
required: true ,
185
184
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." ,
187
187
},
188
188
{
189
189
name: " captureContext" ,
@@ -458,7 +458,8 @@ const status = await Sentry.startSpan({ name: 'my-span' }, async (span) => {
458
458
const status = await doSomething ();
459
459
return status;
460
460
});
461
- ```
461
+
462
+ ````
462
463
< / Expandable>
463
464
464
465
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
494
495
const span = Sentry.startInactiveSpan({ name: 'my-span' });
495
496
doSomething();
496
497
span.end();
497
- ```
498
+ ` ` ` `
498
499
499
500
</Expandable>
500
501
@@ -621,14 +622,6 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
621
622
` browserTracingIntegration ` has not been enabled.
622
623
</SdkApi >
623
624
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
-
632
625
## Tracing Utilities
633
626
634
627
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.
656
649
Get the root span of a span.
657
650
</SdkApi >
658
651
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
+
659
660
## Sessions
660
661
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
+
661
665
<SdkApi name = " startSession" signature = " function startSession(): void" >
662
666
Starts a new session.
663
667
</SdkApi >
@@ -674,6 +678,52 @@ These utilities can be used for more advanced tracing use cases.
674
678
end the session first.
675
679
</SdkApi >
676
680
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
+
677
727
## User Feedback
678
728
679
729
<SdkApi
@@ -851,6 +901,7 @@ These utilities can be used for more advanced tracing use cases.
851
901
</SdkApi >
852
902
853
903
<PlatformCategorySection supported = { [' server' ]} >
904
+
854
905
## Cron Monitoring
855
906
856
907
<SdkApi
0 commit comments