File tree Expand file tree Collapse file tree 6 files changed +103
-0
lines changed
packages/node-integration-tests/suites/public-api/setContext Expand file tree Collapse file tree 6 files changed +103
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/node' ;
2
+
3
+ Sentry . init ( {
4
+ dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
5
+ release : '1.0' ,
6
+ } ) ;
7
+
8
+ Sentry . setContext ( 'context_1' , {
9
+ foo : 'bar' ,
10
+ baz : {
11
+ qux : 'quux' ,
12
+ } ,
13
+ } ) ;
14
+
15
+ Sentry . setContext ( 'context_2' , {
16
+ 1 : 'foo' ,
17
+ bar : false ,
18
+ } ) ;
19
+
20
+ Sentry . setContext ( 'context_3' , null ) ;
21
+
22
+ Sentry . captureMessage ( 'multiple_contexts' ) ;
Original file line number Diff line number Diff line change
1
+ import { Event } from '@sentry/node' ;
2
+
3
+ import { assertSentryEvent , getEventRequest , runServer } from '../../../../utils' ;
4
+
5
+ test ( 'should record multiple contexts' , async ( ) => {
6
+ const url = await runServer ( __dirname ) ;
7
+ const requestBody = await getEventRequest ( url ) ;
8
+
9
+ assertSentryEvent ( requestBody , {
10
+ message : 'multiple_contexts' ,
11
+ contexts : {
12
+ context_1 : {
13
+ foo : 'bar' ,
14
+ baz : { qux : 'quux' } ,
15
+ } ,
16
+ context_2 : { 1 : 'foo' , bar : false } ,
17
+ } ,
18
+ } ) ;
19
+
20
+ expect ( ( requestBody as Event ) . contexts ?. context_3 ) . not . toBeDefined ( ) ;
21
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/node' ;
2
+
3
+ Sentry . init ( {
4
+ dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
5
+ release : '1.0' ,
6
+ } ) ;
7
+
8
+ type Circular = {
9
+ self ?: Circular ;
10
+ } ;
11
+
12
+ const objCircular : Circular = { } ;
13
+ objCircular . self = objCircular ;
14
+
15
+ Sentry . setContext ( 'non_serializable' , objCircular ) ;
16
+
17
+ Sentry . captureMessage ( 'non_serializable' ) ;
Original file line number Diff line number Diff line change
1
+ import { Event } from '@sentry/node' ;
2
+
3
+ import { assertSentryEvent , getEventRequest , runServer } from '../../../../utils' ;
4
+
5
+ test ( 'should normalize non-serializable context' , async ( ) => {
6
+ const url = await runServer ( __dirname ) ;
7
+ const requestBody = await getEventRequest ( url ) ;
8
+
9
+ assertSentryEvent ( requestBody , {
10
+ message : 'non_serializable' ,
11
+ contexts : { } ,
12
+ } ) ;
13
+
14
+ expect ( ( requestBody as Event ) . contexts ?. context_3 ) . not . toBeDefined ( ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/node' ;
2
+
3
+ Sentry . init ( {
4
+ dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
5
+ release : '1.0' ,
6
+ } ) ;
7
+
8
+ Sentry . setContext ( 'foo' , { bar : 'baz' } ) ;
9
+ Sentry . captureMessage ( 'simple_context_object' ) ;
Original file line number Diff line number Diff line change
1
+ import { Event } from '@sentry/node' ;
2
+
3
+ import { assertSentryEvent , getEventRequest , runServer } from '../../../../utils' ;
4
+
5
+ test ( 'should set a simple context' , async ( ) => {
6
+ const url = await runServer ( __dirname ) ;
7
+ const requestBody = await getEventRequest ( url ) ;
8
+
9
+ assertSentryEvent ( requestBody , {
10
+ message : 'simple_context_object' ,
11
+ contexts : {
12
+ foo : {
13
+ bar : 'baz' ,
14
+ } ,
15
+ } ,
16
+ } ) ;
17
+
18
+ expect ( ( requestBody as Event ) . contexts ?. context_3 ) . not . toBeDefined ( ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments