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

@rodrigopsasaki/vision-datadog-exporter

v0.5.0

Published

Datadog exporter for @rodrigopsasaki/vision - structured observability for Node.js

Readme

@rodrigopsasaki/vision-datadog-exporter

A production-ready Datadog exporter for @rodrigopsasaki/vision. Ships with sensible defaults: just plug it into Vision and get distributed traces with rich metadata exported to Datadog.

Features

  • 📦 Plug-and-play Vision exporter for Datadog
  • 🪄 Sensible defaults - exports Vision contexts as OpenTelemetry-compliant distributed traces
  • 🧩 Extensible - override transformation logic for custom needs
  • 🛡️ Type-safe - Zod-validated configuration with full TypeScript support
  • 🏷️ Rich metadata - all Vision context data included as span metadata
  • Production-ready - circuit breaker, retries, batching, and proper error handling
  • 🔄 Multiple export modes - traces (default), metrics, logs, or events

Installation

pnpm add @rodrigopsasaki/vision-datadog-exporter
# or
yarn add @rodrigopsasaki/vision-datadog-exporter
# or
npm install @rodrigopsasaki/vision-datadog-exporter

Quick Start

import { vision } from "@rodrigopsasaki/vision";
import { createDatadogExporter } from "@rodrigopsasaki/vision-datadog-exporter";

vision.init({
  exporters: [
    createDatadogExporter({
      apiKey: "your-datadog-api-key",
      service: "my-service",
      env: "production",
      // Optional: exportMode: 'trace' | 'metric' | 'log' | 'event'
    }),
  ],
});

// Vision contexts automatically become distributed traces in Datadog
await vision.observe("user.login", async () => {
  vision.set("user_id", "user123");
  vision.set("method", "email");
  // ... work happens ...
});

Configuration

All config options are type-safe and Zod-validated:

createDatadogExporter({
  // Required
  apiKey: "your-datadog-api-key",
  service: "my-service",

  // Common options
  env: "production", // Environment tag
  exportMode: "trace", // 'trace' | 'metric' | 'log' | 'event'
  site: "datadoghq.com", // Datadog site

  // Behavior options
  includeContextData: true, // Include all Vision context data as metadata
  includeTiming: true, // Include duration information
  includeErrorDetails: true, // Include error stack traces

  // Performance options
  batchSize: 100, // Batch size for exports
  flushInterval: 5000, // Max time to wait before flushing (ms)
  timeout: 10000, // HTTP request timeout (ms)
  retries: 3, // Number of retries on failure

  // Optional
  tags: ["team:backend", "version:1.0"], // Extra tags for all exports
  hostname: "my-host", // Override hostname
});

OpenTelemetry Compliance

This exporter generates OpenTelemetry-compliant distributed traces:

  • Consistent trace/span IDs generated from Vision context IDs
  • Proper span kinds mapped from Vision context scope (server, client, producer, consumer, internal)
  • Rich metadata including library info, service names, and all context data
  • Error handling with proper error spans and metadata

Span Kind Mapping

The exporter intelligently maps Vision context scopes to OpenTelemetry span kinds:

  • http*, api*, request*server
  • client*, fetch*, call*client
  • producer*, publish*producer
  • consumer*, subscribe*consumer
  • Everything else → internal

Extension

You can extend the transformation logic by subclassing VisionDatadogTransformer:

import {
  VisionDatadogTransformer,
  createDatadogExporter,
} from "@rodrigopsasaki/vision-datadog-exporter";

class MyTransformer extends VisionDatadogTransformer {
  toSpan(context, error) {
    const span = super.toSpan(context, error);

    // Add custom metadata
    span.meta["custom.field"] = "value";

    // Custom span naming
    if (context.scope === "database") {
      span.name = `db.${context.name}`;
    }

    return span;
  }
}

const exporter = createDatadogExporter({
  apiKey: "key",
  service: "svc",
});

// Replace the transformer
exporter.transformer = new MyTransformer(exporter.config);

Production Features

Circuit Breaker

Automatically opens circuit to prevent cascading failures when Datadog is unavailable.

Batching

Efficiently batches exports to reduce API calls and improve performance.

Retries

Exponential backoff retries with intelligent error classification.

Monitoring

const exporter = createDatadogExporter({...});

// Get export statistics
const stats = exporter.getStats();
console.log(stats.queueSize);           // Current queue size
console.log(stats.isProcessing);        // Is currently exporting
console.log(stats.circuitBreakerState); // 'closed' | 'open' | 'half-open'

Vision Usage Example

import { vision } from "@rodrigopsasaki/vision";
import { createDatadogExporter } from "@rodrigopsasaki/vision-datadog-exporter";

vision.init({
  exporters: [createDatadogExporter({ apiKey: "...", service: "..." })],
});

// HTTP request handling
await vision.observe("user.profile.get", { scope: "http-server" }, async () => {
  vision.set("user_id", req.user.id);
  vision.set("endpoint", "/profile");

  // Database query
  await vision.observe("user.fetch", { scope: "database" }, async () => {
    const user = await db.user.findUnique({ where: { id: req.user.id } });
    vision.set("query_time_ms", 42);
    return user;
  });
});

This creates a distributed trace in Datadog showing the full request flow with timing, metadata, and proper parent-child span relationships.

License

MIT