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
9 changes: 9 additions & 0 deletions lib/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ export async function openpgp(): Promise<typeof import('openpgp')> {
* return's sqlite
*/
export async function sqlite(): Promise<typeof import('better-sqlite3')> {
// return default because it's cjs
return (await import('better-sqlite3')).default;
}

/**
* return's bunyan
*/
export function bunyan(): typeof import('bunyan') {
// use `require` to allow opentelemetry instrumentation
return require('bunyan');
}
8 changes: 3 additions & 5 deletions lib/instrumentation/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createRequire } from 'node:module';
import * as api from '@opentelemetry/api';
import { ProxyTracerProvider } from '@opentelemetry/api';
import {
NodeTracerProvider,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-node';
import { bunyan } from '../expose.ts';
import { GetDatasourceReleasesSpanProcessor } from '../modules/datasource/span-processor.ts';
import { GitOperationSpanProcessor } from '../util/git/span-processor.ts';
import {
Expand Down Expand Up @@ -162,13 +162,11 @@ describe('instrumentation/index', () => {
process.env.RENOVATE_TRACING_CONSOLE_EXPORTER = 'true';
init();

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

// shimmer marks wrapped functions with __wrapped = true
expect(
(bunyan.prototype as unknown as Record<string, unknown>)._emit,
(mod.prototype as unknown as Record<string, unknown>)._emit,
).toHaveProperty('__wrapped', true);
});
});
Expand Down
12 changes: 3 additions & 9 deletions lib/logger/bunyan.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { createRequire } from 'node:module';
import {
isNonEmptyStringAndNotWhitespace,
isString,
isUndefined,
} from '@sindresorhus/is';

// 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');

import fs from 'fs-extra';
import upath from 'upath';
import { bunyan } from '../expose.ts';
import cmdSerializer from './cmd-serializer.ts';
import configSerializer from './config-serializer.ts';
import errSerializer from './err-serializer.ts';
Expand Down Expand Up @@ -87,7 +81,7 @@ function createLogFileStream(logFile: string): BunyanStream {
}

function serializedSanitizedLogger(streams: BunyanStream[]): BunyanLogger {
return bunyan.createLogger({
return bunyan().createLogger({
name: 'renovate',
serializers: {
body: configSerializer,
Expand Down Expand Up @@ -144,7 +138,7 @@ export function validateLogLevel(
return (logLevelToCheck as BunyanLogLevel) ?? defaultLevel;
}

const logger = bunyan.createLogger({
const logger = bunyan().createLogger({
name: 'renovate',
streams: [
{
Expand Down
Loading