Skip to content

Commit

Permalink
chore: prepare DASH0_DEBUG_PRINT_METRICS
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jun 11, 2024
1 parent d3f4769 commit 1abe2b0
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions test/integration/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { SpanKind } from '@opentelemetry/api';
import { expect } from 'chai';
import { open, readFile, unlink } from 'node:fs/promises';
import { FileHandle, open, readFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
import semver from 'semver';

Expand Down Expand Up @@ -129,44 +129,46 @@ describe('attach', () => {

describe('print spans to file', () => {
let appUnderTest: ChildProcessWrapper;
const filename = join(__dirname, 'spans.json');
const spanFilename = join(__dirname, 'spans.json');
// const metricsFilename = join(__dirname, 'metrics.json');

before(async () => {
try {
await unlink(filename);
await unlink(spanFilename);
// await unlink(metricsFilename);
} catch {
// expected outcome, file did not exist
// expected outcome, files did not exist
}

const appConfiguration = defaultAppConfiguration(appPort);
appConfiguration.env!.DASH0_DEBUG_PRINT_SPANS = filename;
appConfiguration.env!.DASH0_DEBUG_PRINT_SPANS = spanFilename;
// appConfiguration.env!.DASH0_DEBUG_PRINT_METRICS = metricsFilename;
appUnderTest = new ChildProcessWrapper(appConfiguration);
await appUnderTest.start();
});

after(async () => {
await appUnderTest.stop();
try {
await unlink(filename);
await unlink(spanFilename);
// await unlink(metricsFilename);
} catch (e) {
// ignore
}
});

it('should attach via --require and print spans to target file', async () => {
it('should attach via --require and print spans to the configured file', async () => {
// await waitUntil(async () => {
// const metricsFile = await verifyFileHasBeenCreated(metricsFilename);
// const metrics = JSON.parse(String(await metricsFile.readFile()));
// expect(metrics).to.not.be.empty;
// });

await waitUntil(async () => {
await sendRequestAndVerifyResponse();
let file;
try {
file = await open(filename);
} catch (e: any) {
if (e.code && e.code === 'ENOENT') {
fail(`The Dash0 Node.js distribution in the application under test did not create the file ${filename}.`);
}
throw e;
}
const spanFile = await verifyFileHasBeenCreated(spanFilename);
const spans = [];
for await (const line of file.readLines()) {
for await (const line of spanFile.readLines()) {
try {
spans.push(JSON.parse(line));
} catch (error) {
Expand Down Expand Up @@ -229,4 +231,17 @@ describe('attach', () => {
const responsePayload = await response.json();
expect(responsePayload).to.deep.equal({ message: 'We make Observability easy for every developer.' });
}

async function verifyFileHasBeenCreated(filename: string): Promise<FileHandle> {
let file;
try {
file = await open(filename);
} catch (e: any) {
if (e.code && e.code === 'ENOENT') {
fail(`The Dash0 Node.js distribution in the application under test did not create the file ${filename}.`);
}
throw e;
}
return file;
}
});

0 comments on commit 1abe2b0

Please sign in to comment.