Skip to main content

Overview

SpanOptions defines the configuration for creating spans in ZeroEval. You use this interface when applying the @span decorator to methods or when wrapping functions with withSpan().

Type Definition

interface SpanOptions {
  name: string;
  sessionId?: string;
  sessionName?: string;
  tags?: Record<string, string>;
  attributes?: Record<string, unknown>;
  inputData?: unknown;
  outputData?: unknown;
}

Properties

name
string
required
The name of the span. This identifies the operation being traced and appears in your ZeroEval dashboard.
sessionId
string
Optional session identifier to group related spans together. Use this to track multi-turn conversations or user sessions.
sessionName
string
Optional human-readable name for the session. Helps identify sessions in the dashboard.
tags
Record<string, string>
Optional key-value pairs for categorizing and filtering spans. Tags must be strings and are useful for grouping related operations.
attributes
Record<string, unknown>
Optional arbitrary metadata to attach to the span. You can store any JSON-serializable data here for additional context.
inputData
unknown
Optional explicit input data for the span. If not provided, the decorator automatically captures function arguments.
outputData
unknown
Optional explicit output data for the span. If not provided, the decorator automatically captures the return value.

Usage Examples

Basic Span Decorator

import { span } from 'zeroeval';

class AIService {
  @span({ name: 'generate-response' })
  async generateResponse(prompt: string): Promise<string> {
    // Your logic here
    return 'Generated response';
  }
}

Span with Session Tracking

@span({
  name: 'chat-turn',
  sessionId: 'user-123',
  sessionName: 'Customer Support Chat'
})
async handleChatMessage(message: string): Promise<string> {
  // Process message
  return response;
}

Span with Tags and Attributes

@span({
  name: 'classify-intent',
  tags: {
    model: 'gpt-4',
    environment: 'production'
  },
  attributes: {
    maxTokens: 100,
    temperature: 0.7
  }
})
async classifyIntent(text: string): Promise<string> {
  // Classification logic
  return intent;
}

Explicit Input/Output Data

@span({
  name: 'process-data',
  inputData: { source: 'user-upload' },
  outputData: { status: 'success' }
})
async processData(file: File): Promise<void> {
  // Process file
}

Using withSpan Function Wrapper

import { withSpan } from 'zeroeval';

const result = await withSpan(
  {
    name: 'fetch-user-data',
    tags: { userId: '123' },
    attributes: { cached: false }
  },
  async () => {
    // Your async operation
    return await fetchUserData();
  }
);

Build docs developers (and LLMs) love