@@ -53,8 +53,7 @@ export function copyFlagsFromScopeToEvent(event: Event): Event {
53
53
*
54
54
* @param name Name of the feature flag to insert.
55
55
* @param value Value of the feature flag.
56
- * @param maxSize Max number of flags the buffer should store. It's recommended
57
- * to keep this consistent across insertions. Default is FLAG_BUFFER_SIZE
56
+ * @param maxSize Max number of flags the buffer should store. Default value should always be used in production.
58
57
*/
59
58
export function insertFlagToScope ( name : string , value : unknown , maxSize : number = FLAG_BUFFER_SIZE ) : void {
60
59
const scopeContexts = getCurrentScope ( ) . getScopeData ( ) . contexts ;
@@ -68,7 +67,7 @@ export function insertFlagToScope(name: string, value: unknown, maxSize: number
68
67
/**
69
68
* Exported for tests. Currently only accepts boolean values (otherwise no-op).
70
69
*/
71
- export function insertToFlagBuffer ( flags : FeatureFlag [ ] , name : string , value : unknown , maxSize : number ) : void {
70
+ export function insertToFlagBuffer ( flags : FeatureFlag [ ] , name : string , value : unknown , maxSize : number , allowEviction : boolean = true ) : void {
72
71
if ( typeof value !== 'boolean' ) {
73
72
return ;
74
73
}
@@ -87,8 +86,12 @@ export function insertToFlagBuffer(flags: FeatureFlag[], name: string, value: un
87
86
}
88
87
89
88
if ( flags . length === maxSize ) {
90
- // If at capacity, pop the earliest flag - O(n)
91
- flags . shift ( ) ;
89
+ if ( allowEviction ) {
90
+ // If at capacity, pop the earliest flag - O(n)
91
+ flags . shift ( ) ;
92
+ } else {
93
+ return ;
94
+ }
92
95
}
93
96
94
97
// Push the flag to the end - O(1)
@@ -119,9 +122,7 @@ export function bufferSpanFeatureFlag(
119
122
const span = getActiveSpan ( ) ;
120
123
if ( span ) {
121
124
const flags = spanFlagMap . get ( span ) || [ ] ;
122
- if ( ! flags . find ( flag => flag . flag === name ) && flags . length < maxFlagsPerSpan ) {
123
- flags . push ( { flag : name , result : value } ) ;
124
- }
125
+ insertToFlagBuffer ( flags , name , value , maxFlagsPerSpan , false ) ;
125
126
spanFlagMap . set ( span , flags ) ;
126
127
}
127
128
}
0 commit comments