order | label |
---|---|
1 |
Node.js |
The Baselime Node.js OpenTelemetry SDK enables you to instrument your Node.js services with OpenTelemetry without the boilerplate of using the OpenTelemetry SDK directly.
This SDK uses OpenTelemetry for JavaScript and provides a layer that facilitates instrumenting your Node.js applications.
!!!info Is your application already instrumented with OpenTelemetry?
!ref icon="../../assets/images/logos/logo_open_telemetry.png" text="Configure endpoint and headers" !!!
Install the Baselime Node.js OpenTelemetry SDK.
npm i --save \
@baselime/node-opentelemetry \
@opentelemetry/auto-instrumentations-node
Create a tracing.js
file
const { BaselimeSDK } = require('@baselime/node-opentelemetry');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
import opentelemetry from '@opentelemetry/api';
const sdk = new BaselimeSDK({
instrumentations: [
getNodeAutoInstrumentations(),
],
});
sdk.start();
// Get tracer
const tracer = opentelemetry.trace.getTracer('example-basic-tracer-node');
//Create a span
const parentSpan = tracer.startSpan('main');
parentSpan.end();
// Create meter
const meter = opentelemetry.metrics.getMeter(
'instrumentation-scope-name',
'instrumentation-scope-version',
);
// Create a counter
const counter = meter.createCounter('my-counter');
counter.add(1);
// Create a gauge
const gauge = meter.createUpDownCounter('events.counter');
counter.add(1);
Set the environment variables of your comntainer service to include the Baselime API Key and set the NODE_OPTIONS enviroment variable to preload the OpenTelemetry SDK into your application.
Key | Value | Description |
---|---|---|
BASELIME_KEY | your-api-key |
Get this key from the Baselime console or the Baselime CLI |
NODE_OPTIONS | -r ./src/tracing.js |
Preloads the OpenTelemetry SDK at startup |
Once these steps are completed, distributed traces from your Node.js container applications should be available in Baselime to query via the console or the Baselime CLI.
The BaselimeSDK
class of the Baselime Node.js OpenTelemetry SDK takes the following configuration options.
Field | Type | Description |
---|---|---|
instrumentations |
InstrumentationOption[] |
An array of instrumentation options |
baselimeKey |
string (optional) |
The Baselime API key |
collectorUrl |
string (optional) |
The URL of the collector |
service |
string (optional) |
The service name |
namespace |
string (optional) |
The namespace |