Skip to main content
Home

An extesion of the OpenTelemetry BatchSpanProcessor that awaits by trace before exporting.

This package works with Node.js, DenoIt is unknown whether this package works with Cloudflare Workers, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
70%
Published
4 months ago (2.0.0)

OpenTelemetry BatchTracedSpanProcessor

JSR JSR Score codecov

BatchTracedSpanProcessor is a class that extends from the official BatchSpanProcessor (@opentelemetry/sdk-trace-base). It allows to wait for some time before adding the spans into the BatchSpanProcessor internal buffer. The intention of the delay is to give more room for a root span to end, before the export happens.

Use case

If your application is instrumented by the OpenTelemetry SDK library, but the ingestion of the traces is done by a third party agent (for instance Datadog Agent). Then you have the risk to be sending ended child spans that might be --from the point of view of the third-party collector-- orphan. Depending of the eagerness of the collector, those child spans might be processed too fast and end-up aggregated as "standalone" traces (resource.name in Datadog). By waiting some time for at least a root span to exist in a given trace, It is possible to greatly alleviate that situation.

Usage

import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import { BatchTracedSpanProcessor } from '@esroyo/otel-batch-traced-span-processor'; 
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

const collectorOptions = {
  url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/traces
  headers: {
    foo: 'bar'
  }, // an optional object containing custom headers to be sent with each request will only work with http
  concurrencyLimit: 10, // an optional limit on pending requests
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new BatchSpanProcessor(exporter, {
  // The maximum time to wait for the trace to contain a root span
  // before adding the spans into the regular BatchSpanProcessor buffer
  maxWaitByTraceMillis: 30000,
  // All other options of BatchSpanProcessor apply
  // ...
}));

provider.register();

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";
or

Import directly with a jsr specifier

import * as otel_batch_traced_span_processor from "jsr:@esroyo/otel-batch-traced-span-processor";

Add Package

pnpm i jsr:@esroyo/otel-batch-traced-span-processor
or (using pnpm 10.8 or older)
pnpm dlx jsr add @esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";

Add Package

yarn add jsr:@esroyo/otel-batch-traced-span-processor
or (using Yarn 4.8 or older)
yarn dlx jsr add @esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";

Add Package

vlt install jsr:@esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";

Add Package

npx jsr add @esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";

Add Package

bunx jsr add @esroyo/otel-batch-traced-span-processor

Import symbol

import * as otel_batch_traced_span_processor from "@esroyo/otel-batch-traced-span-processor";