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.
Supported providers
Section titled “Supported providers”Chat completions, streaming, embeddings, and image generation - with full token usage and cost tracking.
Claude messages and streaming - with cache token tracking and full OpenTelemetry semantic conventions.
Chat completions and streaming against vLLM’s OpenAI-compatible API - with full token usage tracking.
What gets collected
Section titled “What gets collected”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
Installation
Section titled “Installation”go get github.com/ThinkfleetAI/shield360-gogo get github.com/ThinkfleetAI/shield360-go@v1.2.3Replace v1.2.3 with the version you want to install.
Quick start
Section titled “Quick start”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.
Configuration
Section titled “Configuration”Pass a Config struct to shield360.Init():
| Field | Environment Variable | Description | Default |
|---|---|---|---|
OtlpEndpoint | OTEL_EXPORTER_OTLP_ENDPOINT | OTLP backend URL | http://127.0.0.1:4318 |
OtlpHeaders | - | Additional HTTP headers for OTLP requests | {} |
ApplicationName | - | Name of your application | default |
Environment | - | Deployment environment label | default |
ServiceVersion | - | Service version string | "" |
DisableTracing | - | Disable trace collection | false |
DisableMetrics | - | Disable metrics collection | false |
DisableBatch | - | Disable batch export (useful for testing) | false |
DisableCaptureMessageContent | - | Omit prompt/completion text from spans | false |
DetailedTracing | - | Enable component-level tracing detail | false |
DisablePricingFetch | - | Skip fetching remote pricing data | false |
PricingEndpoint | - | URL for custom pricing JSON | built-in |
PricingInfo | - | In-process pricing overrides | {} |
TraceExporterTimeout | - | Timeout for trace exports | 10s |
MetricExporterTimeout | - | Timeout for metric exports | 10s |
MetricExportInterval | - | Interval for metric exports | 30s |
Via environment variable
Section titled “Via environment variable”// If OTEL_EXPORTER_OTLP_ENDPOINT is set, no endpoint config is neededshield360.Init(shield360.Config{ ApplicationName: "my-ai-app",})export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318Getting started
Section titled “Getting started”Monitor chat completions, streaming, embeddings, and image generation
Anthropic IntegrationMonitor Claude messages and streaming with cache token tracking
vLLM IntegrationMonitor chat completions and streaming against your vLLM server
DestinationsSend telemetry to Datadog, Grafana, New Relic, and other observability stacks
ConfigurationConfigure the Shield360 SDK according to your requirements