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

@axon-ai/openai-tracer

v1.0.3

Published

OpenAI Function Calling tracer for Axon

Readme

OpenAI Function Calling Tracer

A comprehensive tracing solution for OpenAI Function Calling agents, providing detailed monitoring, cost analysis, and performance insights.

🚀 Features

  • Function Call Tracking: Monitor all function calls with detailed parameters and results
  • Tool Selection Analysis: Track which tools are selected and why
  • Cost Calculation: Automatic cost calculation based on token usage and model pricing
  • Performance Metrics: Latency tracking and performance analysis
  • Error Monitoring: Comprehensive error tracking and debugging
  • Real-time Dashboard: Live visualization of agent execution
  • Conversation Flow: Track multi-turn conversations and context

📦 Installation

npm install @axon-ai/openai-tracer openai

🎯 Quick Start

Basic Usage

import OpenAI from 'openai';
import { createOpenAITracer, TracedOpenAI } from '@axon-ai/openai-tracer';

// Initialize OpenAI client
const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// Create tracer
const tracer = createOpenAITracer({
  projectName: 'my-agent',
  metadata: {
    version: '1.0.0',
    environment: 'production',
  },
});

// Create traced OpenAI client
const tracedOpenAI = new TracedOpenAI(openai, tracer);

// Use the traced client
const response = await tracedOpenAI.createChatCompletion({
  model: 'gpt-4',
  messages: [
    { role: 'user', content: 'What\'s the weather in NYC?' }
  ],
  tools: [/* your tools */],
});

Advanced Configuration

const tracer = createOpenAITracer({
  projectName: 'weather-agent',
  endpoint: 'http://localhost:3000', // Custom trace server
  metadata: {
    agentType: 'weather',
    version: '2.1.0',
    environment: 'staging',
    team: 'ai-platform',
  },
  autoConnect: true, // Auto-connect to trace server
});

🔧 API Reference

OpenAITracer

Constructor Options

interface OpenAITraceConfig {
  projectName?: string;        // Project identifier
  endpoint?: string;          // Trace server endpoint
  metadata?: Record<string, any>; // Custom metadata
  autoConnect?: boolean;      // Auto-connect to server
}

Methods

traceFunctionCallStart(functionName, arguments, model, messages, tools?)

Track the start of a function call.

traceFunctionCallEnd(eventId, result, cost, latency, tokens?)

Track the completion of a function call.

traceToolSelection(availableTools, selectedTool, reasoning?, confidence?)

Track tool selection decisions.

traceConversationTurn(userMessage, assistantResponse, model, tokens?, cost?)

Track conversation turns.

traceError(error, context, functionName?, arguments?)

Track errors and exceptions.

TracedOpenAI

A wrapper around the OpenAI client that automatically traces all interactions.

Methods

createChatCompletion(params)

Enhanced chat completion with automatic tracing.

📊 Dashboard Integration

The tracer automatically sends data to the Agent Trace dashboard for visualization:

  • Function Call Flow: Visual representation of function calls
  • Cost Analysis: Detailed cost breakdown by function and model
  • Performance Metrics: Latency and throughput analysis
  • Tool Usage: Which tools are used most frequently
  • Error Tracking: Error rates and debugging information

🎨 Example Agents

Weather Agent

import { createOpenAITracer, TracedOpenAI } from '@axon-ai/openai-tracer';

const tracer = createOpenAITracer({ projectName: 'weather-agent' });
const tracedOpenAI = new TracedOpenAI(openai, tracer);

const tools = [
  {
    type: 'function',
    function: {
      name: 'getCurrentWeather',
      description: 'Get current weather',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string' }
        }
      }
    }
  }
];

const response = await tracedOpenAI.createChatCompletion({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Weather in NYC?' }],
  tools,
});

Stock Analysis Agent

const tracer = createOpenAITracer({ projectName: 'stock-agent' });
const tracedOpenAI = new TracedOpenAI(openai, tracer);

const tools = [
  {
    type: 'function',
    function: {
      name: 'getStockPrice',
      description: 'Get stock price',
      parameters: {
        type: 'object',
        properties: {
          symbol: { type: 'string' }
        }
      }
    }
  }
];

const response = await tracedOpenAI.createChatCompletion({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'AAPL stock price?' }],
  tools,
});

🔍 Event Types

The tracer tracks several types of events:

Function Call Events

  • function_call_start: When a function call begins
  • function_call_end: When a function call completes

Tool Selection Events

  • tool_selection: When the model selects a tool

Conversation Events

  • conversation_turn: Each user-assistant interaction

Error Events

  • error: When errors occur during execution

💰 Cost Calculation

Automatic cost calculation based on:

  • Model Pricing: Current OpenAI pricing for different models
  • Token Usage: Prompt and completion tokens
  • Function Calls: Additional costs for function calling

Supported models:

  • GPT-4: $0.03/1K prompt, $0.06/1K completion
  • GPT-4 Turbo: $0.01/1K prompt, $0.03/1K completion
  • GPT-3.5 Turbo: $0.001/1K prompt, $0.002/1K completion

🚨 Error Handling

The tracer provides comprehensive error tracking:

try {
  const response = await tracedOpenAI.createChatCompletion(params);
} catch (error) {
  // Error is automatically traced
  console.error('API call failed:', error);
}

🔧 Development

Building

npm run build

Development Mode

npm run dev

Testing

npm test

📈 Performance

The tracer is designed for minimal overhead:

  • Async Operations: Non-blocking event queuing
  • Batch Processing: Efficient event batching
  • Memory Management: Automatic cleanup of old events
  • Network Optimization: Compressed data transmission

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🔄 Changelog

v1.0.0

  • Initial release
  • OpenAI Function Calling support
  • Cost calculation
  • Performance metrics
  • Dashboard integration