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

@wide-events/sdk

v0.4.1

Published

Lightweight structured event SDK for Node, Lambda, and edge runtimes.

Downloads

340

Readme

@wide-events/sdk

Lightweight structured event SDK for Node, Lambda, and edge runtimes.

Install

npm install @wide-events/sdk

Node

import { WideEvents } from "@wide-events/sdk";

const wideEvents = new WideEvents({
  serviceName: "orders-api",
  environment: "production",
  collectorUrl: "http://localhost:4318",
});

app.use(wideEvents.middleware());

app.post("/orders", async (req, res) => {
  wideEvents.annotate(
    {
      "user.id": req.user.id,
      "order.total": req.body.total,
    },
    { promote: ["order.total"] },
  );

  wideEvents.push("db.queries", {
    operation: "select_order",
    duration_ms: 12,
  });

  res.sendStatus(201);
});

Lambda

const wideEvents = new WideEvents({
  serviceName: "orders-lambda",
  collectorUrl: process.env.WIDE_EVENTS_COLLECTOR_URL,
});

export const handler = wideEvents.wrapHandler(async (event) => {
  wideEvents.annotate({
    "http.route": event.rawPath,
  });

  return { statusCode: 200, body: "ok" };
});

wrapHandler() records thrown errors automatically, flushes in finally, and rethrows failures.

Edge

import { WideEvents } from "@wide-events/sdk/edge";

const wideEvents = new WideEvents({
  serviceName: "edge-gateway",
  collectorUrl: "https://collector.example.com",
});

export default {
  fetch(request: Request, env: Env, ctx: ExecutionContext) {
    return wideEvents.fetchHandler(request, ctx, () => new Response("ok"));
  },
};

Instrumentation

Instrumentation is Node-only and client-driven for database/cache/aws clients. The preferred API is a constructor-level instrumentation object:

import { WideEvents } from "@wide-events/sdk";
import { Pool } from "pg";
import Redis from "ioredis";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";

const pool = new Pool({ connectionString: process.env["DATABASE_URL"] });
const redis = new Redis(process.env["REDIS_URL"] ?? "");
const dynamo = new DynamoDBClient({});

const wideEvents = new WideEvents(
  { serviceName: "api", collectorUrl },
  {
    fetch: true,
    pg: [pool],
    redis: [redis],
    aws: [dynamo], // instrument base AWS SDK v3 client
  },
);

const doc = DynamoDBDocumentClient.from(dynamo);

fetch in the second argument is equivalent to autoInstrument.fetch in the core options (kept for backward compatibility). If both are present, the second argument value is used.

You can still instrument manually with subpath installers when you want per-client options:

import { instrumentPg } from "@wide-events/sdk/instrumentation/pg";
import { instrumentAwsSdkV3 } from "@wide-events/sdk/instrumentation/aws-sdk-v3";
import { instrumentIoredis } from "@wide-events/sdk/instrumentation/ioredis";

instrumentPg(pool, wideEvents, { sqlTruncateLength: 120 });
instrumentIoredis(redis, wideEvents);
instrumentAwsSdkV3(dynamo, wideEvents);

Node-only integrations are exposed as package subpaths so edge bundles never pull TCP clients:

npm install @wide-events/sdk pg ioredis
npm install @wide-events/sdk @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb

Typing strategy keeps the SDK small:

  • pg / ioredis use official library types in constructor and installer signatures for strong autocomplete.
  • AWS SDK v3 uses a lightweight hybrid client contract (AwsSdkV3ClientTarget) to stay compatible across Smithy overloads without adding heavy dependency coupling.

WideEvents satisfies InstrumentationHooks, so helper functions can stay generic:

import type { InstrumentationHooks } from "@wide-events/sdk";

function helper(hooks: InstrumentationHooks, pool: Pool) {
  instrumentPg(pool, hooks);
}

Emitted attribute arrays use dotted keys aligned with outbound HTTP instrumentation:

| Subpath | Success key | Failure key | | --- | --- | --- | | (fetch / SDK) | http.client.requests | http.client.errors | | @wide-events/sdk/instrumentation/pg | db.queries | db.errors | | @wide-events/sdk/instrumentation/aws-sdk-v3 | aws.client.operations | aws.client.errors | | @wide-events/sdk/instrumentation/ioredis | redis.commands | redis.errors |

API

| Method | Purpose | | --- | --- | | middleware() | Creates Node request middleware and flushes an event on response finish. | | wrapHandler(handler) | Wraps Lambda-style handlers with event lifecycle, error capture, and flush. | | fetchHandler(request, ctx, handler) | Edge request lifecycle helper. | | annotate(attributes, options?) | Adds structured fields to the active event. | | push(key, value) | Appends nested values, useful for repeated operations like DB calls. | | recordError(error, options?) | Records an error on the active event. | | current() | Returns the current materialized event, if one is active. | | wrapFetch(fetch?) | Returns an instrumented fetch function. | | instrumentFetch() | Wraps globalThis.fetch for fetch-based HTTP clients. | | flush() / forceFlush() | Sends queued events to the collector. | | shutdown() | Restores patched fetch and flushes queued events. |

Automatic exception details are guaranteed only where the SDK owns the execution boundary. Plain Node middleware marks status >= 500 as failed; use route wrappers or platform wrappers for thrown-error details.