Step 1: Install the OpenTelemetry packages
Install the relevant OpenTelemetry packages:Terminal
Step 2: Initialize the instrumentation
Create a file calledtracing.js
at the root of your project and add the following code:
tracing.js
sampler
configuration. This is a custom, head-based sampler that will only sample spans that are generated by Checkly by
inspecting the trace state. This way you only pay for the egress traffic generated by Checkly and not for any other traffic.
Step 3: Start your app with the instrumentation
Toggle on Import Traces and grab your OTel API key in the OTel API keys section of the Traces page in the Checkly app and take a note of the endpoint for the region you want to use.
OTEL_EXPORTER_OTLP_HEADERS
environment variable.
Variable | Description |
---|---|
OTEL_EXPORTER_OTLP_HEADERS | The Authorization HTTP header containing your Checkly OTel API key. |
OTEL_EXPORTER_OTLP_ENDPOINT | The Checkly OTel API endpoint for the region you want to use. |
OTEL_EXPORTER_OTLP_PROTOCOL | The protocol to use for the OTLP exporter. |
OTEL_SERVICE_NAME | The name of your service to identify it among the spans in the web UI. |
-r
flag to load the tracing.js
file before any other files are loaded. In this case
the index.js
file holds your Express app and typically starts with code like:
index.js
Terminal
Reducing noise in the auto Node.js instrumentation
We found the Node.js auto-instrumentation a bit noisy. There can be a lot of file i/o and a ton of DNS calls you might not be interested in. Luckily, you can easily tweak that by providing some extra options to thegetNodeAutoInstrumentations()
function.
We use the following configuration to filter out some of the noise:
tracing.js