Initializing HoneyHive Tracer

Use the following code to initialize HoneyHive tracing in your project:

For TypeScript/JavaScript projects, use the HoneyHiveTracer class to initialize tracing:

import { HoneyHiveTracer } from "honeyhive";

const tracer = await HoneyHiveTracer.init({
  apiKey: process.env.HH_API_KEY,
  project: process.env.HH_PROJECT,
  sessionName: "your-session-name",
});

This initializes tracing for your Vercel AI SDK application. Make sure to set the appropriate environment variables (HH_API_KEY and HH_PROJECT) before running your application.

Supported Vercel AI SDK Versions/Interfaces

Compatible with Vercel AI SDK versions supporting the experimental telemetry feature. Please check the Vercel AI SDK documentation for specific version compatibility.

For the most up-to-date compatibility information, please refer to the HoneyHive documentation.

Integrating with generateText

The Vercel AI SDK’s generateText function supports telemetry integration through the experimental_telemetry option. Here’s how to enable tracing:

const result = await generateText({
  model: openai('your-model-name'),
  prompt: 'Your prompt here',
  experimental_telemetry: {
    isEnabled: true,
    tracer: tracer.getTracer(),
  },
});

Nesting

Nesting is handled automatically by the HoneyHive tracing system. When you use traced components within other traced components, the system will create a hierarchical structure of spans, reflecting the nested nature of your Vercel AI SDK operations.

Enriching Properties

For information on how to enrich your traces and spans with additional context, see our enrichment documentation.

Adding Evaluators

Once traces have been logged in the HoneyHive platform, you can then run evaluations with either Python or TypeScript.

Cookbook Examples

TypeScript Example

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { WrapperTracer, HoneyHiveTracer } from "honeyhive";

const HH_API_KEY = process.env.HH_API_KEY || "";
const HH_API_URL = process.env.HH_API_URL;
const HH_PROJECT = process.env.HH_PROJECT || "";
const HH_PROJECT_ID = process.env.HH_PROJECT_ID || "";

async function initializeTracer(sessionName: string): Promise<HoneyHiveTracer> {
  const tracer = await HoneyHiveTracer.init({
    apiKey: HH_API_KEY,
    project: HH_PROJECT,
    sessionName: sessionName,
  });

  return tracer;
}

async function main() {
  const tracer = await initializeTracer('vercelTest');
  const result = await generateText({
    model: openai('gpt-4-turbo'),
    prompt: 'Write a short story about a cat.',
    experimental_telemetry: {
      isEnabled: true,
      tracer: tracer.getTracer(),
    },
  });

  console.log(result.text);
}

main().catch(console.error);

This example demonstrates how to integrate HoneyHive tracing with the Vercel AI SDK in a TypeScript environment, covering tracer initialization and text generation with OpenAI models.