Skip to main content
Quick setup? Instead of following these steps manually, copy a prompt into your coding agent and it will set this up for you automatically.
LangWatch TypeScript Repo
LangWatch TypeScript SDK version
Get started with LangWatch TypeScript SDK in under 5 minutes. This guide will walk you through setting up observability for your LLM applications, from basic tracing to advanced features.
Protip: wanna to get started even faster? Copy our llms.txt and ask an AI to do this integration

Prerequisites

Before you start, make sure you have:

Quick Start (5 minutes)

Step 1: Install Dependencies

The @ai-sdk/openai and ai packages are only required for the example in this guide. You can skip this step if you’re only looking to install the LangWatch SDK.

Step 2: Set Up API Keys

  1. LangWatch API Key:
    • Go to app.langwatch.ai and sign up
    • Create a new project
    • Copy your API key from the project settings
  2. OpenAI API Key:
  3. Set environment variables:
LANGWATCH_PROJECT_ID is required when using a service API key (e.g. for CI/CD or multi-project setups). Project API keys obtained via npx langwatch login or from the project settings page already have the project context built in.

Step 3: Your First LLM Trace

Create a new file app.ts:

Step 4: Run and See Results

Now visit your LangWatch dashboard - you should see your first trace! 🎉
What you’ll see: A trace named “greet-user” with input/output data, timing, and status.

What Just Happened?

Let’s break down what we just set up:
  • Trace: The entire greetUser function execution
  • Span: The individual operation within the trace
  • Input/Output: The data flowing through your function
  • Timing: How long each operation took
  • Status: Whether the operation succeeded

Core Concepts

Think of LangWatch like a debugger for your LLM applications:
  • Traces = Complete user interactions (e.g., “What’s the weather?”)
  • Spans = Individual steps within a trace (e.g., “LLM call”, “database query”)
  • Threads = Conversations (group related traces together)
  • Users = Individual users (for analytics)
For detailed explanations of all concepts, see our Concepts Guide.
For consistent observability across your application, learn about Semantic Conventions - standardized naming guidelines for attributes and metadata.

Integrations

LangWatch offers seamless integrations with many popular TypeScript libraries and frameworks. These integrations provide automatic instrumentation, capturing relevant data from your LLM applications with minimal setup. Below is a list of currently supported integrations. Click on each to learn more about specific setup instructions and available features:
For detailed integration guides, see our integration documentation. Each integration includes framework-specific examples and best practices.

Common Development Scenarios

Scenario 1: LLM Application

Scenario 2: RAG Application

For consistent attribute naming and TypeScript autocomplete support, see our Semantic Conventions guide. For advanced span management techniques, check out Manual Instrumentation.

Scenario 3: Conversation Threading

Configuration

Basic Configuration

Environment-Specific Setup

Graceful Shutdown

The setupObservability function returns an ObservabilityHandle that provides a shutdown method for graceful cleanup. This ensures all pending traces are exported before your application terminates.

Automatic Shutdown

By default, LangWatch automatically handles shutdown when your application receives a SIGTERM signal:

Manual Shutdown

For environments where you can’t listen to SIGTERM or need custom shutdown logic, you can manually call the shutdown method:

What Happens During Shutdown

The shutdown process ensures data integrity:
  1. Flushes pending traces to the exporter
  2. Closes the trace exporter connection
  3. Shuts down the tracer provider
  4. Cleans up registered instrumentations
Always call shutdown() before your application exits to prevent data loss. The method is safe to call multiple times.
If you don’t call shutdown(), some traces may be lost when your application terminates abruptly.

Development Workflow

Local Development

  1. Set up environment:
  1. Run your app:
  1. Check dashboard: Visit app.langwatch.ai to see traces

Debugging

Enable console logging for local development:

Troubleshooting

Common Issues

  • Check your API key is correct
  • Verify network connectivity to app.langwatch.ai
  • Ensure setupObservability is called before any tracing
  • Check browser console for errors
  • See Debugging and Troubleshooting for detailed solutions
  • Use batch processing: processorType: 'batch'
  • Implement graceful shutdown
  • Consider reducing data capture in production
  • Tracer overhead is minimal (~1-2ms per span)
  • Use module-level tracers (not function-level)
  • Consider sampling in high-traffic scenarios

Getting Help

Next Steps

Now that you have basic tracing working, explore:
Start simple and add complexity gradually. You can always add more detailed tracing later as your application grows!