Blue Guardrails

Send traces from TypeScript

Instrument your TypeScript application with OpenTelemetry and send traces to Blue Guardrails for issue detection.

Send OpenTelemetry traces from a Node.js application to Blue Guardrails. These examples use OpenInference instrumentation to capture model requests and responses.

For the coding-agent setup prompt or Python examples, open Getting started.

Prerequisites

Configure your environment

Set your workspace key and your model provider's key before running an example:

export BLUE_GUARDRAILS_API_KEY="<YOUR_API_KEY>"
export OPENAI_API_KEY="<YOUR_OPENAI_KEY>"
# Or ANTHROPIC_API_KEY for Anthropic / Claude Agent SDK.

Never hardcode or commit keys. These examples run on the server, not in the browser.

Install dependencies and send traces

Choose your framework for its installation command and complete example. These are the same snippets used in the product's onboarding flow.

npm install openai @arizeai/openinference-instrumentation-openai @opentelemetry/api @opentelemetry/exporter-trace-otlp-proto @opentelemetry/sdk-node
import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { NodeSDK } from "@opentelemetry/sdk-node";
import OpenAI from "openai";

const sdk = new NodeSDK({
  serviceName: "my-ai-app",
  traceExporter: new OTLPTraceExporter({
    url: process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ?? "https://api.blueguardrails.com/v1/traces",
    headers: { Authorization: `Bearer ${process.env.BLUE_GUARDRAILS_API_KEY}` },
  }),
});

sdk.start();

const instrumentation = new OpenAIInstrumentation();
instrumentation.manuallyInstrument(OpenAI);

const client = new OpenAI();

try {
  const response = await client.chat.completions.create({
    model: "gpt-5-mini",
    messages: [
      { role: "system", content: "Answer the question based on the context." },
      { role: "user", content: "Context: Revenue in Q1 was $85 Billion." },
      { role: "user", content: "What was Google's revenue in Q1 2025?" },
    ],
  });

  console.log(response.choices[0].message.content);
} finally {
  await sdk.shutdown();
}

Initialize tracing once before AI calls. In a running application, call sdk.shutdown() on application shutdown, not after every request. The standalone samples call it when they finish so the process can exit after exporting.

Verify your traces

Run the example with your project's TypeScript runner, such as npx tsx example.ts. Open your workspace's Dashboard to see incoming messages and issue metrics.

On this page