Docs
Open app

integrations

Node.js SDK

Install the Node.js SDK to emit batched usage events to Doow.

Use the Node.js SDK when a Node.js service owns the usage event and can send it to Doow from application code.

What you need

  • A Doow SDK API key. SDK keys start with dk_.
  • A license ID for the contract or license that receives the usage.
  • A Node.js service where the usage event happens.

Installation

npm install @doow/track
# or
yarn add @doow/track

Quick start

Send one test event before adding the SDK to every usage path.

import { DoowTracker } from '@doow/track';
 
const meter = new DoowTracker(process.env.DOOW_TRACK_API_KEY);
 
// Track a usage event
meter.track({
  metric: 'api_calls',
  quantity: 1,
  license_id: 'lic_your_license_id',
});
 
await meter.shutdown();

After the event appears in Doow, move the track() call to the application path where usage is created.

Event shape

meter.track({
  metric: 'tokens',
  quantity: 1024,
  license_id: 'lic_...',
  unit: 'tokens',
  attribution: {
    model: 'gpt-4o',
    team: 'platform',
  },
});
FieldDescription
metricMetric name that matches the usage you want Doow to report
quantityNumeric usage value
license_idDoow license that receives the usage
unitOptional unit label
attributionOptional metadata for team, model, environment, feature, or service

Do not send request payloads, customer content, secrets, or raw application logs in attribution.

Initialization options

OptionTypeDefaultDescription
endpointstringhttps://api.doow.coDoow API endpoint
enabledbooleantrueSet to false to disable all tracking (useful in development)
attributionobjectNoneKey-value pairs merged into every event for environment, team, or service attribution
flushAtnumber20Flush after this many events are queued
flushIntervalnumber10000Flush every N milliseconds
retryCountnumber3Max retries on transient failures
onErrorfunctionconsole.warnCalled when the SDK reports an error
debugbooleanfalseEnable debug logging

Environment variable overrides

Environment variables can set common SDK options.

VariableDescription
DOOW_TRACK_API_KEYYour dk_ API key
DOOW_TRACK_ENDPOINTOverride the API endpoint
DOOW_TRACK_DISABLED=trueDisable the SDK entirely
DOOW_TRACK_FLUSH_ATFlush event count threshold
DOOW_TRACK_FLUSH_INTERVALFlush interval in milliseconds
DOOW_TRACK_ATTRIBUTIONJSON string for SDK-level attribution (for example, {"env":"prod"})

Graceful shutdown

Call meter.shutdown() before the process exits so buffered events can flush.

process.on('SIGTERM', async () => {
  await meter.shutdown();
  process.exit(0);
});

Confirm the event arrived

After sending a test event, open the integration detail page from Company Settings, then Integrations. A healthy SDK connection shows recent received events for the expected metric and license.

If the event does not appear, confirm that the dk_ key is valid, the event has a numeric quantity, and the license_id matches a license in your Doow workspace.

Production checklist

Before using this method in production:

  • Store the dk_ key in a secret manager or environment variable.
  • Confirm batching and retry settings match your traffic volume.
  • Confirm the service calls shutdown() during process termination.
  • Create separate keys for staging and production when you need independent revocation.
  • Keep metric names and units stable before tying them to customer reporting.

Troubleshooting

Use these checks when events do not arrive:

  • Confirm the dk_ key is active and belongs to the expected Doow workspace.
  • Confirm each event includes metric, quantity, and license_id.
  • Confirm quantity is numeric and greater than zero.
  • Confirm your process flushes events before shutdown.
  • Check application logs for authentication, validation, or network errors.

Disconnecting

Go to Settings, then API Keys, then SDK Keys in your Doow workspace and revoke the key. Replace the key in your application before sending more production events.

Next steps

After the test event appears, send events from a production-like environment and confirm batching, retry, and shutdown behavior before rollout.

Was this page helpful?