@@ -34,7 +34,11 @@ describe('attach', () => {
34
34
expectedDistroVersion = JSON . parse ( String ( await readFile ( 'package.json' ) ) ) . version ;
35
35
} ) ;
36
36
37
- describe ( 'tracing' , ( ) => {
37
+ beforeEach ( async function ( ) {
38
+ collector ( ) . clear ( ) ;
39
+ } ) ;
40
+
41
+ describe ( 'basic tracing' , ( ) => {
38
42
let appUnderTest : ChildProcessWrapper ;
39
43
40
44
before ( async ( ) => {
@@ -49,7 +53,7 @@ describe('attach', () => {
49
53
50
54
it ( 'should attach via --require and capture spans' , async ( ) => {
51
55
await waitUntil ( async ( ) => {
52
- const telemetry = await waitForTelemetry ( ) ;
56
+ const telemetry = await sendRequestAndWaitForTraceData ( ) ;
53
57
expectMatchingSpan (
54
58
telemetry . traces ,
55
59
[
@@ -59,7 +63,7 @@ describe('attach', () => {
59
63
resource => expectResourceAttribute ( resource , 'telemetry.distro.version' , expectedDistroVersion ) ,
60
64
] ,
61
65
[
62
- span => expect ( span . kind ) . to . equal ( SpanKind . SERVER ) ,
66
+ span => expect ( span . kind ) . to . equal ( SpanKind . SERVER , 'span kind should be server' ) ,
63
67
span => expectSpanAttribute ( span , 'http.route' , '/ohai' ) ,
64
68
] ,
65
69
) ;
@@ -83,12 +87,12 @@ describe('attach', () => {
83
87
84
88
it ( 'should attach via --require and detect the pod uid' , async ( ) => {
85
89
await waitUntil ( async ( ) => {
86
- const telemetry = await waitForTelemetry ( ) ;
90
+ const telemetry = await sendRequestAndWaitForTraceData ( ) ;
87
91
expectMatchingSpan (
88
92
telemetry . traces ,
89
93
[ resource => expectResourceAttribute ( resource , 'k8s.pod.uid' , 'f57400dc-94ce-4806-a52e-d2726f448f15' ) ] ,
90
94
[
91
- span => expect ( span . kind ) . to . equal ( SpanKind . SERVER ) ,
95
+ span => expect ( span . kind ) . to . equal ( SpanKind . SERVER , 'span kind should be server' ) ,
92
96
span => expectSpanAttribute ( span , 'http.route' , '/ohai' ) ,
93
97
] ,
94
98
) ;
@@ -111,22 +115,56 @@ describe('attach', () => {
111
115
112
116
it ( 'should attach via --require and derive a service name from the package.json file' , async ( ) => {
113
117
await waitUntil ( async ( ) => {
114
- const telemetry = await waitForTelemetry ( ) ;
118
+ const telemetry = await sendRequestAndWaitForTraceData ( ) ;
115
119
expectMatchingSpan (
116
120
telemetry . traces ,
117
121
[
118
122
resource =>
119
123
expectResourceAttribute ( resource , 'service.name' , '[email protected] ' ) ,
120
124
] ,
121
125
[
122
- span => expect ( span . kind ) . to . equal ( SpanKind . SERVER ) ,
126
+ span => expect ( span . kind ) . to . equal ( SpanKind . SERVER , 'span kind should be server' ) ,
123
127
span => expectSpanAttribute ( span , 'http.route' , '/ohai' ) ,
124
128
] ,
125
129
) ;
126
130
} ) ;
127
131
} ) ;
128
132
} ) ;
129
133
134
+ describe ( 'bootstrap span' , ( ) => {
135
+ let appUnderTest : ChildProcessWrapper ;
136
+
137
+ before ( async ( ) => {
138
+ const appConfiguration = defaultAppConfiguration ( appPort ) ;
139
+ appConfiguration . env ! . DASH0_BOOTSTRAP_SPAN = 'Dash0 Test Bootstrap Span' ;
140
+ appUnderTest = new ChildProcessWrapper ( appConfiguration ) ;
141
+ } ) ;
142
+
143
+ after ( async ( ) => {
144
+ await appUnderTest . stop ( ) ;
145
+ } ) ;
146
+
147
+ it ( 'should create an internal span on bootstrap' , async ( ) => {
148
+ // It is important for this test that we do not start the app in the before hook, since the beforeEach from the
149
+ // top level suite clears the mock collector's spans, thus we would accidentally delete the bootstrap span
150
+ // (because the top level beforeHook is executed after this suite's before hook).
151
+ await appUnderTest . start ( ) ;
152
+ await waitUntil ( async ( ) => {
153
+ const telemetry = await waitForTraceData ( ) ;
154
+ expectMatchingSpan (
155
+ telemetry . traces ,
156
+ [
157
+ resource => expectResourceAttribute ( resource , 'telemetry.sdk.name' , 'opentelemetry' ) ,
158
+ resource => expectResourceAttribute ( resource , 'telemetry.sdk.language' , 'nodejs' ) ,
159
+ resource => expectResourceAttribute ( resource , 'telemetry.distro.name' , 'dash0-nodejs' ) ,
160
+ resource => expectResourceAttribute ( resource , 'telemetry.distro.version' , expectedDistroVersion ) ,
161
+ ] ,
162
+ [ span => expect ( span . name ) . to . equal ( 'Dash0 Test Bootstrap Span' ) ] ,
163
+ ) ;
164
+ } ) ;
165
+ } ) ;
166
+ } ) ;
167
+
130
168
describe ( 'print spans to file' , ( ) => {
131
169
let appUnderTest : ChildProcessWrapper ;
132
170
const spanFilename = join ( __dirname , 'spans.json' ) ;
@@ -185,7 +223,7 @@ describe('attach', () => {
185
223
resourceAttributes =>
186
224
expect ( resourceAttributes [ 'telemetry.distro.version' ] ) . to . equal ( expectedDistroVersion ) ,
187
225
] ,
188
- [ spanAttributes => expect ( spanAttributes . kind ) . to . equal ( SpanKind . SERVER ) ] ,
226
+ [ spanAttributes => expect ( spanAttributes . kind ) . to . equal ( SpanKind . SERVER , 'span kind should be server' ) ] ,
189
227
[ spanAttributes => expect ( spanAttributes [ 'http.route' ] ) . to . equal ( '/ohai' ) ] ,
190
228
) ;
191
229
} ) ;
@@ -217,12 +255,9 @@ describe('attach', () => {
217
255
} ) ;
218
256
} ) ;
219
257
220
- async function waitForTelemetry ( ) {
258
+ async function sendRequestAndWaitForTraceData ( ) {
221
259
await sendRequestAndVerifyResponse ( ) ;
222
- if ( ! ( await collector ( ) . hasTraces ( ) ) ) {
223
- throw new Error ( 'The collector never received any spans.' ) ;
224
- }
225
- return await collector ( ) . fetchTelemetry ( ) ;
260
+ return waitForTraceData ( ) ;
226
261
}
227
262
228
263
async function sendRequestAndVerifyResponse ( ) {
@@ -232,6 +267,13 @@ describe('attach', () => {
232
267
expect ( responsePayload ) . to . deep . equal ( { message : 'We make Observability easy for every developer.' } ) ;
233
268
}
234
269
270
+ async function waitForTraceData ( ) {
271
+ if ( ! ( await collector ( ) . hasTraces ( ) ) ) {
272
+ throw new Error ( 'The collector never received any spans.' ) ;
273
+ }
274
+ return await collector ( ) . fetchTelemetry ( ) ;
275
+ }
276
+
235
277
async function verifyFileHasBeenCreated ( filename : string ) : Promise < FileHandle > {
236
278
let file ;
237
279
try {
0 commit comments