Skip to content

Commit

Permalink
fix(server): cluster metrics duplicate (#9416)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Dec 30, 2024
1 parent cec4a4b commit e630290
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/backend/server/src/plugins/gcloud/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ import { MetricExporter } from '@google-cloud/opentelemetry-cloud-monitoring-exp
import { TraceExporter } from '@google-cloud/opentelemetry-cloud-trace-exporter';
import { GcpDetectorSync } from '@google-cloud/opentelemetry-resource-util';
import { Global, Provider } from '@nestjs/common';
import { getEnv } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import {
MetricReader,
PeriodicExportingMetricReader,
} from '@opentelemetry/sdk-metrics';
import { SpanExporter } from '@opentelemetry/sdk-trace-node';
import {
SEMRESATTRS_CONTAINER_NAME,
SEMRESATTRS_K8S_POD_NAME,
} from '@opentelemetry/semantic-conventions';

import { OptionalModule } from '../../base';
import { OpentelemetryFactory } from '../../base/metrics';

export class GCloudOpentelemetryFactory extends OpentelemetryFactory {
override getResource(): Resource {
return super.getResource().merge(new GcpDetectorSync().detect());
const env = getEnv();
return super
.getResource()
.merge(
new Resource({
[SEMRESATTRS_K8S_POD_NAME]: env.HOSTNAME,
[SEMRESATTRS_CONTAINER_NAME]: env.CONTAINER_NAME,
})
)
.merge(new GcpDetectorSync().detect());
}

override getMetricReader(): MetricReader {
Expand Down

0 comments on commit e630290

Please sign in to comment.