- A core tracing module (
github.com/langwatch/langwatch/sdks/go) with the exporter, theTracer, theLangWatchSpanhelpers and span filtering. It has no provider dependencies at all. - A set of provider instrumentations, each its own Go module, so importing one never pulls in the others’ SDKs. OpenAI, Anthropic, Google Gemini / Vertex, Amazon Bedrock, Azure OpenAI, Ollama, the community
go-openaiclient and Firebase Genkit are all supported natively. - A typed REST API client (
github.com/langwatch/langwatch/sdks/go/client) for reading and writing LangWatch resources: prompts, datasets, traces, annotations, evaluations and more.
Protip: wanna to get started even faster? Copy our llms.txt and ask an AI to do this integration
Prerequisites
Before you begin, ensure you have:- Go 1.25 or later installed on your system
- A LangWatch account at app.langwatch.ai
- An OpenAI API key (or other LLM provider key)
- Basic familiarity with Go and OpenTelemetry concepts
Setup
Get started in just a few minutes by installing the SDK and instrumenting your application.1
Get your LangWatch API Key
Sign up at app.langwatch.ai and find your API key in your project settings. Set it as an environment variable:
LANGWATCH_PROJECT_ID is required when using a service API key or a Personal Access Token (e.g. for CI/CD or multi-project setups). Project API keys obtained from the project settings page already have the project context built in.You can verify your API key is set by running
echo $LANGWATCH_API_KEY2
Install SDK Packages
Add the core SDK plus the instrumentation for the provider you use. Each instrumentation is its own module, so you only pull in the SDK you actually need:
Verify installation by running
go mod tidy and checking that all dependencies are resolved.3
Configure the LangWatch Exporter
Set up the LangWatch exporter in your application initialization.
NewExporter reads LANGWATCH_API_KEY from the environment, builds an OTLP exporter pointed at LangWatch, and you register it as your global tracer provider:4
Instrument Your OpenAI Client
Add the LangWatch middleware to your OpenAI client. The middleware captures request and response content by default, so you do not need to enable either:
The middleware captures input and output content by default (
langwatch.DataCaptureAll). To opt out, pass otelopenai.WithDataCapture(langwatch.DataCaptureNone). See Data Capture.5
Create Your First Trace
Start a root span to capture your LLM interaction. Any instrumented call made with the returned
ctx is nested under it:View your traces at app.langwatch.ai within seconds of making your first API call.
Complete Working Example
Here’s a minimal working example that combines all the setup steps. Note theopenai-go/v3 import paths:
Core Concepts
The Go SDK is designed to feel familiar to anyone who has used OpenTelemetry. It provides a thin wrapper to simplify LangWatch-specific functionality.- Each message triggering your LLM pipeline as a whole is captured with a Trace.
- A Trace contains multiple Spans, which are the steps inside your pipeline.
- Traces can be grouped into a conversation by assigning a common
thread_id. - Use User ID to track individual user interactions.
- Apply Labels for custom categorization and filtering.
Creating a Trace
A trace represents a single, end-to-end task, like handling a user request. You create a trace by starting a “root” span. All other spans created within its context will be nested under it. Before creating traces, ensure you have configured the SDK as shown in the Setup Guide.Creating Nested Spans
To instrument specific parts of your pipeline (like a RAG query or a tool call), create nested spans within an active trace. Set a span type so LangWatch can visualise it appropriately.The context
ctx is crucial. It carries the active span information, ensuring that tracer.Start() correctly creates a nested span instead of a new trace.Automatic Instrumentation
Each provider instrumentation is a separate Go module so importing one never pulls in the others’ SDKs. Add only the one(s) you use. All of the following are supported natively:
Every instrumentation captures the maximum available GenAI data: request + response model, every token type (input / output / total / cached / reasoning / cache-creation), cost where the provider returns it, finish reasons, request params, system instructions, tool definitions, and (capture-gated) input/output.
OpenAI-compatible providers
Many providers expose an OpenAI-compatible endpoint. Reuse theopenai instrumentation, point the client at the provider’s base URL, and label the spans with the right provider name via WithGenAIProvider:
Recording Data on Spans
LangWatchSpan embeds the standard OpenTelemetry span and adds LangWatch helper methods. All setters return the span, so they can be chained:
SetInput / SetOutput infer a value type (text, json, chat_messages, list, …) from the Go value, or you can force one with a typed variant such as SetInputJSON or SetOutputChatMessages. Token usage is recorded with SetGenAIUsage; cost (only) is recorded with SetMetrics:
Data Capture
Data capture controls whether span input/output content leaves the process. It is enforced at export time, so one setting governs every instrumentation (the provider middlewares and your manual spans alike). Span structure, metrics, metadata, models and identity are always kept; only the content attributes are stripped. The default, unconfigured, captures everything.langwatch.DataCaptureAll, langwatch.DataCaptureInput, langwatch.DataCaptureOutput and langwatch.DataCaptureNone. Each instrumentation also accepts WithDataCapture(...) to gate content at the source for a single client; the two compose.
The LangWatch API Client
Separate from tracing,github.com/langwatch/langwatch/sdks/go/client is a typed REST client for the LangWatch API: prompts, datasets, traces, annotations, events, evaluations, triggers, monitors, scenarios and projects. It lives in its own module so the generated code stays out of the core graph:
sk-lw-* keys or pat-lw-* PATs with a project id).
Environment Variables
The SDK respects these environment variables for configuration:Filtering Spans
The LangWatch SDK filters which spans are exported. Use filtering to reduce noise, exclude sensitive data, or focus on specific instrumentation.Using Preset Filters
The SDK includes convenient preset filters for common use cases:Custom Filtering
Create custom filters usingInclude() or Exclude() with matching criteria:
Matcher Types
The SDK provides several matcher types:Filters use AND semantics when combined - a span must pass all filters to be exported. Within a
Criteria, matchers use OR semantics - a span matches if it matches any of the matchers in the list.Features
- 🔗 OpenTelemetry integration - Works with your existing OTel setup
- 🚀 Multi-provider instrumentation - OpenAI, Anthropic, Gemini/Vertex, Bedrock, Azure, Ollama, Genkit and more
- 📊 Rich LLM telemetry - Capture inputs, outputs, every token type, cost, and model information
- 🔍 Specialized span types - LLM, Chain, Tool, Agent, RAG, and more
- 🧵 Thread support - Group related LLM interactions together
- 🎛️ Data capture controls - Decide exactly what content leaves your process
- 🔄 Streaming support - Real-time reconstruction of streaming responses
- 🧰 Typed REST client - Read and write prompts, datasets, traces, evaluations and more
Troubleshooting
Common Issues
No traces appearing in LangWatch dashboard:- Verify your
LANGWATCH_API_KEYis set correctly - Check that you’re calling the shutdown function to flush traces
- Ensure your application is making LLM API calls through an instrumented client
- Run
go mod tidyto ensure all dependencies are properly resolved - Verify you’re using Go 1.25 or later
- Make sure the OpenAI client import path is
github.com/openai/openai-go/v3(and/v3/option)
- Check that the LangWatch endpoint URL is correct
- Verify your API key has the correct permissions
Getting Help
If you’re still having issues:- Check the API reference for detailed function documentation
- Review the OpenTelemetry Go documentation
- Join our community support for additional help
Next Steps
- Learn about specific provider integrations like OpenAI, Anthropic and Amazon Bedrock
- Check the API reference for detailed documentation
- Explore span types for specialized LLM operations
- Read the Data Capture controls to manage what content leaves your process