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

datadog-logger-client

v1.0.1

Published

DataDog HTTP API client

Readme

datadog-logger-client

Shared DataDog HTTP API client. Provides structured log ingestion via DataDog's HTTP Logs v2 API — no agent required.

Background

This package sends logs to DataDog's HTTP ingestion API directly from application code. All HTTP calls are fire-and-forget and non-blocking. If DataDog is unreachable, the client retries up to 2 times then swallows the failure silently — your app is never impacted by observability failures. If the API key is missing, all calls are silently skipped.

Installation

Add to the consuming app's package.json:

{
  "dependencies": {
    "datadog-logger-client": "^1.0.0"
  }
}

Build the package before installing it in consuming apps:

cd datadog-logger-client
yarn install
yarn build

Configuration

Pass the Datadog API Key directly (or as a lazy resolver function) when constructing the factory.

Usage

Recommended: DatadogClientFactory (module-level singleton)

Use DatadogClientFactory rather than instantiating DatadogClient directly. The factory caches the client instance and re-creates it only if the resolved API key changes.

Declare the factory once at the module level:

// datadogFactory.ts
import { DatadogClientFactory } from 'datadog-logger-client'

export const datadogFactory = new DatadogClientFactory(
  'my-service-name',       // service name as it appears in DataDog
  () => settings.apiKey,   // API key — string or lazy () => string
  'nodejs',                // log source
  'my-host',               // hostname
  () => env,               // environment
  ['team:my-team'],        // optional extra tags
  'https://http-intake.logs.datadoghq.eu/api/v2/logs', // optional custom endpoint
)

Then call getClient() wherever you need to log:

import { datadogFactory } from '../datadogFactory'

const dd = datadogFactory.getClient()

dd.error('Operation failed', ['operation:myOp'])

Logging

All log methods accept a string message and an optional tags array.

dd.info('Operation completed', ['operation:myOp'])

dd.warn('Cache miss on lookup', ['operation:fetchData', 'key:abc'])

dd.error('Operation failed', ['operation:myOp'])

dd.debug('Fetched data', ['itemId:456'])

API Reference

new DatadogClientFactory(service, apiKey, source, host, env, tags?, endpoint?)

| Argument | Type | Required | Description | |-----------|-------------------------|----------|-------------| | service | string | Yes | Service name as it appears in DataDog | | apiKey | string \| (() => string) | Yes | DataDog API key, or a function that returns it (evaluated on each getClient() call). Cache is invalidated when the resolved value changes. | | source | string | Yes | Log source (e.g. nodejs) | | host | string | Yes | Hostname attached to every log entry | | env | string \| (() => string) | Yes | Environment tag (e.g. production, staging) | | tags | string[] | No | Additional tags applied to every log entry | | endpoint | string \| (() => string) | No | DataDog Logs v2 endpoint, or a function that returns it. Defaults to the US5 endpoint. Override for other regions (e.g. EU: https://http-intake.logs.datadoghq.eu/api/v2/logs). Cache is invalidated when the resolved value changes |

factory.getClient(): DatadogClient

Returns the cached DatadogClient. Re-creates the client only if the resolved API key, endpoint or environment has changed since the last call.


Methods

| Method | Description | |-------------------------------------------|--------------------------| | info(message: string, tags?: string[]) | Send an info-level log | | warn(message: string, tags?: string[]) | Send a warn-level log | | error(message: string, tags?: string[]) | Send an error-level log | | debug(message: string, tags?: string[]) | Send a debug-level log |

Public Exports

export { DatadogClient } from './DatadogClient'
export { DatadogClientFactory } from './DatadogClientFactory'
export { LogLevel } from './types'
export type { DatadogClientConfig } from './types'

Package Structure

src/
├── index.ts                  — public exports
├── types.ts                  — interfaces and types
├── constants.ts              — DataDog endpoint, retry and timeout config
├── DatadogClient.ts          — main client class
├── DatadogClientFactory.ts   — lazy init and module-level caching
└── LogsClient.ts             — DataDog Logs v2 HTTP API wrapper

Behaviour Notes

  • DatadogClientFactory caches the DatadogClient instance and only re-creates it if the API key OR endpoint changes.
  • If apiKey is empty, all log calls are silently skipped.
  • HTTP calls are made asynchronously and do not block request handlers.
  • Failed HTTP calls are retried up to 2 times with a 500ms delay between attempts.
  • After retries are exhausted, the failure is swallowed and logged to console.log.
  • Logs are sent to the US5 DataDog region by default (https://http-intake.logs.us5.datadoghq.com/api/v2/logs). You can override via the endpoint parameter
  • Each log entry is tagged with env, plus any tags passed to the factory/client