Documentation
¶
Index ¶
- func ExtractClientIP(r *http.Request) string
- func GetRequestContext(c *gin.Context) map[string]interface{}
- type BreakpointConfig
- type Config
- type Counter
- type Gauge
- type Histogram
- type SDK
- func (s *SDK) AddAttribute(span trace.Span, key, value string)
- func (s *SDK) AddAttributes(span trace.Span, attrs ...attribute.KeyValue)
- func (s *SDK) AddBoolAttribute(span trace.Span, key string, value bool)
- func (s *SDK) AddBusinessAttributes(span trace.Span, attrs map[string]interface{})
- func (s *SDK) AddDatabaseAttributes(span trace.Span, dbSystem, dbName, operation, table string)
- func (s *SDK) AddEvent(span trace.Span, name string, attrs ...attribute.KeyValue)
- func (s *SDK) AddFloatAttribute(span trace.Span, key string, value float64)
- func (s *SDK) AddHTTPAttributes(span trace.Span, method, url string, statusCode int)
- func (s *SDK) AddIntAttribute(span trace.Span, key string, value int64)
- func (s *SDK) AddUserAttributes(span trace.Span, userID, email string)
- func (s *SDK) CheckAndCapture(filePath string, lineNumber int, variables map[string]interface{})
- func (s *SDK) CheckAndCaptureWithContext(ctx context.Context, label string, variables map[string]interface{})
- func (s *SDK) Counter(name string, tags map[string]string) Counter
- func (s *SDK) EchoMiddleware() echo.MiddlewareFunc
- func (s *SDK) GRPCClientInterceptors() []grpc.DialOption
- func (s *SDK) GRPCServerInterceptors() []grpc.ServerOption
- func (s *SDK) Gauge(name string, tags map[string]string) Gauge
- func (s *SDK) GinMiddleware() gin.HandlerFunc
- func (s *SDK) GormPlugin() gorm.Plugin
- func (s *SDK) HTTPClient(client *http.Client) *http.Client
- func (s *SDK) HTTPHandler(handler http.Handler, operation string) http.Handler
- func (s *SDK) HTTPMiddleware(operation string) func(http.Handler) http.Handler
- func (s *SDK) Histogram(name string, tags map[string]string) Histogram
- func (s *SDK) MongoClientOptions() *options.ClientOptions
- func (s *SDK) RecordError(span trace.Span, err error)
- func (s *SDK) RecordErrorWithMessage(span trace.Span, err error, message string)
- func (s *SDK) SetError(span trace.Span, message string)
- func (s *SDK) SetSuccess(span trace.Span)
- func (s *SDK) SetSuccessWithMessage(span trace.Span, message string)
- func (s *SDK) Shutdown(ctx context.Context) error
- func (s *SDK) SnapshotClient() *SnapshotClient
- func (s *SDK) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (s *SDK) TraceFunction(ctx context.Context, name string, fn func(context.Context, trace.Span) error) error
- func (s *SDK) TraceGormDB(db *gorm.DB) error
- func (s *SDK) Tracer() trace.Tracer
- func (s *SDK) WithGormTracing(config *gorm.Config) *gorm.Config
- func (s *SDK) WrapDB(db *sql.DB, dbSystem string) *TracedDB
- func (s *SDK) WrapMongoClient(client *mongo.Client) *mongo.Client
- func (s *SDK) WrapRedis(client *redis.Client) error
- func (s *SDK) WrapRedisCluster(client *redis.ClusterClient) error
- func (s *SDK) WrapRoundTripper(rt http.RoundTripper) http.RoundTripper
- type SecurityFlag
- type Snapshot
- type SnapshotClient
- type TracedDB
- func (tdb *TracedDB) Begin() (*sql.Tx, error)
- func (tdb *TracedDB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (tdb *TracedDB) Close() error
- func (tdb *TracedDB) DB() *sql.DB
- func (tdb *TracedDB) Driver() driver.Driver
- func (tdb *TracedDB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tdb *TracedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tdb *TracedDB) Ping() error
- func (tdb *TracedDB) PingContext(ctx context.Context) error
- func (tdb *TracedDB) Prepare(query string) (*sql.Stmt, error)
- func (tdb *TracedDB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (tdb *TracedDB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tdb *TracedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (tdb *TracedDB) QueryRow(query string, args ...interface{}) *sql.Row
- func (tdb *TracedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (tdb *TracedDB) SetMaxIdleConns(n int)
- func (tdb *TracedDB) SetMaxOpenConns(n int)
- func (tdb *TracedDB) Stats() sql.DBStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractClientIP ¶ added in v1.3.0
ExtractClientIP extracts the client IP address from an HTTP request. It checks X-Forwarded-For, X-Real-IP headers (for proxied requests) and falls back to RemoteAddr. This function is used by the HTTP middleware to automatically add client IP to traces.
func GetRequestContext ¶ added in v1.0.3
GetRequestContext retrieves the request context from Gin context
Types ¶
type BreakpointConfig ¶
type BreakpointConfig struct {
ID string `json:"id"`
ServiceName string `json:"service_name"`
FilePath string `json:"file_path"`
FunctionName string `json:"function_name"`
Label string `json:"label,omitempty"` // Stable identifier
LineNumber int `json:"line_number"`
Condition string `json:"condition,omitempty"`
MaxCaptures int `json:"max_captures"`
CaptureCount int `json:"capture_count"`
ExpireAt *time.Time `json:"expire_at,omitempty"`
Enabled bool `json:"enabled"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
BreakpointConfig represents a breakpoint configuration
type Config ¶
type Config struct {
// Required
APIKey string
ServiceName string
// Optional - defaults to app.tracekit.dev
// Can be just the host (app.tracekit.dev) or full URL
Endpoint string
// Optional - defaults to /v1/traces
TracesPath string
// Optional - defaults to /v1/metrics
MetricsPath string
// Optional - defaults to true (use TLS)
UseSSL bool
// Optional - service version
ServiceVersion string
// Optional - deployment environment
Environment string
// Optional - additional resource attributes
ResourceAttributes map[string]string
// Optional - enable code monitoring
EnableCodeMonitoring bool
// Optional - code monitoring poll interval (default: 30s)
CodeMonitoringPollInterval time.Duration
// Optional - sampling rate (0.0 to 1.0, default: 1.0 = 100%)
SamplingRate float64
// Optional - batch timeout (default: 5s)
BatchTimeout time.Duration
// Optional - map hostnames to service names for peer.service attribute
// Useful for mapping localhost URLs to actual service names
// Example: map[string]string{"localhost:8084": "node-test-app", "localhost:8082": "go-test-app"}
ServiceNameMappings map[string]string
}
Config holds the TraceKit SDK configuration
type Counter ¶ added in v1.3.1
type Counter interface {
Inc()
Add(value float64)
}
Counter tracks monotonically increasing values
type Gauge ¶ added in v1.3.1
type Gauge interface {
Set(value float64)
Inc()
Dec()
}
Gauge tracks point-in-time values
type Histogram ¶ added in v1.3.1
type Histogram interface {
Record(value float64)
}
Histogram tracks value distributions
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is the main TraceKit SDK client
func (*SDK) AddAttribute ¶
AddAttribute adds a string attribute to a span
func (*SDK) AddAttributes ¶
AddAttributes adds multiple attributes to a span
func (*SDK) AddBoolAttribute ¶
AddBoolAttribute adds a boolean attribute to a span
func (*SDK) AddBusinessAttributes ¶
AddBusinessAttributes adds business-specific attributes (order ID, transaction ID, etc.)
func (*SDK) AddDatabaseAttributes ¶
AddDatabaseAttributes adds common database attributes to a span
func (*SDK) AddFloatAttribute ¶
AddFloatAttribute adds a float attribute to a span
func (*SDK) AddHTTPAttributes ¶
AddHTTPAttributes adds common HTTP attributes to a span
func (*SDK) AddIntAttribute ¶
AddIntAttribute adds an integer attribute to a span
func (*SDK) AddUserAttributes ¶
AddUserAttributes adds user-related attributes to a span
func (*SDK) CheckAndCapture ¶ added in v1.0.2
CheckAndCapture checks if there's a breakpoint and captures a snapshot
func (*SDK) CheckAndCaptureWithContext ¶ added in v1.0.4
func (s *SDK) CheckAndCaptureWithContext(ctx context.Context, label string, variables map[string]interface{})
CheckAndCaptureWithContext is a wrapper for code monitoring snapshot capture with context It automatically registers the breakpoint location - no need to manually create breakpoints!
label: Optional stable identifier (e.g. "payment-error", "auth-check")
If empty, uses auto-generated label based on function name
func (*SDK) EchoMiddleware ¶
func (s *SDK) EchoMiddleware() echo.MiddlewareFunc
EchoMiddleware returns an Echo middleware with OpenTelemetry instrumentation
func (*SDK) GRPCClientInterceptors ¶
func (s *SDK) GRPCClientInterceptors() []grpc.DialOption
GRPCClientInterceptors returns gRPC client interceptors with OpenTelemetry
func (*SDK) GRPCServerInterceptors ¶
func (s *SDK) GRPCServerInterceptors() []grpc.ServerOption
GRPCServerInterceptors returns gRPC server interceptors with OpenTelemetry
func (*SDK) GinMiddleware ¶
func (s *SDK) GinMiddleware() gin.HandlerFunc
GinMiddleware returns a Gin middleware with OpenTelemetry instrumentation It captures request context for code monitoring and adds client IP to spans
func (*SDK) GormPlugin ¶
GormPlugin returns a GORM plugin with OpenTelemetry instrumentation Use with: db.Use(sdk.GormPlugin())
func (*SDK) HTTPClient ¶
HTTPClient wraps an http.Client with OpenTelemetry instrumentation Automatically creates CLIENT spans for outgoing HTTP calls with peer.service attribute
func (*SDK) HTTPHandler ¶
HTTPHandler wraps an http.Handler with OpenTelemetry instrumentation and automatically captures client IP address
func (*SDK) HTTPMiddleware ¶
HTTPMiddleware returns a middleware function for standard http.Handler chains
func (*SDK) MongoClientOptions ¶
func (s *SDK) MongoClientOptions() *options.ClientOptions
MongoClientOptions returns MongoDB client options with OpenTelemetry instrumentation
func (*SDK) RecordError ¶
RecordError records an error on a span with stack trace and marks it as error
func (*SDK) RecordErrorWithMessage ¶
RecordErrorWithMessage records an error with a custom message
func (*SDK) SetError ¶
SetError marks a span as error with a message (without recording an error object)
func (*SDK) SetSuccess ¶
SetSuccess marks a span as successful
func (*SDK) SetSuccessWithMessage ¶
SetSuccessWithMessage marks a span as successful with a message
func (*SDK) SnapshotClient ¶
func (s *SDK) SnapshotClient() *SnapshotClient
SnapshotClient returns the code monitoring client (nil if not enabled)
func (*SDK) StartSpan ¶
func (s *SDK) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
StartSpan starts a new span with the given name
func (*SDK) TraceFunction ¶
func (s *SDK) TraceFunction(ctx context.Context, name string, fn func(context.Context, trace.Span) error) error
TraceFunction wraps a function with automatic span creation
func (*SDK) TraceGormDB ¶
TraceGormDB adds tracing to an existing GORM DB instance
func (*SDK) WithGormTracing ¶
WithGormTracing is a helper to configure a GORM DB with tracing Example:
db, err := gorm.Open(postgres.Open(dsn), sdk.WithGormTracing(&gorm.Config{}))
func (*SDK) WrapDB ¶
WrapDB wraps a database/sql DB with OpenTelemetry tracing This creates traced versions of all database operations
func (*SDK) WrapMongoClient ¶
WrapMongoClient wraps an existing MongoDB client with OpenTelemetry (not recommended, use MongoClientOptions instead) Note: This should be called before any operations on the client
func (*SDK) WrapRedisCluster ¶
func (s *SDK) WrapRedisCluster(client *redis.ClusterClient) error
WrapRedisCluster adds OpenTelemetry instrumentation to a Redis cluster client
func (*SDK) WrapRoundTripper ¶
func (s *SDK) WrapRoundTripper(rt http.RoundTripper) http.RoundTripper
WrapRoundTripper wraps an http.RoundTripper with OpenTelemetry instrumentation
type SecurityFlag ¶ added in v1.2.0
type SecurityFlag struct {
Type string `json:"type"`
Severity string `json:"severity"`
Variable string `json:"variable,omitempty"`
}
SecurityFlag represents a security issue found in snapshot variables
type Snapshot ¶
type Snapshot struct {
BreakpointID string `json:"breakpoint_id"`
ServiceName string `json:"service_name"`
FilePath string `json:"file_path"`
LineNumber int `json:"line_number"`
Variables map[string]interface{} `json:"variables"`
SecurityFlags []SecurityFlag `json:"security_flags,omitempty"`
StackTrace string `json:"stack_trace"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
RequestContext map[string]interface{} `json:"request_context,omitempty"`
CapturedAt time.Time `json:"captured_at"`
}
Snapshot represents a captured code state
type SnapshotClient ¶
type SnapshotClient struct {
// contains filtered or unexported fields
}
SnapshotClient handles code monitoring snapshots
func NewSnapshotClient ¶
func NewSnapshotClient(apiKey, baseURL, serviceName string) *SnapshotClient
NewSnapshotClient creates a new snapshot client
func (*SnapshotClient) CheckAndCapture ¶
func (c *SnapshotClient) CheckAndCapture(filePath string, lineNumber int, variables map[string]interface{})
CheckAndCapture checks if there's an active breakpoint at this location and captures a snapshot
func (*SnapshotClient) CheckAndCaptureWithContext ¶
func (c *SnapshotClient) CheckAndCaptureWithContext(ctx context.Context, label string, variables map[string]interface{})
CheckAndCaptureWithContext checks and captures with trace context It automatically registers the breakpoint location on first call label: optional stable identifier for the checkpoint
func (*SnapshotClient) Start ¶
func (c *SnapshotClient) Start()
Start begins polling for active breakpoints
type TracedDB ¶
type TracedDB struct {
// contains filtered or unexported fields
}
TracedDB is a wrapper around sql.DB that adds tracing
func (*TracedDB) ExecContext ¶
func (tdb *TracedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning rows, with tracing
func (*TracedDB) PingContext ¶
PingContext verifies connection with tracing
func (*TracedDB) PrepareContext ¶
PrepareContext creates a prepared statement with tracing
func (*TracedDB) QueryContext ¶
func (tdb *TracedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query with tracing
func (*TracedDB) QueryRow ¶
QueryRow executes a query that returns a single row with tracing (no context)
func (*TracedDB) QueryRowContext ¶
func (tdb *TracedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryRowContext executes a query that returns a single row with tracing
func (*TracedDB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of idle connections
func (*TracedDB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections