@@ -3,9 +3,10 @@ import { BrowserClient } from '@sentry/browser';
3
3
import { getMainCarrier , Hub } from '@sentry/hub' ;
4
4
import * as hubModule from '@sentry/hub' ;
5
5
import * as utilsModule from '@sentry/utils' ; // for mocking
6
- import { getGlobalObject , isNodeEnv , logger } from '@sentry/utils' ;
6
+ import { base64ToUnicode , getGlobalObject , isNodeEnv , logger } from '@sentry/utils' ;
7
7
import * as nodeHttpModule from 'http' ;
8
8
9
+ import { Transaction } from '../src' ;
9
10
import { BrowserTracing } from '../src/browser/browsertracing' ;
10
11
import { addExtensionMethods } from '../src/hubextensions' ;
11
12
import { extractTraceparentData , TRACEPARENT_REGEXP } from '../src/utils' ;
@@ -31,6 +32,45 @@ describe('Hub', () => {
31
32
jest . useRealTimers ( ) ;
32
33
} ) ;
33
34
35
+ describe ( 'transaction creation' , ( ) => {
36
+ it ( 'uses inherited values when given in transaction context' , ( ) => {
37
+ const transactionContext = {
38
+ name : 'dogpark' ,
39
+ traceId : '12312012123120121231201212312012' ,
40
+ parentSpanId : '1121201211212012' ,
41
+ tracestate : 'doGsaREgReaT==' ,
42
+ } ;
43
+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
44
+ const transaction = hub . startTransaction ( transactionContext ) ;
45
+
46
+ expect ( transaction ) . toEqual ( expect . objectContaining ( transactionContext ) ) ;
47
+ } ) ;
48
+
49
+ it ( 'creates a new tracestate value (with the right data) if not given one in transaction context' , ( ) => {
50
+ const hub = new Hub (
51
+ new BrowserClient ( {
52
+ dsn :
'https://[email protected] /12312012' ,
53
+ tracesSampleRate : 1 ,
54
+ release : 'off.leash.park' ,
55
+ environment : 'dogpark' ,
56
+ } ) ,
57
+ ) ;
58
+ const transaction = hub . startTransaction ( { name : 'FETCH /ball' } ) ;
59
+
60
+ const b64Value =
61
+ 'ewAiAHAAdQBiAGwAaQBjAF8AawBlAHkAIgA6ACIAZABvAGcAcwBhAHIAZQBiAGEAZABhAHQAawBlAGUAcA' +
62
+ 'BpAG4AZwBzAGUAYwByAGUAdABzACIALAAiAGUAbgB2AGkAcgBvAG4AbQBlAG4AdAAiADoAIgBkAG8AZwBwAGEAcgBrACIALAAiA' +
63
+ 'HIAZQBsAGUAYQBzAGUAIgA6ACIAbwBmAGYALgBsAGUAYQBzAGgALgBwAGEAcgBrACIAfQA.' ;
64
+
65
+ expect ( transaction . tracestate ) . toEqual ( b64Value ) ;
66
+ expect ( JSON . parse ( base64ToUnicode ( b64Value . replace ( '.' , '=' ) ) ) ) . toEqual ( {
67
+ environment : 'dogpark' ,
68
+ public_key : 'dogsarebadatkeepingsecrets' ,
69
+ release : 'off.leash.park' ,
70
+ } ) ;
71
+ } ) ;
72
+ } ) ;
73
+
34
74
describe ( 'getTransaction()' , ( ) => {
35
75
it ( 'should find a transaction which has been set on the scope if sampled = true' , ( ) => {
36
76
const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
0 commit comments