Node.js App Instrumentation
Follow the steps below to auto-instrument your Node.js service. When completed, your service will appear in the Cardinal Service Catalog, and Chip will begin monitoring it.
Local Testing
- Get a Cardinal API key:
Sign in to your Cardinal account, and get an API key from the Organization Settings > API Keys section.
- 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.us-east-2.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 Cardinal is receiving data:
Exercise the service by calling some API endpoints, or causing some logs or metrics to be emitted. Wait for a few minutes, then visit the Service Catalog in the Cardinal UI to check that your service appears in the list.
Docker
Set the environment variables outlined above in your Docker container runtime configuration.
- Update
OTEL_RESOURCE_ATTRIBUTES
to set thedeployment.environment.name
value to your environment. - If you run an OpenTelemetry Collector, set the
OTEL_EXPORTER_OTLP_ENDPOINT
to your Collector's OTLP Receiver endpoint, and follow the steps in the OTLP Export to Cardinal section to forward data to Cardinal.
Kubernetes
Set the environment variables outlined above in your Deployment
or StatefulSet
manifest.
- Update
OTEL_RESOURCE_ATTRIBUTES
to set thedeployment.environment.name
value to your environment. - If you run an OpenTelemetry Collector, set the
OTEL_EXPORTER_OTLP_ENDPOINT
to your Collector's OTLP Receiver endpoint, and follow the steps in the OTLP Export to Cardinal section to forward data to Cardinal.
Additional Integrations
Pino Logger
Configure Pino (opens in a new tab) to forward logs to Cardinal.
- Install the
pino-opentelemetry-transport
package:
npm install --save pino-opentelemetry-transport
- Configure Pino to use the
pino-opentelemetry-transport
when 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: {},
},
],
},
});