-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create bootstrap span on demand (DASH0_BOOTSTRAP_SPAN.)
- Loading branch information
Showing
5 changed files
with
154 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ describe('attach', () => { | |
expectedDistroVersion = JSON.parse(String(await readFile('package.json'))).version; | ||
}); | ||
|
||
describe('tracing', () => { | ||
describe('basic tracing', () => { | ||
let appUnderTest: ChildProcessWrapper; | ||
|
||
before(async () => { | ||
|
@@ -49,7 +49,7 @@ describe('attach', () => { | |
|
||
it('should attach via --require and capture spans', async () => { | ||
await waitUntil(async () => { | ||
const telemetry = await waitForTelemetry(); | ||
const telemetry = await sendRequestAndWaitForTraceData(); | ||
expectMatchingSpan( | ||
telemetry.traces, | ||
[ | ||
|
@@ -59,7 +59,7 @@ describe('attach', () => { | |
resource => expectResourceAttribute(resource, 'telemetry.distro.version', expectedDistroVersion), | ||
], | ||
[ | ||
span => expect(span.kind).to.equal(SpanKind.SERVER), | ||
span => expect(span.kind).to.equal(SpanKind.SERVER, 'span kind should be server'), | ||
span => expectSpanAttribute(span, 'http.route', '/ohai'), | ||
], | ||
); | ||
|
@@ -83,12 +83,12 @@ describe('attach', () => { | |
|
||
it('should attach via --require and detect the pod uid', async () => { | ||
await waitUntil(async () => { | ||
const telemetry = await waitForTelemetry(); | ||
const telemetry = await sendRequestAndWaitForTraceData(); | ||
expectMatchingSpan( | ||
telemetry.traces, | ||
[resource => expectResourceAttribute(resource, 'k8s.pod.uid', 'f57400dc-94ce-4806-a52e-d2726f448f15')], | ||
[ | ||
span => expect(span.kind).to.equal(SpanKind.SERVER), | ||
span => expect(span.kind).to.equal(SpanKind.SERVER, 'span kind should be server'), | ||
span => expectSpanAttribute(span, 'http.route', '/ohai'), | ||
], | ||
); | ||
|
@@ -111,22 +111,53 @@ describe('attach', () => { | |
|
||
it('should attach via --require and derive a service name from the package.json file', async () => { | ||
await waitUntil(async () => { | ||
const telemetry = await waitForTelemetry(); | ||
const telemetry = await sendRequestAndWaitForTraceData(); | ||
expectMatchingSpan( | ||
telemetry.traces, | ||
[ | ||
resource => | ||
expectResourceAttribute(resource, 'service.name', '[email protected]'), | ||
], | ||
[ | ||
span => expect(span.kind).to.equal(SpanKind.SERVER), | ||
span => expect(span.kind).to.equal(SpanKind.SERVER, 'span kind should be server'), | ||
span => expectSpanAttribute(span, 'http.route', '/ohai'), | ||
], | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('bootstrap span', () => { | ||
let appUnderTest: ChildProcessWrapper; | ||
|
||
before(async () => { | ||
const appConfiguration = defaultAppConfiguration(appPort); | ||
appConfiguration.env!.DASH0_BOOTSTRAP_SPAN = 'Dash0 Test Bootstrap Span'; | ||
appUnderTest = new ChildProcessWrapper(appConfiguration); | ||
await appUnderTest.start(); | ||
}); | ||
|
||
after(async () => { | ||
await appUnderTest.stop(); | ||
}); | ||
|
||
it('should create an internal span on bootstrap', async () => { | ||
await waitUntil(async () => { | ||
const telemetry = await waitForTraceData(); | ||
expectMatchingSpan( | ||
telemetry.traces, | ||
[ | ||
resource => expectResourceAttribute(resource, 'telemetry.sdk.name', 'opentelemetry'), | ||
resource => expectResourceAttribute(resource, 'telemetry.sdk.language', 'nodejs'), | ||
resource => expectResourceAttribute(resource, 'telemetry.distro.name', 'dash0-nodejs'), | ||
resource => expectResourceAttribute(resource, 'telemetry.distro.version', expectedDistroVersion), | ||
], | ||
[span => expect(span.name).to.equal('Dash0 Test Bootstrap Span')], | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('print spans to file', () => { | ||
let appUnderTest: ChildProcessWrapper; | ||
const spanFilename = join(__dirname, 'spans.json'); | ||
|
@@ -185,7 +216,7 @@ describe('attach', () => { | |
resourceAttributes => | ||
expect(resourceAttributes['telemetry.distro.version']).to.equal(expectedDistroVersion), | ||
], | ||
[spanAttributes => expect(spanAttributes.kind).to.equal(SpanKind.SERVER)], | ||
[spanAttributes => expect(spanAttributes.kind).to.equal(SpanKind.SERVER, 'span kind should be server')], | ||
[spanAttributes => expect(spanAttributes['http.route']).to.equal('/ohai')], | ||
); | ||
}); | ||
|
@@ -217,12 +248,9 @@ describe('attach', () => { | |
}); | ||
}); | ||
|
||
async function waitForTelemetry() { | ||
async function sendRequestAndWaitForTraceData() { | ||
await sendRequestAndVerifyResponse(); | ||
if (!(await collector().hasTraces())) { | ||
throw new Error('The collector never received any spans.'); | ||
} | ||
return await collector().fetchTelemetry(); | ||
return waitForTraceData(); | ||
} | ||
|
||
async function sendRequestAndVerifyResponse() { | ||
|
@@ -232,6 +260,13 @@ describe('attach', () => { | |
expect(responsePayload).to.deep.equal({ message: 'We make Observability easy for every developer.' }); | ||
} | ||
|
||
async function waitForTraceData() { | ||
if (!(await collector().hasTraces())) { | ||
throw new Error('The collector never received any spans.'); | ||
} | ||
return await collector().fetchTelemetry(); | ||
} | ||
|
||
async function verifyFileHasBeenCreated(filename: string): Promise<FileHandle> { | ||
let file; | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.