Skip to content

Honeycomb with OpenTelemetry

The spanslice package sets up OpenTelemetry for a Node service. It applies your rules to every span before the span is exported. It replaces the SDK you start today, either @opentelemetry/sdk-node or Honeycomb’s @honeycombio/opentelemetry-node. Your instrumentations, and any spans you create with @opentelemetry/api, stay as they are. To keep your NodeSDK setup instead, see Keep your NodeSDK setup.

Before you start, connect Honeycomb. Then make sure the service exists in SpanSlice, with a dataset in each environment it runs in.

Terminal window
npm install spanslice
src/instrument.ts
import { spanSliceInit } from 'spanslice'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
const telemetry = spanSliceInit({
service: 'api', // the service in SpanSlice; also service.name
instrumentations: [getNodeAutoInstrumentations()],
})
await telemetry.ready
Terminal window
SPANSLICE_API_KEY=ss_… node --import ./src/instrument.ts server.js

SPANSLICE_API_KEY is the SpanSlice environment’s key, from Settings › API keys. Your Honeycomb ingest key doesn’t go in your code or your environment variables. The SDK gets it with its config, along with the service’s dataset. See Install the Node SDK for the other options.

Coming from @honeycombio/opentelemetry-node

Section titled “Coming from @honeycombio/opentelemetry-node”

If your service starts Honeycomb’s SDK like this:

import { HoneycombSDK } from '@honeycombio/opentelemetry-node'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
const sdk = new HoneycombSDK({
apiKey: process.env.HONEYCOMB_API_KEY,
serviceName: 'api',
instrumentations: [getNodeAutoInstrumentations()],
})
sdk.start()

replace it with spanSliceInit, passing the same instrumentations, as in Set up the SDK above.

  • Start only one SDK. A process has one OpenTelemetry tracer provider, so spans from the other SDK never reach SpanSlice’s rules.
  • Replace any sampleRate you set in Honeycomb’s SDK with a Set Sample Rate rule. Then one place decides sampling, and the SampleRate that Honeycomb receives is correct.
  • HONEYCOMB_API_KEY and HONEYCOMB_DATASET are no longer read. The ingest key and dataset come from Project settings › Honeycomb.

To keep Honeycomb’s key in your own deployment, or to send through an OpenTelemetry Collector, set the exporter to otlp. The SDK then uses the standard OpenTelemetry variables and ignores the destination that SpanSlice resolves:

Terminal window
SPANSLICE_EXPORTER=otlp
OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io # https://api.eu1.honeycomb.io for an EU team
OTEL_EXPORTER_OTLP_HEADERS=x-honeycomb-team=<ingest key>
  • Traces go over OTLP/HTTP (protobuf). Honeycomb stores them in the dataset named after service.name, which is the service you pass to spanSliceInit.
  • Metrics need a dataset of their own. Add OTEL_EXPORTER_OTLP_METRICS_HEADERS=x-honeycomb-team=<ingest key>,x-honeycomb-dataset=api_metrics, or pass metricExporter: 'none' to send no metrics.
  • For a collector, point OTEL_EXPORTER_OTLP_ENDPOINT at it, and let the collector’s exporter add the Honeycomb headers.
  • SpanSlice still provides the rules, synchronous span handling and stuck-span checks. The Honeycomb exporter switches under Project settings › Exporters don’t apply to this process.
  • Only the spans your rules kept. When a span is dropped, its children move up to its nearest kept ancestor, so traces stay connected.
  • SampleRate on spans from a sampled trace: the trace rate, multiplied by the span rate when a Set Span Sample Rate applied. It’s left off when nothing was sampled.
  • Attributes as the rules left them, after any renaming, setting, redacting or removal.
  • A <span name> (incomplete) event for a span that’s still open past a stuck-span timeout. It carries spanslice.stuck_by. See Stuck spans.