Skip to content

paperwave/observatory

 
 

Repository files navigation

Observatory

The Context Company does agent observability. We care deeply about DX; it's our single biggest priority.

Observatory is a monorepo containing core packages for AI agent observability across TypeScript and Python:

TypeScript:

Python:

  • contextcompany - Python SDK with built-in integrations for LangChain, CrewAI, Agno, and LiteLLM

Local mode (AI SDK + Next.js)

Local mode allows you to run The Context Company in a local-first way. This is 100% open-source and requires no account or API key. To set up local mode, refer to the guide below or our documentation.

Local mode currently only supports Vercel AI SDK on Next.js.

Setup

Step 1: Install dependencies

pnpm add @contextcompany/otel @vercel/otel @opentelemetry/api

Step 2: Add instrumentation to Next.js

If you haven't already, add an instrumentation.[js|ts] file in the root directory of your project (or inside the src folder if you're using one). Call the registerOTelTCC function to instrument your AI SDK calls.

See the Next.js Instrumentation guide for more information on instrumenting your Next.js application.

// instrumentation.ts
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    const { registerOTelTCC } = await import("@contextcompany/otel/nextjs");
    registerOTelTCC({ local: true });
  }
}

Step 3: Add widget to layout

Add the Local Mode widget to the root layout of your Next.js application.

// app/layout.tsx
import Script from "next/script";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        {/* add The Context Company widget */}
        <Script
          crossOrigin="anonymous"
          src="//unpkg.com/@contextcompany/widget/dist/auto.global.js"
        />
        {/* other scripts */}
      </head>
      <body>{children}</body>
    </html>
  );
}

Step 4: Enable telemetry for AI SDK calls

As of AI SDK v5, telemetry is experimental and requires the experimental_telemetry flag to be set to true. Ensure you set this flag to true for all AI SDK calls you want to instrument.

// route.ts
import { generateText } from "ai";

const result = generateText({
  // ...
  experimental_telemetry: { isEnabled: true }, // required
});

Note

By default, The Context Company collects limited anonymous usage data when running local mode. No sensitive or personally identifiable information is ever collected. You can view exactly which events and values are tracked here. To disable anonymous telemetry, set the TCC_DISABLE_ANONYMOUS_TELEMETRY environment variable to true in your Next.js project. Learn more about this in our documentation.

Examples

Check out the examples/ directory for working demos across all supported frameworks:

Example Framework Language
nextjs-widget AI SDK + Local Widget TypeScript
nextjs-aisdk AI SDK + Cloud Mode TypeScript
claude-agent-sdk Claude Agent SDK TypeScript
langchain-ts LangChain / LangGraph TypeScript
mastra Mastra TypeScript
custom-ts Custom Instrumentation TypeScript
openclaw OpenClaw (OTLP Collector) TypeScript
pi Pi Agent SDK TypeScript
langchain LangChain Python
crewai CrewAI Python
agno Agno Python
custom-python Custom Instrumentation Python

Contributing

Acknowledgments

  • Big thanks to Anthony Hoang for being an active contributor and maintainer!
  • Special thanks to @RobPruzan for helping with the design of the tool and being an early adopter.
  • React Scan has a phenomenal DX and Preact widget that we took inspiration from.
  • The implementation behind the Next.js Devtools overlay widget was insightful.

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 68.9%
  • Python 17.2%
  • CSS 13.8%
  • JavaScript 0.1%