Watchlog DocsWatchlog Docs
Home
Get Started
Integrations
Log Watchlist
Home
Get Started
Integrations
Log Watchlist
  • Watchlog
  • Get Started
  • Custom Events
  • APM
  • Kubernetes Cluster Monitoring
  • AI Traces Client Libraries Documentation

AI Traces Client Libraries Documentation

JavaScript (npm)

Installation

npm install @watchlog/ai-tracer

Quick Start

// test.js
const WatchlogTracer = require('@watchlog/ai-tracer');
const tracer = new WatchlogTracer({
  app: 'my-app',          // required, your application name
  // agentURL: 'http://...', // optional override of the agent URL
  // batchSize: 50,          // spans per HTTP batch
  // flushOnSpanCount: 50,    // completed spans to auto-enqueue
  // ... see full config options below
});

// Start a new trace
tracer.startTrace();

// Create root span
const rootSpan = tracer.startSpan('handle-request', { feature: 'ai-summary' });

// ... do work ...

// End the root span
tracer.endSpan(rootSpan, {
  tokens: 100,
  cost: 0.002,
  model: 'gpt-4',
  provider: 'openai',
  input: 'Summarize this text...',
  output: 'Summary result'
});

// Send all spans (flushes queue)
tracer.send();

Configuration Options

OptionTypeDefaultDescription
appstringn/aRequired: your application name
agentURLstringauto-detected (K8s vs localhost)Override agent endpoint URL
batchSizenumber50Spans to send per HTTP request
flushOnSpanCountnumber50Auto-enqueue when this many spans complete
maxRetriesnumber3HTTP retry attempts
maxQueueSizenumber10000Max spans in disk queue before rotating file
maxFieldLengthnumber256Max length for serialized fields
sensitiveFieldsstring[]["password","api_key","token"]Fields to redact in metadata
autoFlushIntervalnumber1000ms between background flushes
maxInMemorySpansnumber5000Keep this many completed spans in memory
requestTimeoutnumber5000ms HTTP timeout for agent requests
queueItemTTLnumber600000 (10min)ms TTL for queued spans on disk

Python (pip)

Installation

pip install python-ai-tracer

Quick Start

from watchlog_ai_tracer import WatchlogTracer

# Initialize tracer (app name required)
tracer = WatchlogTracer(app='my-app')

# Start a new trace
tracer.start_trace()

# Create a span
span_id = tracer.start_span('handle-request', metadata={'feature': 'ai-summary'})

# ... your code here ...

# End the span with metrics
tracer.end_span(span_id,
                tokens=100,
                cost=0.002,
                model='gpt-4',
                provider='openai',
                input='Summarize this text...',
                output='Summary result')

# Send/flush all spans
tracer.send()

Configuration Options

ParameterTypeDefaultDescription
appstrRequiredYour application name
agent_urlstrauto-detected (K8s vs localhost)Override the agent endpoint URL
batch_sizeint50Spans per HTTP batch
flush_on_span_countint50Completed spans to auto-enqueue
max_retriesint3HTTP retry attempts
max_queue_sizeint10000Max spans in disk queue before rotating file
max_field_lengthint256Max length for serialized fields
sensitive_fieldslist[str]["password","api_key","token"]Fields to redact in metadata
auto_flush_intervalint1000ms between background flushes
max_in_memory_spansint5000Keep this many completed spans in memory
request_timeoutint5000ms HTTP timeout for agent requests
queue_item_ttlint600000 (10min)ms TTL for queued spans on disk

Repository Links

  • JavaScript: https://github.com/Watchlog-monitoring/watchlog-node-ai-tracer
  • Python: https://github.com/Watchlog-monitoring/python-ai-tracer

Versioning

Both packages use semantic versioning. Please refer to the respective CHANGELOGs in each repo.


Support

For issues and contributions, open an issue or pull request on GitHub.

Last Updated:: 8/6/25, 8:03 AM
Contributors: mohammad
Prev
Kubernetes Cluster Monitoring