From 8cba35135ff33e5a30635f3068c0a2f2191c1057 Mon Sep 17 00:00:00 2001 From: Matthias Theuermann Date: Thu, 11 Jan 2024 13:26:54 +0100 Subject: [PATCH] fix: node.js metric instrumentation --- .../kubernetes/node-controller.yaml | 6 ++-- .../node/instrumentation.js | 30 ------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/dapr-distributed-calendar/kubernetes/node-controller.yaml b/dapr-distributed-calendar/kubernetes/node-controller.yaml index f68e58b..0c2d930 100644 --- a/dapr-distributed-calendar/kubernetes/node-controller.yaml +++ b/dapr-distributed-calendar/kubernetes/node-controller.yaml @@ -47,10 +47,8 @@ spec: env: - name: APP_PORT value: "3000" - # - name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - # value: "otel-dapr-collector:4317" - # - name: OTEL_SERVICE_NAME - # value: "controller" + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: "http://otel-dapr-collector:4317" ports: - containerPort: 3000 imagePullPolicy: Always diff --git a/dapr-distributed-calendar/node/instrumentation.js b/dapr-distributed-calendar/node/instrumentation.js index 42ac4e6..17022e4 100644 --- a/dapr-distributed-calendar/node/instrumentation.js +++ b/dapr-distributed-calendar/node/instrumentation.js @@ -1,9 +1,7 @@ /*instrumentation.js*/ -// only console exporter seems to work const opentelemetry = require('@opentelemetry/api'); const { MeterProvider, - ConsoleMetricExporter, PeriodicExportingMetricReader, } = require('@opentelemetry/sdk-metrics'); const { @@ -24,9 +22,7 @@ const resource = Resource.default().merge( const metricReader = new PeriodicExportingMetricReader({ exporter: new OTLPMetricExporter({ - url: 'http://otel-dapr-collector:4317', }), - exporter: new ConsoleMetricExporter(), }); const myServiceMeterProvider = new MeterProvider({ @@ -37,29 +33,3 @@ myServiceMeterProvider.addMetricReader(metricReader); // Set this MeterProvider to be global to the app being instrumented. opentelemetry.metrics.setGlobalMeterProvider(myServiceMeterProvider); - - - - -// possible other solution dont forget to set OTEL_EXPORTER_OTLP_METRICS_ENDPOINT env in pod -// const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics'); -// const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc'); - -// const metricExporter = new OTLPMetricExporter(); -// const resource = Resource.default().merge( -// new Resource({ -// [SemanticResourceAttributes.SERVICE_NAME]: 'controller', -// [SemanticResourceAttributes.SERVICE_VERSION]: '0.1.0', -// }), -// ); -// const meterProvider = new MeterProvider({ -// resource: resource -// }); - -// meterProvider.addMetricReader(new PeriodicExportingMetricReader({ -// exporter: metricExporter, -// exportIntervalMillis: 1000, -// })); - -// // Set this MeterProvider to be global to the app being instrumented. -// opentelemetry.metrics.setGlobalMeterProvider(meterProvider);