Documentation
¶
Overview ¶
Package shield360 provides OpenTelemetry-native observability for LLM applications in Go. It offers automatic instrumentation for popular LLM providers like OpenAI and Anthropic.
Index ¶
Constants ¶
const Version = "1.0.0"
Version is the current version of the Shield360 Go SDK.
This is the single source of truth. Releases go through the Release / Packages workflow, which tags this repository `sdk-go-<Version>`; the mirror sync then tags ThinkfleetAI/shield360-go `v<Version>`, which is the tag Go itself resolves, because a module's import path is its repository URL and this repository is private.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
Init initializes the Shield360 SDK with the provided configuration. This should be called once at application startup.
Example:
err := shield360.Init(shield360.Config{
OtlpEndpoint: "http://127.0.0.1:4318",
Environment: "production",
ApplicationName: "my-go-app",
})
if err != nil {
log.Fatalf("Failed to initialize Shield360: %v", err)
}
defer shield360.Shutdown(context.Background())
func IsInitialized ¶
func IsInitialized() bool
IsInitialized returns whether Shield360 has been initialized.
Types ¶
type Config ¶
type Config struct {
// OtlpEndpoint is the OTLP endpoint for sending traces and metrics
// Default: "http://127.0.0.1:4318"
OtlpEndpoint string
// OtlpHeaders are additional headers to send with OTLP requests
OtlpHeaders map[string]string
// Environment identifies the deployment environment
// Default: "default"
Environment string
// ApplicationName is the name of your application
// Default: "default"
ApplicationName string
// TracerName is the name for the tracer provider
// Default: "shield360"
TracerName string
// ServiceVersion is the version of your service
ServiceVersion string
// DisableTracing disables trace collection
// Default: false
DisableTracing bool
// DisableMetrics disables metrics collection
// Default: false
DisableMetrics bool
// DisableBatch disables batch processing for exports
// Default: false
DisableBatch bool
// TraceExporterTimeout is the timeout for trace exports
// Default: 10 seconds
TraceExporterTimeout time.Duration
// MetricExporterTimeout is the timeout for metric exports
// Default: 10 seconds
MetricExporterTimeout time.Duration
// MetricExportInterval is the interval for metric exports
// Default: 30 seconds
MetricExportInterval time.Duration
// PricingInfo contains custom pricing information for models
PricingInfo map[string]ModelPricing
// PricingEndpoint is the endpoint to fetch pricing information
// Default: none; pricing is not fetched unless an endpoint is set
PricingEndpoint string
// DisablePricingFetch disables automatic pricing information fetching
DisablePricingFetch bool
// DisableCaptureMessageContent prevents prompt/completion text from being
// recorded as span attributes. Set to true for privacy-sensitive workloads.
// Default: false (content IS captured, matching Python SDK default of capture_message_content=True)
DisableCaptureMessageContent bool
// DetailedTracing enables detailed component-level tracing.
// Default: false
DetailedTracing bool
// IDGenerator overrides the default OTel ID generator. Use this when
// callers need deterministic trace/span IDs (e.g. the shield360 CLI's
// coding-agent hook deriving a stable TraceId from a session id so
// every span emitted across separate hook invocations lands in the
// same trace). When nil, OTel's random generator is used.
IDGenerator sdktrace.IDGenerator
// Sampler overrides the default head sampler. When nil, the SDK
// uses AlwaysSample — every span emitted reaches the collector.
// Callers wanting a head-sampling strategy (e.g. drop noisy
// `coding_agent.tool.requested` events) can pass a
// ParentBasedSampler or a custom span-name aware sampler here.
// See cli/internal/otlp/sampler.go for an example.
Sampler sdktrace.Sampler
// ExtraResourceAttributes are merged into the OTel Resource set on
// every span/metric this SDK emits. Callers use this to attach
// stable identity (e.g. `gen_ai.user.name`, `host.name`) once at
// startup rather than tagging each span individually.
ExtraResourceAttributes map[string]string
}
Config holds the configuration for Shield360 SDK initialization
type EvaluateRuleOptions ¶
type EvaluateRuleOptions struct {
// URL is the Shield360 dashboard base URL.
// Falls back to SHIELD360_URL env var, then http://127.0.0.1:3000.
URL string
// APIKey is the Bearer token for authentication.
// Falls back to SHIELD360_API_KEY env var.
APIKey string
// EntityType specifies which kind of entities to match ("context", "prompt", or "evaluation").
EntityType RuleEntityType
// Fields are the trace attributes to evaluate against rules.
// Example: {"gen_ai.system": "openai", "gen_ai.request.model": "gpt-4"}
Fields map[string]interface{}
// IncludeEntityData requests full entity data in the response when true.
IncludeEntityData bool
// EntityInputs provides optional inputs for entity resolution (e.g. prompt variables).
EntityInputs map[string]interface{}
// Timeout for the HTTP request. Defaults to 30 seconds.
Timeout time.Duration
}
EvaluateRuleOptions holds parameters for the EvaluateRule call.
type EvaluateRuleResult ¶
type EvaluateRuleResult struct {
MatchingRuleIDs []string `json:"matchingRuleIds"`
Entities []RuleEntity `json:"entities"`
EntityData map[string]interface{} `json:"entity_data,omitempty"`
}
EvaluateRuleResult is the parsed response from the rule engine evaluate endpoint.
func EvaluateRule ¶
func EvaluateRule(ctx context.Context, opts EvaluateRuleOptions) (*EvaluateRuleResult, error)
EvaluateRule calls the Shield360 dashboard rule-engine evaluate endpoint. It sends the provided fields against configured rules and returns matching rule IDs, associated entities, and optionally the full entity data.
This function does NOT require shield360.Init() — it is a standalone HTTP call, consistent with get_prompt/get_secrets in the Python and TypeScript SDKs.
Example:
result, err := shield360.EvaluateRule(ctx, shield360.EvaluateRuleOptions{
EntityType: shield360.RuleEntityContext,
Fields: map[string]interface{}{
"gen_ai.system": "openai",
"gen_ai.request.model": "gpt-4",
"service.name": "my-app",
},
IncludeEntityData: true,
})
type ModelPricing ¶
ModelPricing represents pricing information for a model
type RuleEntity ¶
type RuleEntity struct {
RuleID string `json:"rule_id"`
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
}
RuleEntity represents a single matched rule-entity association.
type RuleEntityType ¶
type RuleEntityType string
RuleEntityType constrains the entity_type values accepted by the rule engine.
const ( // RuleEntityContext matches rules that return context entities. RuleEntityContext RuleEntityType = "context" // RuleEntityPrompt matches rules that return prompt entities. RuleEntityPrompt RuleEntityType = "prompt" // RuleEntityEvaluation matches rules that return evaluation entities. RuleEntityEvaluation RuleEntityType = "evaluation" )