mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-10-31 11:11:19 +00:00
Exports application logs as OTel log records when OTEL_LOGS_ENABLED=true, correlated with the active trace, and gates every signal explicitly so a disabled signal never falls back to the SDK's default OTLP exporter. Verified end to end over OTLP/gRPC against an in-process collector.
42 lines
1 KiB
JavaScript
42 lines
1 KiB
JavaScript
require('dotenv').config();
|
|
|
|
function isTruthy(value) {
|
|
return value?.trim().toLowerCase() === 'true';
|
|
}
|
|
|
|
function isTelemetryEnabled() {
|
|
const signalEnabled =
|
|
isTruthy(process.env.OTEL_TRACING_ENABLED) || isTruthy(process.env.OTEL_LOGS_ENABLED);
|
|
return signalEnabled && !isTruthy(process.env.OTEL_SDK_DISABLED);
|
|
}
|
|
|
|
if (isTelemetryEnabled()) {
|
|
const {
|
|
initializeTelemetry,
|
|
telemetryMiddleware,
|
|
telemetryErrorMiddleware,
|
|
} = require('@librechat/api/telemetry');
|
|
const controller = initializeTelemetry();
|
|
|
|
module.exports = {
|
|
get enabled() {
|
|
return controller.enabled;
|
|
},
|
|
get status() {
|
|
return controller.status;
|
|
},
|
|
shutdown: controller.shutdown,
|
|
telemetryMiddleware,
|
|
telemetryErrorMiddleware,
|
|
};
|
|
} else {
|
|
module.exports = {
|
|
enabled: false,
|
|
get status() {
|
|
return 'disabled';
|
|
},
|
|
shutdown: async () => {},
|
|
telemetryMiddleware: (_req, _res, next) => next(),
|
|
telemetryErrorMiddleware: (err, _req, _res, next) => next(err),
|
|
};
|
|
}
|