1
- import type { EvaluationDetails , HookContext } from '@openfeature/server-sdk' ;
1
+ import type { EvaluationDetails , HookContext } from '@openfeature/core' ;
2
+ import { MapHookData } from '@openfeature/core' ;
2
3
3
4
const addEvent = jest . fn ( ) ;
4
5
const recordException = jest . fn ( ) ;
@@ -12,7 +13,7 @@ jest.mock('@opentelemetry/api', () => ({
12
13
} ) ) ;
13
14
14
15
// Import must be after the mocks
15
- import { TracingHook } from './tracing-hook' ;
16
+ import { SpanEventTracingHook } from './tracing-hook' ;
16
17
17
18
describe ( 'OpenTelemetry Hooks' , ( ) => {
18
19
const hookContext : HookContext = {
@@ -30,9 +31,10 @@ describe('OpenTelemetry Hooks', () => {
30
31
defaultValue : true ,
31
32
flagValueType : 'boolean' ,
32
33
logger : console ,
34
+ hookData : new MapHookData ( ) ,
33
35
} ;
34
36
35
- let tracingHook : TracingHook ;
37
+ let tracingHook : SpanEventTracingHook ;
36
38
37
39
afterEach ( ( ) => {
38
40
jest . clearAllMocks ( ) ;
@@ -41,7 +43,7 @@ describe('OpenTelemetry Hooks', () => {
41
43
describe ( 'after stage' , ( ) => {
42
44
describe ( 'no attribute mapper' , ( ) => {
43
45
beforeEach ( ( ) => {
44
- tracingHook = new TracingHook ( ) ;
46
+ tracingHook = new SpanEventTracingHook ( ) ;
45
47
} ) ;
46
48
47
49
it ( 'should use the variant value on the span event' , ( ) => {
@@ -52,7 +54,7 @@ describe('OpenTelemetry Hooks', () => {
52
54
flagMetadata : { } ,
53
55
} ;
54
56
55
- tracingHook . after ( hookContext , evaluationDetails ) ;
57
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
56
58
57
59
expect ( addEvent ) . toBeCalledWith ( 'feature_flag' , {
58
60
'feature_flag.key' : 'testFlagKey' ,
@@ -68,7 +70,7 @@ describe('OpenTelemetry Hooks', () => {
68
70
flagMetadata : { } ,
69
71
} ;
70
72
71
- tracingHook . after ( hookContext , evaluationDetails ) ;
73
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
72
74
73
75
expect ( addEvent ) . toBeCalledWith ( 'feature_flag' , {
74
76
'feature_flag.key' : 'testFlagKey' ,
@@ -83,7 +85,7 @@ describe('OpenTelemetry Hooks', () => {
83
85
value : 'already-string' ,
84
86
flagMetadata : { } ,
85
87
} ;
86
- tracingHook . after ( hookContext , evaluationDetails ) ;
88
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
87
89
88
90
expect ( addEvent ) . toBeCalledWith ( 'feature_flag' , {
89
91
'feature_flag.key' : 'testFlagKey' ,
@@ -101,15 +103,15 @@ describe('OpenTelemetry Hooks', () => {
101
103
flagMetadata : { } ,
102
104
} ;
103
105
104
- tracingHook . after ( hookContext , evaluationDetails ) ;
106
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
105
107
expect ( addEvent ) . not . toBeCalled ( ) ;
106
108
} ) ;
107
109
} ) ;
108
110
109
111
describe ( 'attribute mapper configured' , ( ) => {
110
112
describe ( 'no error in mapper' , ( ) => {
111
113
beforeEach ( ( ) => {
112
- tracingHook = new TracingHook ( {
114
+ tracingHook = new SpanEventTracingHook ( {
113
115
attributeMapper : ( flagMetadata ) => {
114
116
return {
115
117
customAttr1 : flagMetadata . metadata1 ,
@@ -132,7 +134,7 @@ describe('OpenTelemetry Hooks', () => {
132
134
} ,
133
135
} ;
134
136
135
- tracingHook . after ( hookContext , evaluationDetails ) ;
137
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
136
138
137
139
expect ( addEvent ) . toBeCalledWith ( 'feature_flag' , {
138
140
'feature_flag.key' : 'testFlagKey' ,
@@ -147,7 +149,7 @@ describe('OpenTelemetry Hooks', () => {
147
149
148
150
describe ( 'error in mapper' , ( ) => {
149
151
beforeEach ( ( ) => {
150
- tracingHook = new TracingHook ( {
152
+ tracingHook = new SpanEventTracingHook ( {
151
153
attributeMapper : ( ) => {
152
154
throw new Error ( 'fake error' ) ;
153
155
} ,
@@ -166,7 +168,7 @@ describe('OpenTelemetry Hooks', () => {
166
168
} ,
167
169
} ;
168
170
169
- tracingHook . after ( hookContext , evaluationDetails ) ;
171
+ tracingHook . finally ( hookContext , evaluationDetails ) ;
170
172
171
173
expect ( addEvent ) . toBeCalledWith ( 'feature_flag' , {
172
174
'feature_flag.key' : 'testFlagKey' ,
0 commit comments