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

@sebspark/otel

v2.1.7

Published

Unified **OpenTelemetry** implementation for logging, tracing, and metrics — with environment detection, auto‑instrumentation, and clean console output for local development.

Downloads

3,427

Readme

@sebspark/otel

Unified OpenTelemetry implementation for logging, tracing, and metrics — with environment detection, auto‑instrumentation, and clean console output for local development.


Use logger, tracer, and metrics

Install:

npm install @sebspark/otel
# or
yarn add @sebspark/otel
# or
pnpm add @sebspark/otel

Initialization

This must be the first import in your application:

import { initialize, instrumentation } from '@sebspark/otel'

async function start () {
  await initialize(
    instrumentation.undici,
    instrumentation.http,
    instrumentation.express,
    instrumentation.redis,
  )

  // start your application
}

start()

Automatically:

  • Initializes the OpenTelemetry SDK
  • Auto‑instruments common libraries like HTTP, gRPC, Redis, PostgreSQL
  • Enables W3C Trace Context propagation
  • Detects environment and adds resourceAttributes
  • Links logs with trace_id and span_id
  • Handles graceful shutdown on SIGTERM

Logging

import { getLogger } from '@sebspark/otel'

const logger = getLogger()

// Will do nothing if OTEL is not yet initialized
logger.debug('debug message')
logger.info('something happened')
logger.warn('almost bad')
logger.error('very bad')

Logs inside active spans automatically include:

  • trace_id
  • span_id
  • service.name
  • service.version

Tracing

import { getTracer } from '@sebspark/otel'

// Will throw if OTEL is not yet initialized
const tracer = getTracer()

await tracer.withTrace('trace.name', async (span) => {
  span.setAttribute('user.id', '123')
  // do something...
})

If the callback throws:

  • Span is marked as ERROR
  • Exception is recorded
  • Span is ended properly

Synchronous variant:

tracer.withTraceSync('init.config', (span) => {
  // synchronous code
  span.setStatus({ code: SpanStatusCode.OK })
})

Nested:

await tracer.withTrace('trace.name', async (span1) => {
  span1.setAttribute('user.id', '123')
  
  await tracer.withTrace('trace.name2', span1, async (span2) => {
    // do stuff
  })
})

Manual span usage:

const span = tracer.startSpan('manual-operation')
span.setAttribute('manual', true)
// work...
span.end()

Metrics

import { getMeter } from '@sebspark/otel'

// Will throw if OTEL is not yet initialized
const meter = getMeter()

const counter = meter.createCounter('http_requests_total', {
  description: 'Total number of HTTP requests',
})

counter.add(1, {
  route: '/api/hello',
  method: 'GET',
})

Configure for cloud use (with OpenTelemetry Collector)

When deployed to Cloud Run, GKE, or other cloud environments, telemetry automatically exports to your configured OpenTelemetry Collector.

Set these environment variables:

| Variable | Description | Example | |-------------------------------|---------------------------------|-------------------------------| | OTEL_EXPORTER_OTLP_ENDPOINT | Collector endpoint | http://otel-collector:4318 | | OTEL_SERVICE_NAME | Override detected service name | trade-api | | OTEL_SERVICE_VERSION | Version of this instance | 1.2.3 |

Additional GCP/Kubernetes context is auto‑detected:

| Env Variable | Attribute Key | Example | |---------------------------|-----------------------|-------------------| | K_SERVICE | cloud.run.service | trade-api | | K_REVISION | cloud.run.revision | trade-api-v15 | | POD_NAME | k8s.pod_name | api-1234 | | KUBERNETES_SERVICE_HOST | cloud.orchestrator | kubernetes | | GCP_PROJECT | cloud.account.id | my-gcp-project |


Configure for local use (dev logging)

In development, @sebspark/otel outputs human-readable logs, spans, and metrics directly to the console.


Environment variables

| Variable | Affects | Values | Description | |----------------|---------|------------------------------------------|-----------------------------------------------------------------------------------------| | LOG_LEVEL | Logs | debug,info,warn,error | Minimum severity to print | | SPAN_LEVEL | Traces | OK, ERROR, UNSET (comma-separated) | Only trees containing at least one span with one of these statuses will be printed | | METRIC_FILTER| Metrics | Glob patterns (comma-separated) | Only metrics matching any of the patterns are shown |


Logs

Filtered by LOG_LEVEL:

LOG_LEVEL=warn yarn dev
⚠️  [[email protected]] GET /orders/limit-exceeded      WARN    trace_id=abc123 span_id=def456
❌  [[email protected]] Order validation failed         ERROR   trace_id=abc123 span_id=def456

Spans

Filtered by SPAN_LEVEL — the entire span tree is printed only if at least one span in the tree matches the status.

SPAN_LEVEL=ERROR yarn dev
[[email protected]] 12:00:00.000
└─ express                 ████████████████████                OK     (0 ms–1.00 s)
   └─ middleware:auth      ███████                             OK     (0 ms–0.20 s)
   └─ handler:getUser      ████████████████████                ERROR  (0 ms–1.00 s)
SPAN_LEVEL=OK,ERROR yarn dev
[[email protected]] 12:01:00.000
└─ express                 ████████████████████                OK     (0 ms–1.00 s)
   └─ middleware:auth      ███████                             OK     (0 ms–0.20 s)

📈 Metrics

Filtered by METRIC_FILTER:

METRIC_FILTER=http.*,db.* yarn dev
📊 [[email protected]] 12:00:00.000  📊  express http.server.duration 240ms {route=/api/hello method=GET}
📊 [[email protected]] 12:00:01.000  📊  pg db.query.count 1 {query=SELECT * FROM users}