@@ -6,6 +6,7 @@ import { expect, test, beforeAll, afterAll } from 'vitest'
6
6
import {
7
7
getGlobalContext ,
8
8
setGlobalContext ,
9
+ addAttributesToActiveSpan ,
9
10
addEventToActiveSpan ,
10
11
addErrorToActiveSpan ,
11
12
setMultiSpanAttributes ,
@@ -94,6 +95,39 @@ test('addErrorToActiveSpan - attributes are added', async () => {
94
95
} )
95
96
} )
96
97
98
+ test ( 'addAttributesToActiveSpan - attributes are added' , async ( ) => {
99
+ const tracer = trace . getTracer ( 'default' )
100
+ const span = tracer . startSpan ( 'my-span' ) as Span
101
+ const ctx = trace . setSpan ( context . active ( ) , span )
102
+
103
+ context . with ( ctx , async ( ) => {
104
+ const attributes = {
105
+ 'build.test' : 'something' ,
106
+ 'build.another-test' : 'something-else' ,
107
+ }
108
+ addAttributesToActiveSpan ( attributes )
109
+
110
+ expect ( span . attributes ) . toStrictEqual ( attributes )
111
+ } )
112
+ } )
113
+
114
+ test ( 'addAttributesToActiveSpan - no attributes are added' , async ( ) => {
115
+ const tracer = trace . getTracer ( 'default' )
116
+ const span = tracer . startSpan ( 'my-span' ) as Span
117
+ const ctx = trace . setSpan ( context . active ( ) , span )
118
+
119
+ context . with ( ctx , async ( ) => {
120
+ const attributes = { }
121
+ expect ( ( ) => addAttributesToActiveSpan ( ) ) . not . toThrowError ( )
122
+
123
+ expect ( span . attributes ) . toStrictEqual ( attributes )
124
+ } )
125
+ } )
126
+
127
+ test ( 'addAttributesToActiveSpan - does not throw without active span' , async ( ) => {
128
+ expect ( ( ) => addAttributesToActiveSpan ( ) ) . not . toThrowError ( )
129
+ } )
130
+
97
131
test ( 'setMultiSpanAttributes - baggage is populated' , async ( ) => {
98
132
const ctx = setMultiSpanAttributes ( { some : 'test' , foo : 'bar' } )
99
133
const baggage = propagation . getBaggage ( ctx )
0 commit comments