Notes for OpenTelemetry Node.js developers

Instana supports standard OpenTelemetry JavaScript automatic or manual instrumentation for Node.js. For more information, see OpenTelemetry official documents.

Use proper "resource detectors" to improve the infrastructure entity correlation used in Instana. The OpenTelemetry JavaScript auto-instrumentation must declare resource detectors to have enough resource attributes. You must have an external Instrumentation.js that has resource detectors to support enough resource attributes. For example, @opentelemetry/resource-detector-container version 0.3.4 or later is required for linking in a container environment such as a Kubernetes or Red Hat OpenShift cluster. The following example is a Instrumentation.js that is used in the OpenTelemetry official demo:

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { alibabaCloudEcsDetector } = require('@opentelemetry/resource-detector-alibaba-cloud');
const { awsEc2Detector, awsEksDetector } = require('@opentelemetry/resource-detector-aws');
const { containerDetector } = require('@opentelemetry/resource-detector-container');
const { gcpDetector } = require('@opentelemetry/resource-detector-gcp');
const { envDetector, hostDetector, osDetector, processDetector } = require('@opentelemetry/resources');

const sdk = new opentelemetry.NodeSDK({
    traceExporter: new OTLPTraceExporter(),
    instrumentations: [getNodeAutoInstrumentations()],
    metricReader: new PeriodicExportingMetricReader({
        exporter: new OTLPMetricExporter(),
    }),
    resourceDetectors: [
        containerDetector,
        envDetector,
        hostDetector,
        osDetector,
        processDetector,
        alibabaCloudEcsDetector,
        awsEksDetector,
        awsEc2Detector,
        gcpDetector,
    ],
});

sdk.start();

For more information about Node.JS resource detector, see opentelemetry-js-contrib.