npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

autotel-plugins

v0.19.19

Published

OpenTelemetry instrumentation for libraries without official support (BigQuery)

Downloads

1,199

Readme

Autotel Plugins

OpenTelemetry instrumentation for libraries without official support OR where the official support is fundamentally broken.

Philosophy

autotel-plugins only includes instrumentation that:

  1. Has NO official OpenTelemetry package (e.g., BigQuery)
  2. Has BROKEN official instrumentation
  3. Adds significant value beyond official packages

We do NOT include:

  • Re-exports of official packages
  • Wrappers that add no value
  • Duplicates of working official packages

Why This Approach?

With the --import pattern (Node.js 18.19+), using official OpenTelemetry packages when they work is simple:

// instrumentation.mjs
import { init } from 'autotel';
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';

init({
  service: 'my-app',
  instrumentations: [new PgInstrumentation()],
});
# Run with --import flag
tsx --import ./instrumentation.mjs src/index.ts

Benefits of official packages (when they work):

  • ✅ Always up-to-date (maintained by OpenTelemetry)
  • ✅ Complete feature coverage
  • ✅ Battle-tested in production
  • ✅ Zero maintenance burden
  • ✅ More discoverable and trustworthy

When to Use Official Packages

For databases/ORMs with working official instrumentation, use those directly:

Browse all official instrumentations →

Installation

Install the package and autotel (required for all plugins):

npm install autotel autotel-plugins

What to install per plugin

Each plugin needs the core packages above plus the library (and optional OTel instrumentation) you use:

| Plugin | Install | | ------------ | -------------------------------------------------------------------------------------------------------------------------- | | BigQuery | autotel + autotel-plugins + @google-cloud/bigquery | | Kafka | autotel + autotel-plugins + kafkajs. Optional: @opentelemetry/instrumentation-kafkajs for producer/consumer spans. |

Examples:

# BigQuery
npm install autotel autotel-plugins @google-cloud/bigquery

# Kafka (with optional official instrumentation)
npm install autotel autotel-plugins kafkajs @opentelemetry/instrumentation-kafkajs

Currently Supported

Kafka

Composition layer for KafkaJS: processing span wrapper, producer span wrapper, batch lineage for fan-in trace correlation, and batch consumer wrapper. Works alongside optional @opentelemetry/instrumentation-kafkajs for producer/consumer spans.

Batch consumer: Wrap KafkaJS eachBatch with withBatchConsumer(config, handler). Preserves the exact KafkaJS payload signature. Config: name, consumerGroup, perMessageSpans ('none' | 'all' | 'errors'), onProgress.

Per-message spans:

  • 'all' : One span per message. Message spans are parented to extracted trace context from message headers when valid (trace continuation); otherwise to the batch span. All per-message spans are ended when the batch completes, including skipped or unresolved messages (no span leak).
  • 'errors' : Per-message span only on failure. When the handler throws, an error span is created for the first message. Use createMessageErrorSpan in your catch block for per-message error spans.
import { withBatchConsumer } from 'autotel-plugins/kafka';

await consumer.run({
  eachBatch: withBatchConsumer(
    {
      name: 'orders.batch',
      consumerGroup: 'processor',
      perMessageSpans: 'all',
    },
    async ({ batch, resolveOffset }) => {
      for (const message of batch.messages) {
        await processOrder(message);
        resolveOffset(message.offset);
      }
    },
  ),
});

Optional: install @opentelemetry/instrumentation-kafkajs for producer/consumer spans.

Combining with Official Packages

Mix autotel-plugins with official OpenTelemetry instrumentations:

import { init } from 'autotel';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';

init({
  service: 'my-service',
  instrumentations: [
    new HttpInstrumentation(),
    new ExpressInstrumentation(),
    new PgInstrumentation(), // Official packages
  ],
});

Creating Your Own Instrumentation

Don't see your library here? Autotel makes it easy to create custom instrumentation for any library using simple, well-tested utilities.

Quick Example

import { trace, SpanKind } from '@opentelemetry/api';
import { runWithSpan, finalizeSpan } from 'autotel/trace-helpers';

const INSTRUMENTED_FLAG = Symbol('instrumented');

export function instrumentMyLibrary(client) {
  if (client[INSTRUMENTED_FLAG]) return client;

  const tracer = trace.getTracer('my-library');
  const originalMethod = client.someMethod.bind(client);

  client.someMethod = async function (...args) {
    const span = tracer.startSpan('operation', { kind: SpanKind.CLIENT });
    span.setAttribute('operation.param', args[0]);

    try {
      const result = await runWithSpan(span, () => originalMethod(...args));
      finalizeSpan(span);
      return result;
    } catch (error) {
      finalizeSpan(span, error);
      throw error;
    }
  };

  client[INSTRUMENTED_FLAG] = true;
  return client;
}

Full Guide

For a comprehensive guide including:

  • Step-by-step tutorial with real examples
  • Best practices for security and idempotency
  • Complete utilities reference
  • Ready-to-use template code

See: Creating Custom Instrumentation in the main autotel docs.

You can also check INSTRUMENTATION_TEMPLATE.ts for a fully commented, copy-paste-ready template.

Contributing

Found a database/ORM without official OpenTelemetry instrumentation? Please open an issue to discuss adding it.

License

MIT