mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(server): otel not working due to port conflicts after combining containers (#10078)
fix: otel not working due to port conflicts after combining containers Fixes #9759
This commit is contained in:
parent
20efd82461
commit
2f2aecfb47
6 changed files with 44 additions and 26 deletions
|
|
@ -33,23 +33,36 @@ const aggregation = new metrics.ExplicitBucketHistogramAggregation(
|
|||
true,
|
||||
);
|
||||
|
||||
const metricsPort = Number.parseInt(process.env.IMMICH_METRICS_PORT ?? '8081');
|
||||
let otelSingleton: NodeSDK | undefined;
|
||||
|
||||
export const otelSDK = new NodeSDK({
|
||||
resource: new resources.Resource({
|
||||
[SemanticResourceAttributes.SERVICE_NAME]: `immich`,
|
||||
[SemanticResourceAttributes.SERVICE_VERSION]: serverVersion.toString(),
|
||||
}),
|
||||
metricReader: new PrometheusExporter({ port: metricsPort }),
|
||||
contextManager: new AsyncLocalStorageContextManager(),
|
||||
instrumentations: [
|
||||
new HttpInstrumentation(),
|
||||
new IORedisInstrumentation(),
|
||||
new NestInstrumentation(),
|
||||
new PgInstrumentation(),
|
||||
],
|
||||
views: [new metrics.View({ aggregation, instrumentName: '*', instrumentUnit: 'ms' })],
|
||||
});
|
||||
export const otelStart = (port: number) => {
|
||||
if (otelSingleton) {
|
||||
throw new Error('OpenTelemetry SDK already started');
|
||||
}
|
||||
otelSingleton = new NodeSDK({
|
||||
resource: new resources.Resource({
|
||||
[SemanticResourceAttributes.SERVICE_NAME]: `immich`,
|
||||
[SemanticResourceAttributes.SERVICE_VERSION]: serverVersion.toString(),
|
||||
}),
|
||||
metricReader: new PrometheusExporter({ port }),
|
||||
contextManager: new AsyncLocalStorageContextManager(),
|
||||
instrumentations: [
|
||||
new HttpInstrumentation(),
|
||||
new IORedisInstrumentation(),
|
||||
new NestInstrumentation(),
|
||||
new PgInstrumentation(),
|
||||
],
|
||||
views: [new metrics.View({ aggregation, instrumentName: '*', instrumentUnit: 'ms' })],
|
||||
});
|
||||
otelSingleton.start();
|
||||
};
|
||||
|
||||
export const otelShutdown = async () => {
|
||||
if (otelSingleton) {
|
||||
await otelSingleton.shutdown();
|
||||
otelSingleton = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const otelConfig: OpenTelemetryModuleOptions = {
|
||||
metrics: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue