Setting up Traceloop SDK for Middleware (Go)
This guide will walk you through the process of setting up the Traceloop SDK to work with Middleware for LLM Observability in a Go environment.
1. Install the SDK
Run the following command in your terminal:
go get github.com/traceloop/go-openllmetry/traceloop-sdk
2. Initialize the SDK
In your LLM application, initialize the Traceloop tracer:
import sdk "github.com/traceloop/go-openllmetry/traceloop-sdk" func main() { ctx := context.Background() traceloop := sdk.NewClient(config.Config{ BaseURL: "https://<MW_UID>.middleware.io:443", Headers: map[string]string{ "Authorization": "<MW_API_KEY>", "X-Trace-Source": "traceloop",
3. Log Your Prompts
Currently, automatic instrumentation is not available for Go libraries. You'll need to manually log your prompts and completions.
Here's an example of how to log prompts and completions when using the OpenAI library:
import ( openai "github.com/sashabaranov/go-openai" ) func call_llm() { // Call OpenAI like you normally would resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo,
Viewing Your Traces
After setting up the Traceloop SDK with Middleware, you'll be able to view your LLM application traces in your Middleware LLM Observability Section.
This integration provides instant visibility into everything happening within your LLM, including calls to vector databases or other external services.
For more detailed information on setting up Traceloop with Go, please refer to the Traceloop Go documentation.
Need assistance or want to learn more about using Traceloop with Middleware? Contact our support team in Slack.