Skip to content

Go SDK Overview

The Shield360 Go SDK provides OpenTelemetry-native observability for Go applications using LLM APIs. It wraps your provider clients with lightweight instrumentation that automatically collects traces, metrics, and cost data without requiring any changes to your application logic.

OpenAI

Chat completions, streaming, embeddings, and image generation - with full token usage and cost tracking.

Anthropic

Claude messages and streaming - with cache token tracking and full OpenTelemetry semantic conventions.

vLLM

Chat completions and streaming against vLLM’s OpenAI-compatible API - with full token usage tracking.

Every instrumented call automatically records:

  • Distributed traces - spans with request/response details, model name, token counts, and cost
  • OTel metrics - gen_ai.client.token.usage, gen_ai.client.operation.duration, gen_ai.server.time_to_first_token, gen_ai.server.time_per_output_token, gen_ai.server.request.duration
  • Streaming metrics - time-to-first-chunk and per-chunk latency observations
  • Cost tracking - automatic cost calculation using the built-in pricing data
Terminal window
go get github.com/ThinkfleetAI/shield360-go
package main
import (
"context"
"fmt"
"log"
shield360 "github.com/ThinkfleetAI/shield360-go"
"github.com/ThinkfleetAI/shield360-go/instrumentation/openai"
)
func main() {
// 1. Initialize Shield360 (once, at startup)
if err := shield360.Init(shield360.Config{
OtlpEndpoint: "http://127.0.0.1:4318",
ApplicationName: "my-ai-app",
Environment: "production",
}); err != nil {
log.Fatal(err)
}
defer shield360.Shutdown(context.Background())
// 2. Create an instrumented client
client := openai.NewClient("your-openai-api-key")
// 3. Use it exactly like a normal client
resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
Model: "gpt-4o",
Messages: []openai.Message{
{Role: "user", Content: "Hello, world!"},
},
MaxTokens: 100,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}

Replace YOUR_OTEL_ENDPOINT with the URL of your OpenTelemetry backend, such as http://127.0.0.1:4318 for a local Shield360 deployment.

Pass a Config struct to shield360.Init():

FieldEnvironment VariableDescriptionDefault
OtlpEndpointOTEL_EXPORTER_OTLP_ENDPOINTOTLP backend URLhttp://127.0.0.1:4318
OtlpHeaders-Additional HTTP headers for OTLP requests{}
ApplicationName-Name of your applicationdefault
Environment-Deployment environment labeldefault
ServiceVersion-Service version string""
DisableTracing-Disable trace collectionfalse
DisableMetrics-Disable metrics collectionfalse
DisableBatch-Disable batch export (useful for testing)false
DisableCaptureMessageContent-Omit prompt/completion text from spansfalse
DetailedTracing-Enable component-level tracing detailfalse
DisablePricingFetch-Skip fetching remote pricing datafalse
PricingEndpoint-URL for custom pricing JSONbuilt-in
PricingInfo-In-process pricing overrides{}
TraceExporterTimeout-Timeout for trace exports10s
MetricExporterTimeout-Timeout for metric exports10s
MetricExportInterval-Interval for metric exports30s
// If OTEL_EXPORTER_OTLP_ENDPOINT is set, no endpoint config is needed
shield360.Init(shield360.Config{
ApplicationName: "my-ai-app",
})
Terminal window
export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318