1
- import { InstrumentationTestRegistry } from "../../test/instrumentation_registry"
1
+ import {
2
+ InstrumentationTestRegistry ,
3
+ instrumentationNames
4
+ } from "../../test/instrumentation_registry"
2
5
import { Extension } from "../extension"
3
6
import { Client } from "../client"
4
7
import { Metrics } from "../metrics"
@@ -16,6 +19,7 @@ describe("Client", () => {
16
19
const DEFAULT_OPTS = { name, pushApiKey }
17
20
18
21
beforeEach ( ( ) => {
22
+ InstrumentationTestRegistry . clear ( )
19
23
client = new Client ( { ...DEFAULT_OPTS } )
20
24
} )
21
25
@@ -142,16 +146,37 @@ describe("Client", () => {
142
146
expect ( meter ) . toBeInstanceOf ( Metrics )
143
147
} )
144
148
149
+ it ( "initializes the OpenTelemetry SDK when active" , ( ) => {
150
+ client = new Client ( { ...DEFAULT_OPTS , active : true } )
151
+ expect ( InstrumentationTestRegistry . didInitializeSDK ) . toEqual ( true )
152
+ } )
153
+
154
+ it ( "does not initialize the OpenTelemetry SDK when its config option is false" , ( ) => {
155
+ client = new Client ( {
156
+ ...DEFAULT_OPTS ,
157
+ active : true ,
158
+ initializeOpentelemetrySdk : false
159
+ } )
160
+ expect ( InstrumentationTestRegistry . didInitializeSDK ) . toEqual ( false )
161
+ } )
162
+
145
163
describe ( "Instrumentations" , ( ) => {
146
164
it ( "registers the default instrumentations" , ( ) => {
147
165
client = new Client ( { ...DEFAULT_OPTS , active : true } )
148
166
// Not testing against all of them or a fixed number so
149
167
// that we don't have to change these tests every time we
150
168
// add a new instrumentation.
151
- const instrumentationNames =
169
+ const registryInstrumentationNames =
152
170
InstrumentationTestRegistry . instrumentationNames ( )
153
- expect ( instrumentationNames . length ) . toBeGreaterThan ( 10 )
154
- expect ( instrumentationNames ) . toContain (
171
+ expect ( registryInstrumentationNames . length ) . toBeGreaterThan ( 10 )
172
+ expect ( registryInstrumentationNames ) . toContain (
173
+ "@opentelemetry/instrumentation-http"
174
+ )
175
+
176
+ const opentelemetryInstrumentations =
177
+ client . opentelemetryInstrumentations ( )
178
+ expect ( opentelemetryInstrumentations . length ) . toBeGreaterThan ( 10 )
179
+ expect ( instrumentationNames ( opentelemetryInstrumentations ) ) . toContain (
155
180
"@opentelemetry/instrumentation-http"
156
181
)
157
182
} )
@@ -165,6 +190,7 @@ describe("Client", () => {
165
190
const instrumentationNames =
166
191
InstrumentationTestRegistry . instrumentationNames ( )
167
192
expect ( instrumentationNames ) . toEqual ( [ ] )
193
+ expect ( client . opentelemetryInstrumentations ( ) ) . toEqual ( [ ] )
168
194
} )
169
195
170
196
it ( "can disable some default instrumentations" , ( ) => {
@@ -173,12 +199,19 @@ describe("Client", () => {
173
199
active : true ,
174
200
disableDefaultInstrumentations : [ "@opentelemetry/instrumentation-http" ]
175
201
} )
176
- const instrumentationNames =
202
+ const registryInstrumentationNames =
177
203
InstrumentationTestRegistry . instrumentationNames ( )
178
- expect ( instrumentationNames ) . not . toContain (
204
+ expect ( registryInstrumentationNames ) . not . toContain (
205
+ "@opentelemetry/instrumentation-http"
206
+ )
207
+ expect ( registryInstrumentationNames . length ) . toBeGreaterThan ( 10 )
208
+
209
+ const opentelemetryInstrumentations =
210
+ client . opentelemetryInstrumentations ( )
211
+ expect ( instrumentationNames ( opentelemetryInstrumentations ) ) . not . toContain (
179
212
"@opentelemetry/instrumentation-http"
180
213
)
181
- expect ( instrumentationNames . length ) . toBeGreaterThan ( 0 )
214
+ expect ( opentelemetryInstrumentations . length ) . toBeGreaterThan ( 10 )
182
215
} )
183
216
184
217
it ( "can add additional instrumentations" , ( ) => {
@@ -211,13 +244,22 @@ describe("Client", () => {
211
244
additionalInstrumentations : [ new TestInstrumentation ( ) ]
212
245
} )
213
246
214
- const instrumentationNames =
247
+ const registryInstrumentationNames =
215
248
InstrumentationTestRegistry . instrumentationNames ( )
216
- expect ( instrumentationNames ) . toContain (
249
+ expect ( registryInstrumentationNames ) . toContain (
250
+ "@opentelemetry/instrumentation-http"
251
+ )
252
+ expect ( registryInstrumentationNames . length ) . toBeGreaterThan ( 10 )
253
+ expect ( registryInstrumentationNames ) . toContain ( "test/instrumentation" )
254
+ const opentelemetryInstrumentations =
255
+ client . opentelemetryInstrumentations ( )
256
+ expect ( instrumentationNames ( opentelemetryInstrumentations ) ) . toContain (
217
257
"@opentelemetry/instrumentation-http"
218
258
)
219
- expect ( instrumentationNames . length ) . toBeGreaterThan ( 10 )
220
- expect ( instrumentationNames ) . toContain ( "test/instrumentation" )
259
+ expect ( opentelemetryInstrumentations . length ) . toBeGreaterThan ( 10 )
260
+ expect ( instrumentationNames ( opentelemetryInstrumentations ) ) . toContain (
261
+ "test/instrumentation"
262
+ )
221
263
} )
222
264
} )
223
265
} )
0 commit comments