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

glass-ai

v0.1.1

Published

Glass AI TypeScript SDK - OpenTelemetry tracing for AI applications

Readme

Glass AI TypeScript SDK

OpenTelemetry tracing for AI applications.

Installation

npm install glass-ai
# or
yarn add glass-ai
# or
pnpm add glass-ai

Quick Start

import * as glass from 'glass-ai';

// Initialize the SDK
glass.init({ apiKey: 'your-api-key' });

// Wrap functions with tracing
const processMessage = glass.trace(async (message: string) => {
  // Your AI logic here
  return `Processed: ${message}`;
}, { name: 'processMessage' });

// Track user interactions
await glass.interaction({ userId: 'user-123', input: 'Hello!' }, async (ctx) => {
  const result = await processMessage('Hello!');
  ctx.finish({ response: result });
  return result;
});

API Reference

Initialization

glass.init(options?: InitOptions): void

Initialize the Glass SDK and configure OpenTelemetry.

Options:

  • apiKey?: string - Glass API key (or set GLASS_API_KEY environment variable)
  • debug?: boolean - Enable console logging of traces (default: false)
  • instrumentations?: Instrumentor[] - Custom OpenTelemetry instrumentors
  • skipDefaultInstrumentations?: boolean - Skip auto-instrumenting AI libraries (default: false)
  • traceEndpoint?: string - Custom OTLP endpoint URL

Example:

// Basic initialization
glass.init({ apiKey: 'your-api-key' });

// With debug mode
glass.init({ apiKey: 'your-api-key', debug: true });

// Using environment variable
process.env.GLASS_API_KEY = 'your-api-key';
glass.init();

trace()

glass.trace<T>(fn: T, options?: TraceOptions): T

Higher-order function that wraps a function with OpenTelemetry tracing.

Options:

  • name?: string - Custom span name (defaults to function name)
  • attributes?: Record<string, unknown> - Additional span attributes

Example:

// Wrap a sync function
const add = glass.trace((a: number, b: number) => a + b, { name: 'add' });

// Wrap an async function
const fetchUser = glass.trace(async (id: string) => {
  const response = await fetch(`/api/users/${id}`);
  return response.json();
}, { name: 'fetchUser' });

// With attributes
const analyzeText = glass.trace(
  async (text: string) => { /* ... */ },
  { name: 'analyzeText', attributes: { model: 'gpt-4' } }
);

interaction()

glass.interaction<T>(
  metadata: InteractionMetadata,
  callback: (ctx: InteractionContext) => T | Promise<T>
): Promise<T>

Track a user interaction with a span. Metadata flows to nested traced functions.

Metadata:

  • userId?: string - User identifier
  • sessionId?: string - Session identifier
  • project?: string - Project classification
  • input?: string - User input text
  • service?: string - Service name
  • [key: string]: unknown - Additional custom metadata

Context methods:

  • ctx.finish(output) - Record the final output
  • ctx.setAttribute(key, value) - Set a span attribute
  • ctx.recordException(error) - Record an exception

Example:

const response = await glass.interaction(
  { userId: 'user-123', sessionId: 'session-456', project:'conversational-chat', input: 'Hello!' },
  async (ctx) => {
    // Nested traces automatically inherit userId, sessionId
    const result = await processMessage('Hello!');
    
    // Set additional attributes
    ctx.setAttribute('tokens_used', 150);
    
    // Record the final output
    ctx.finish({ response: result, tokens: 150 });
    
    return result;
  }
);

task()

glass.task<T>(
  name: string,
  callback: (ctx: TaskContext) => T | Promise<T>,
  options?: TaskOptions
): Promise<T>

Create a manual task span with explicit input/output recording.

Options:

  • attributes?: Record<string, unknown> - Additional span attributes

Context methods:

  • ctx.recordInput(data) - Record input data
  • ctx.recordOutput(data) - Record output data
  • ctx.setAttribute(key, value) - Set a span attribute
  • ctx.recordException(error) - Record an exception

Example:

const result = await glass.task('embed-documents', async (ctx) => {
  const documents = ['doc1', 'doc2', 'doc3'];
  
  // Record the input
  ctx.recordInput({ documents, count: documents.length });
  
  // Do the work
  const embeddings = await embedDocuments(documents);
  
  // Record the output
  ctx.recordOutput({ embeddings_count: embeddings.length });
  
  return embeddings;
}, { attributes: { model: 'text-embedding-ada-002' } });

Advanced Usage

Access Active Metadata

import { getActiveMetadata } from 'glass-ai';

// Inside a traced function or interaction callback
const metadata = getActiveMetadata();
console.log(metadata.userId); // Access inherited metadata

Custom Context Propagation

import { runWithMetadata } from 'glass-ai';

// Run code with custom metadata
runWithMetadata({ customField: 'value' }, () => {
  // All traced functions here will have customField in their metadata
});

Shutdown

import { shutdown } from 'glass-ai';

// Gracefully shutdown and flush pending spans
await shutdown();

Requirements

  • Node.js >= 18.0.0
  • TypeScript >= 5.0 (for TypeScript users)

License

MIT