Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ COPY . .
RUN npm run build

# Start the server using the production build
CMD [ "node", "dist/main.js" ]
CMD [ "node", "--require", "./otlp.js", "dist/main.js" ]
6 changes: 6 additions & 0 deletions docker-compose-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ services:
target: production
environment:
DATABASE_URI: mongodb://inventory-db:27017
OTEL_TRACES_EXPORTER: none
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector:4318"
OTEL_NODE_RESOURCE_DETECTORS: env,host,os
OTEL_SERVICE_NAME: inventory
OTEL_SEMCONV_STABILITY_OPT_IN: http
NODE_OPTIONS: --require @opentelemetry/auto-instrumentations-node/register
depends_on:
- inventory-db
inventory-db:
Expand Down
23 changes: 23 additions & 0 deletions otlp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http');
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');

const sdk = new NodeSDK({
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({ url: 'http://otel-collector:4318/v1/metrics' }),
exportIntervalMillis: 5000,
}),
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-http': {
'enabled': true,
'enhancedMetrics': true,
'tracing': false,
},
}),
],
});

sdk.start();
console.log('OpenTelemetry initialized ✅');
Loading