Skip to main content
Send a signal to the current active trace. This is a convenience function that automatically determines the trace ID from the current execution context.

Signature

function sendTraceSignal(
  name: string,
  value: string | boolean | number,
  signalType?: 'boolean' | 'numerical'
): void

Parameters

name
string
required
Name of the signal.
value
string | boolean | number
required
Value of the signal. Can be a string, boolean, or number.
signalType
'boolean' | 'numerical'
Optional signal type. If not provided, the type will be auto-detected based on the value.

Returns

void - The signal is queued and will be sent when the trace is flushed.

Behavior

  • If no active span/trace is found, a warning is logged and the signal is not sent
  • The signal is added to pending trace signals and will be sent when the trace completes
  • This function is synchronous and does not block execution

Examples

Send a signal to the current trace

import { sendTraceSignal, span } from 'zeroeval';

@span()
async function processUser(userId: string) {
  // Send a signal to the trace
  sendTraceSignal('processing_type', 'user');
  
  // Process user...
  return { userId };
}

Send numerical trace signals

import { sendTraceSignal, tracer } from 'zeroeval';

async function processData(data: any[]) {
  const rootSpan = tracer.startSpan('processData');
  
  try {
    sendTraceSignal('data_size', data.length);
    sendTraceSignal('has_data', data.length > 0);
    
    // Process data...
  } finally {
    tracer.endSpan(rootSpan);
  }
}

Track trace-level metrics

import { sendTraceSignal, tracer } from 'zeroeval';

async function analyzeWorkflow() {
  const span = tracer.startSpan('workflow');
  
  try {
    let apiCalls = 0;
    
    // Make multiple API calls
    for (let i = 0; i < 5; i++) {
      await makeApiCall();
      apiCalls++;
    }
    
    // Track total API calls at trace level
    sendTraceSignal('api_calls_count', apiCalls);
    sendTraceSignal('workflow_complete', true);
  } finally {
    tracer.endSpan(span);
  }
}

Build docs developers (and LLMs) love