Files
renovate/lib/instrumentation/utils.ts
Jamie Tanna 0879ce538f feat(instrumentation): add support for protobuf + gRPC exporter (#45527)
As noted in #36073, having support for the different protocols for
exporting OpenTelemetry data would be useful, especially if this is
leading to users seeing issues when they have auto-injected
configuration being set.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-28 11:28:53 +00:00

53 lines
1.8 KiB
TypeScript

import { isNullOrUndefined } from '@sindresorhus/is';
import { getEnv } from '../util/env.ts';
export type OtlpProtocol = 'grpc' | 'http/json' | 'http/protobuf';
const otlpProtocols: OtlpProtocol[] = ['grpc', 'http/json', 'http/protobuf'];
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#otlp-exporter
// `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` takes precedence over the general `OTEL_EXPORTER_OTLP_PROTOCOL`.
// Defaults to `http/json`, matching Renovate's historic (pre-multi-protocol) behaviour, rather than the spec's `http/protobuf` default, to avoid a breaking change for existing users who haven't set this variable.
export function getOtlpProtocol(): OtlpProtocol {
const protocol =
getEnv().OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ??
getEnv().OTEL_EXPORTER_OTLP_PROTOCOL;
return otlpProtocols.includes(protocol as OtlpProtocol)
? (protocol as OtlpProtocol)
: 'http/json';
}
export function isTracingEnabled(): boolean {
return (
isTraceDebuggingEnabled() ||
isTraceSendingEnabled() ||
isFileExporterEnabled()
);
}
export function isTraceDebuggingEnabled(): boolean {
return !!getEnv().RENOVATE_TRACING_CONSOLE_EXPORTER;
}
export function isTraceSendingEnabled(): boolean {
return !!getEnv().OTEL_EXPORTER_OTLP_ENDPOINT;
}
export function isFileExporterEnabled(): boolean {
return !!getEnv().RENOVATE_TRACING_FILE_EXPORTER_PATH;
}
export function getFileExporterPath(): string {
return getEnv().RENOVATE_TRACING_FILE_EXPORTER_PATH!;
}
export function massageThrowable(e: unknown): string | undefined {
if (isNullOrUndefined(e)) {
return undefined;
}
if (e instanceof Error) {
return e.message;
}
return String(e); // oxlint-disable-line typescript/no-base-to-string
}