BeeAI Tracing (JS)

Auto-instrument and observe BeeAI agents

This module provides automatic instrumentation for the BeeAI framework using OpenInference. It integrates with @opentelemetry/sdk-node to collect and export telemetry data to Arize.

Launch Arize

To get started, sign up for a free Arize account. You'll need your Space ID and API Key to configure tracing.

Install

Install the relevant packages. Adjust the BeeAI Framework version if needed.

npm install --save beeai-framework \
  @arizeai/openinference-instrumentation-beeai \
  @arizeai/openinference-semantic-conventions \
  @opentelemetry/sdk-trace-node \
  @opentelemetry/resources \
  @opentelemetry/exporter-trace-otlp-proto \
  @opentelemetry/semantic-conventions \
  @opentelemetry/instrumentation

Setup

To instrument your application, import and enable BeeAIInstrumentation . Create the instrumentation.js file:

import {
  NodeTracerProvider,
  SimpleSpanProcessor,
  ConsoleSpanExporter,
} from "@opentelemetry/sdk-trace-node";
import { resourceFromAttributes } from "@opentelemetry/resources";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";
import * as beeaiFramework from "beeai-framework";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { BeeAIInstrumentation } from "@arizeai/openinference-instrumentation-beeai";

const provider = new NodeTracerProvider({
  resource: resourceFromAttributes({
    [ATTR_SERVICE_NAME]: "beeai-project",
    [SEMRESATTRS_PROJECT_NAME]: "beeai-project",
  }),
  spanProcessors: [
    new SimpleSpanProcessor(new ConsoleSpanExporter()),
    new SimpleSpanProcessor(
      new OTLPTraceExporter({
        url: `https://otlp.arize.com/v1/traces`,
        headers: { 
          'space_id': 'your-space-id-here',
          'api_key': 'your-api-key-here',
        },
      }),
    ),
  ],
});

provider.register();

const beeAIInstrumentation = new BeeAIInstrumentation();
beeAIInstrumentation.manuallyInstrument(beeaiFramework);

registerInstrumentations({
  instrumentations: [beeAIInstrumentation],
});

console.log("👀 OpenInference initialized");

Run BeeAI

Import the instrumentation.js file first, then use the BeeAI framework as usual. This sample agent built using BeeAI with automatic tracing:

import "./instrumentation.js";
import { ToolCallingAgent } from "beeai-framework/agents/toolCalling/agent";
import { TokenMemory } from "beeai-framework/memory/tokenMemory";
import { DuckDuckGoSearchTool } from "beeai-framework/tools/search/duckDuckGoSearch";
import { OpenMeteoTool } from "beeai-framework/tools/weather/openMeteo";
import { OpenAIChatModel } from "beeai-framework/adapters/openai/backend/chat";

const llm = new OpenAIChatModel(
  "gpt-4o", 
  {},
  { apiKey: 'your-api-key-here' } 
);

const agent = new ToolCallingAgent({
  llm,
  memory: new TokenMemory(),
  tools: [
    new DuckDuckGoSearchTool(),
    new OpenMeteoTool(), // weather tool
  ],
});

async function main() {
  const response = await agent.run({ prompt: "What's the current weather in Berlin?" });
  console.log(`Agent 🤖 : `, response.result.text);
}

main();

Observe

Arize provides visibility into your BeeAI agent operations by automatically tracing all interactions.

Troubleshooting

Add the following at the top of your instrumentation.js to see OpenTelemetry diagnostic logs in your console while debugging:

import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";

// Enable OpenTelemetry diagnostic logging
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);

If traces aren't appearing, a common cause is an outdated beeai-framework package. Check the diagnostic logs for version or initialization errors and update your package as needed.

Resources

Last updated

Was this helpful?