Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/instrumentation/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createRequire } from 'node:module';
import * as api from '@opentelemetry/api';
import { ProxyTracerProvider } from '@opentelemetry/api';
import {
Expand Down Expand Up @@ -153,6 +154,25 @@ describe('instrumentation/index', () => {
});
});

describe('BunyanInstrumentation', () => {
// OpenTelemetry's context propagation currently uses `AsyncLocalStorage`, which does not behave the same way in vitest worker threads as in a real Node.js process, so we cannot write a full end-to-end here to validate the `span_id`, `trace_id` and `trace_flags` are set
//
// Claude Sonnet 4.6 suggests that we instead create an (admittedly brittle) test to validate that this is marked as `__wrapped`.
it('patches bunyan Logger._emit when tracing is enabled', () => {
process.env.RENOVATE_TRACING_CONSOLE_EXPORTER = 'true';
init();

const bunyan = createRequire(import.meta.url)(
'bunyan',
) as typeof import('bunyan');

// shimmer marks wrapped functions with __wrapped = true
expect(
(bunyan.prototype as unknown as Record<string, unknown>)._emit,
).toHaveProperty('__wrapped', true);
});
});

describe('instrument', () => {
it('should return result', () => {
const value = 'testResult';
Expand Down
9 changes: 8 additions & 1 deletion lib/logger/bunyan.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { createRequire } from 'node:module';
import {
isNonEmptyStringAndNotWhitespace,
isString,
isUndefined,
} from '@sindresorhus/is';
import * as bunyan from 'bunyan';

// Use createRequire so that @opentelemetry/instrumentation-bunyan can patch
// bunyan via require-in-the-middle. A plain ESM `import` bypasses the hook.
const bunyan = createRequire(import.meta.url)(
'bunyan',
) as typeof import('bunyan');
Comment on lines +10 to +12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should refactor to use our expost.ts (like we do with prettier and re2). will send a pr later


import fs from 'fs-extra';
import upath from 'upath';
import cmdSerializer from './cmd-serializer.ts';
Expand Down
Loading