Node.js App Instrumentation
Follow the steps below to auto-instrument your Node.js service. When complete, your service will start emitting logs, metrics, and traces to Lakerunner.
Local Testing
-
Get a Cardinal API key.
Follow the steps in the Overview to mint an ingest API key.
-
Install the OpenTelemetry auto-instrumentation dependencies:
npm install --save @opentelemetry/api npm install --save @opentelemetry/auto-instrumentations-node -
Enable log forwarding.
See the Pino Logger section below.
-
Export the following environment variables:
export OTEL_SERVICE_NAME="your-service-name" # Set your service name export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=local" # local/dev/staging/prod export OTEL_METRICS_EXPORTER="otlp" export OTEL_LOGS_EXPORTER="otlp" export OTEL_TRACES_EXPORTER="otlp" export OTEL_EXPORTER_OTLP_ENDPOINT="https://otelhttp.intake.<your-region>.aws.cardinalhq.io" export OTEL_EXPORTER_OTLP_HEADERS="x-cardinalhq-api-key=<your-api-key>" # Set your API key export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register" -
Run your application:
npm run start # Or your application's start script -
Validate that Lakerunner is receiving data.
Exercise the service by calling some API endpoints or causing some logs and metrics to be emitted. Wait a few minutes, then query for your service in the Cardinal dashboard.
Docker
Set the environment variables outlined above in your Docker container runtime configuration.
- Update
OTEL_RESOURCE_ATTRIBUTESto setdeployment.environment.namefor your environment. - If you run an OpenTelemetry Collector, set
OTEL_EXPORTER_OTLP_ENDPOINTto your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.
Kubernetes
Set the environment variables outlined above in your Deployment or StatefulSet manifest.
- Update
OTEL_RESOURCE_ATTRIBUTESto setdeployment.environment.namefor your environment. - If you run an OpenTelemetry Collector, set
OTEL_EXPORTER_OTLP_ENDPOINTto your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.
Additional Integrations
Pino Logger
Configure Pino to forward logs to Lakerunner.
-
Install the
pino-opentelemetry-transportpackage:npm install --save pino-opentelemetry-transport -
Configure Pino to use the
pino-opentelemetry-transportwhen you initialize the logger:const logger = pino({ transport: { targets: [ { target: "pino/file", options: { destination: 1 }, // continues to write to stdout }, { target: "pino-opentelemetry-transport", options: {}, }, ], }, });
Reach out to support@cardinalhq.io for support or to ask questions not answered in our documentation.