From harness-claude
Initializes the OpenTelemetry Node.js SDK with resource attributes, OTLP exporters, and auto-instrumentation for traces and metrics.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:otel-sdk-setupThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Initialize the OpenTelemetry Node.js SDK with resource attributes, exporters, and auto-instrumentation
Initialize the OpenTelemetry Node.js SDK with resource attributes, exporters, and auto-instrumentation
instrumentation.ts) — it must run before any other application code.node --require ./instrumentation.ts or import './instrumentation' at the top of your entry point.npm install @opentelemetry/sdk-node \
@opentelemetry/auto-instrumentations-node \
@opentelemetry/exporter-trace-otlp-http \
@opentelemetry/exporter-metrics-otlp-http \
@opentelemetry/resources \
@opentelemetry/semantic-conventions
// instrumentation.ts — must be loaded before application code
import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { Resource } from '@opentelemetry/resources';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
ATTR_DEPLOYMENT_ENVIRONMENT,
} from '@opentelemetry/semantic-conventions';
const resource = new Resource({
[ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'my-service',
[ATTR_SERVICE_VERSION]: process.env.npm_package_version || '0.0.0',
[ATTR_DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV || 'development',
});
const sdk = new NodeSDK({
resource,
traceExporter: new OTLPTraceExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
}),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/metrics',
}),
exportIntervalMillis: 15000,
}),
instrumentations: [
getNodeAutoInstrumentations({
// Disable noisy instrumentations
'@opentelemetry/instrumentation-fs': { enabled: false },
'@opentelemetry/instrumentation-dns': { enabled: false },
}),
],
});
sdk.start();
// Graceful shutdown
process.on('SIGTERM', () => {
sdk.shutdown().then(
() => console.log('Telemetry shut down'),
(err) => console.error('Telemetry shutdown error', err)
);
});
// package.json — load instrumentation first
{
"scripts": {
"start": "node --require ./dist/instrumentation.js ./dist/index.js",
"dev": "tsx --require ./src/instrumentation.ts ./src/index.ts"
}
}
Load order is critical. OpenTelemetry hooks into library internals (HTTP, pg, express) by monkey-patching. If you import express before OpenTelemetry initializes, the instrumentation will not work. Always load instrumentation.ts first.
Auto-instrumentations included:
@opentelemetry/instrumentation-http — HTTP/HTTPS client and server@opentelemetry/instrumentation-express — Express routes and middleware@opentelemetry/instrumentation-pg — PostgreSQL queries@opentelemetry/instrumentation-redis — Redis commands@opentelemetry/instrumentation-mongodb — MongoDB operations@opentelemetry/instrumentation-grpc — gRPC callsauto-instrumentations-nodeEnvironment variables (standard):
OTEL_SERVICE_NAME — service name (overrides code)OTEL_EXPORTER_OTLP_ENDPOINT — collector URLOTEL_EXPORTER_OTLP_PROTOCOL — grpc or http/protobufOTEL_TRACES_SAMPLER — always_on, always_off, traceidratioOTEL_TRACES_SAMPLER_ARG — sampler argument (e.g., 0.1 for 10%)Local development: Run the OpenTelemetry Collector and Jaeger locally:
docker run -d -p 4318:4318 -p 16686:16686 jaegertracing/all-in-one:latest
Then view traces at http://localhost:16686.
Common mistakes:
sdk.shutdown() on process exit (traces may be lost)/v1/traces)https://opentelemetry.io/docs/languages/js/getting-started/nodejs/
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeGuides OpenTelemetry instrumentation setup across multiple languages (Node.js, Go, Python, Java, .NET, Ruby, PHP, browser, Next.js). Covers spans, metrics, logs, resource attributes, sampling, and sensitive data handling.
Configures OTLP exporters to send traces, metrics, and logs to observability backends and collectors. Covers direct export vs collector-mediated export, batching, compression, and retry behavior.
Guides setup of OpenTelemetry NodeSDK, declarative YAML configuration, and auto-instrumentations for Node.js services.