@@ -11,14 +11,46 @@ interface ExampleUserScope {
11
11
userId : string
12
12
}
13
13
14
+ interface ExampleTicketEventScope {
15
+ ticketId : string
16
+ eventId : string
17
+ }
18
+
14
19
interface ExampleCustomFieldScope {
15
20
customFieldId : string
16
21
}
17
22
23
+ interface ExampleScopeWithMultipleKeys {
24
+ customId : string
25
+ customOtherId : string
26
+ }
27
+
28
+ interface TicketFieldScope {
29
+ ticketId : string
30
+ ticketFieldType : 'dropdown'
31
+ }
32
+ interface TicketAppScope {
33
+ ticketId : string
34
+ appId : string
35
+ }
36
+
18
37
type ExampleAllPossibleScopes =
19
38
| ExampleTicketScope
20
39
| ExampleUserScope
21
40
| ExampleCustomFieldScope
41
+ | ExampleScopeWithMultipleKeys
42
+ | ExampleTicketEventScope
43
+
44
+ // TODO:
45
+ // // Helper type to ensure we get a tuple instead of an array type
46
+ // type ToTuple<T extends any[]> = [...T];
47
+
48
+ // // Main type that transforms union of objects to union of tuples of keys
49
+ // type ObjectKeysToTuple<T> = T extends object
50
+ // ? ToTuple<keyof T extends infer K ? K extends PropertyKey ? [K] : never : never>
51
+ // : never;
52
+
53
+ // type X = ObjectKeysToTuple<ExampleAllPossibleScopes> // ["ticketId"] | ["userId"] | ["customFieldId"] | ["customId", "customOtherId"] | ["ticketId", "eventId"]
22
54
23
55
const mockSpanWithoutScope = {
24
56
name : 'some-span' ,
@@ -92,21 +124,24 @@ describe.skip('type tests', () => {
92
124
const ticketActivationTracer = traceManager . createTracer ( {
93
125
name : 'ticket.activation' ,
94
126
scopes : [ 'ticketId' ] ,
127
+ // scope: 'global',
95
128
requiredToEnd : [ { matchScopes : [ 'ticketId' ] } ] ,
96
129
} )
97
130
98
131
const ticketActivationTracer2 = traceManager . createTracer ( {
99
132
name : 'ticket.activation' ,
100
- scopes : [ 'ticketId ' ] ,
133
+ scopes : [ 'customId' , 'customOtherId '] ,
101
134
requiredToEnd : [
102
- // match.withAllConditions(
103
- // match.withName((name, scopes) => name === `${scopes.ticketId}.end`),
104
- // // match.withName('end'),
105
- // // match.withMatchingScopes(['ticketId']),
106
- // ),
107
- // match.withName((name, scopes) => name === `${scopes.ticketId}.end`),
108
- // match.withName('customFieldId'),
109
- match . withMatchingScopes ( [ 'customFieldId' ] ) ,
135
+ match . withAllConditions (
136
+ match . withName ( ( name , scopes ) => name === `${ scopes . customId } .end` ) ,
137
+ match . withName ( 'end' ) ,
138
+ match . withMatchingScopes ( [ 'customId' ] ) ,
139
+ ) ,
140
+ match . withName ( ( name , scopes ) => name === `${ scopes . customId } .end` ) ,
141
+ match . withName ( 'customFieldId' ) ,
142
+ match . withMatchingScopes ( [ 'customId' ] ) ,
143
+ // @ts -expect-error invalid scope
144
+ match . withMatchingScopes ( [ 'sticketId' ] ) ,
110
145
] ,
111
146
} )
112
147
@@ -232,6 +267,56 @@ describe.skip('type tests', () => {
232
267
} )
233
268
} )
234
269
270
+ it ( 'mixed scopes' , ( ) => {
271
+ const tracer = traceManager . createTracer ( {
272
+ name : 'ticket.scope-operation' ,
273
+ type : 'operation' ,
274
+ scopes : [ 'ticketId' , 'customFieldId' ] ,
275
+ timeoutDuration : 5_000 ,
276
+ requiredToEnd : [ { name : 'end' , matchScopes : true } ] ,
277
+ } )
278
+ const traceId = tracer . start ( {
279
+ scope : {
280
+ customFieldId : '3' ,
281
+ ticketId : '4' ,
282
+ } ,
283
+ } )
284
+ } )
285
+
286
+ it ( 'redaction example' , ( ) => {
287
+ const tracer = traceManager . createTracer ( {
288
+ name : 'ticket.event.redacted' ,
289
+ type : 'operation' ,
290
+ scopes : [ 'ticketId' , 'eventId' ] ,
291
+ timeoutDuration : 5_000 ,
292
+ requiredToEnd : [ { name : 'OmniLogEvent' , matchScopes : true } ] ,
293
+ debounceOn : [ { name : 'OmniLog' , matchScopes : [ 'ticketId' ] } ] ,
294
+ } )
295
+ const traceId = tracer . start ( {
296
+ scope : {
297
+ ticketId : '4' ,
298
+ eventId : '3' ,
299
+ } ,
300
+ } )
301
+ } )
302
+
303
+ it ( 'redaction invalid example' , ( ) => {
304
+ const tracer = traceManager . createTracer ( {
305
+ name : 'ticket.event.redacted' ,
306
+ type : 'operation' ,
307
+ // @ts -expect-error enforce a complete set of keys of a given scope
308
+ scopes : [ 'eventId' ] ,
309
+ timeoutDuration : 5_000 ,
310
+ requiredToEnd : [ { name : 'OmniLogEvent' , matchScopes : true } ] ,
311
+ } )
312
+ const traceId = tracer . start ( {
313
+ scope : {
314
+ ticketId : '4' ,
315
+ eventId : '3' ,
316
+ } ,
317
+ } )
318
+ } )
319
+
235
320
it ( 'does not allow to include invalid scope key' , ( ) => {
236
321
const tracer = traceManager . createTracer ( {
237
322
name : 'ticket.scope-operation' ,
0 commit comments