Skip to content

Commit

Permalink
Merge branch 'main' into dluna/update-tedious-support
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna committed May 10, 2024
2 parents 4b33aac + c1c3650 commit 5e8246d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/baggage-span-processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ APACHE 2.0 - See [LICENSE][license-url] for more information.
[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@opentelemetry/host-metrics
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fhost-metrics.svg
[npm-url]: https://www.npmjs.com/package/@opentelemetry/baggage-span-processor
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fbaggage-span-processor.svg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import {
testInjection,
testNoInjection,
} from './common';
import {
runTestFixture,
TestCollector,
} from '@opentelemetry/contrib-test-utils';

import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
Expand Down Expand Up @@ -235,4 +239,74 @@ describe('PinoInstrumentation', () => {
});
});
});
describe('ESM usage', () => {
beforeEach(() => {
testContext = setupInstrumentationAndInitTestContext();
});
it('should work with ESM default import', async function () {
testContext = setupInstrumentationAndInitTestContext();
let logRecords: any[];
await runTestFixture({
cwd: __dirname,
argv: ['fixtures/use-pino-default-import.mjs'],
env: {
NODE_OPTIONS:
'--experimental-loader=@opentelemetry/instrumentation/hook.mjs',
NODE_NO_WARNINGS: '1',
},
checkResult: (err, stdout, _stderr) => {
assert.ifError(err);
logRecords = stdout
.trim()
.split('\n')
.map(ln => JSON.parse(ln));
assert.strictEqual(logRecords.length, 1);
},
checkCollector: (collector: TestCollector) => {
// Check that both log records had the trace-context of the span injected.
const spans = collector.sortedSpans;
assert.strictEqual(spans.length, 1);
logRecords.forEach(rec => {
assert.strictEqual(rec.trace_id, spans[0].traceId);
assert.strictEqual(rec.span_id, spans[0].spanId);
});
},
});
});

it('should work with ESM named import', async function () {
if (semver.lt(testContext.pino.version, '6.8.0')) {
// Pino 6.8.0 added named ESM exports (https://github.com/pinojs/pino/pull/936).
this.skip();
} else {
let logRecords: any[];
await runTestFixture({
cwd: __dirname,
argv: ['fixtures/use-pino-named-import.mjs'],
env: {
NODE_OPTIONS:
'--experimental-loader=@opentelemetry/instrumentation/hook.mjs',
NODE_NO_WARNINGS: '1',
},
checkResult: (err, stdout, _stderr) => {
assert.ifError(err);
logRecords = stdout
.trim()
.split('\n')
.map(ln => JSON.parse(ln));
assert.strictEqual(logRecords.length, 1);
},
checkCollector: (collector: TestCollector) => {
// Check that both log records had the trace-context of the span injected.
const spans = collector.sortedSpans;
assert.strictEqual(spans.length, 1);
logRecords.forEach(rec => {
assert.strictEqual(rec.trace_id, spans[0].traceId);
assert.strictEqual(rec.span_id, spans[0].spanId);
});
},
});
}
});
});
});

0 comments on commit 5e8246d

Please sign in to comment.