File tree 2 files changed +19
-4
lines changed
packages/effect/src/internal
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " effect " : patch
3
+ ---
4
+
5
+ generate a random span id for the built-in tracer
6
+
7
+ This ensures the same span id isn't used between application runs.
Original file line number Diff line number Diff line change 3
3
*/
4
4
import * as Context from "../Context.js"
5
5
import type * as Exit from "../Exit.js"
6
- import { globalValue } from "../GlobalValue.js"
7
- import * as MutableRef from "../MutableRef.js"
8
6
import type * as Option from "../Option.js"
9
7
import type * as Tracer from "../Tracer.js"
10
8
@@ -23,7 +21,17 @@ export const tracerTag = Context.GenericTag<Tracer.Tracer>("effect/Tracer")
23
21
/** @internal */
24
22
export const spanTag = Context . GenericTag < Tracer . ParentSpan > ( "effect/ParentSpan" )
25
23
26
- const ids = globalValue ( "effect/Tracer/SpanId.ids" , ( ) => MutableRef . make ( 0 ) )
24
+ const randomString = ( function ( ) {
25
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
26
+ const charactersLength = characters . length
27
+ return function ( length : number ) {
28
+ let result = ""
29
+ for ( let i = 0 ; i < length ; i ++ ) {
30
+ result += characters . charAt ( Math . floor ( Math . random ( ) * charactersLength ) )
31
+ }
32
+ return result
33
+ }
34
+ } ) ( )
27
35
28
36
/** @internal */
29
37
export class NativeSpan implements Tracer . Span {
@@ -48,7 +56,7 @@ export class NativeSpan implements Tracer.Span {
48
56
startTime
49
57
}
50
58
this . attributes = new Map ( )
51
- this . spanId = `span${ MutableRef . incrementAndGet ( ids ) } `
59
+ this . spanId = `span${ randomString ( 16 ) } `
52
60
}
53
61
54
62
end = ( endTime : bigint , exit : Exit . Exit < unknown , unknown > ) : void => {
You can’t perform that action at this time.
0 commit comments