telemetry

package
v0.0.0-...-8e108db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 36 Imported by: 35

Documentation

Index

Constants

View Source
const (
	GCPTraceContextHeader = "X-Cloud-Trace-Context"
	AWSTraceContextHeader = "X-Amzn-Trace-Id"
)
View Source
const (
	ApiOrchestratorCountMeterName GaugeIntType = "api.orchestrator.status"
	OrchestratorStatusGaugeName   GaugeIntType = "orchestrator.status"

	// Sandbox metrics
	SandboxRamUsedGaugeName   GaugeIntType = "e2b.sandbox.ram.used"
	SandboxRamTotalGaugeName  GaugeIntType = "e2b.sandbox.ram.total"
	SandboxRamCacheGaugeName  GaugeIntType = "e2b.sandbox.ram.cache"
	SandboxCpuTotalGaugeName  GaugeIntType = "e2b.sandbox.cpu.total"
	SandboxDiskUsedGaugeName  GaugeIntType = "e2b.sandbox.disk.used"
	SandboxDiskTotalGaugeName GaugeIntType = "e2b.sandbox.disk.total"

	// Team metrics
	TeamSandboxRunningGaugeName GaugeIntType = "e2b.team.sandbox.running"

	SandboxCountGaugeName GaugeIntType = "api.env.instance.running"

	// Build resource metrics
	BuildRootfsSizeHistogramName HistogramType = "template.build.rootfs.size"
)
View Source
const DefaultPprofPort = 6060

DefaultPprofPort is the default port that we should use to mount pprof endpoint.

Variables

View Source
var (
	// Pre-allocated result attributes for use with PrecomputeAttrs.
	Success = attribute.String(resultAttr, resultTypeSuccess)
	Failure = attribute.String(resultAttr, resultTypeFailure)
)

Functions

func GetCounter

func GetCounter(meter metric.Meter, name CounterType) (metric.Int64Counter, error)

func GetFloatHistogram

func GetFloatHistogram(meter metric.Meter, name HistogramType) (metric.Float64Histogram, error)

func GetGaugeFloat

func GetGaugeFloat(meter metric.Meter, name GaugeFloatType) (metric.Float64ObservableGauge, error)

func GetGaugeInt

func GetGaugeInt(meter metric.Meter, name GaugeIntType) (metric.Int64ObservableGauge, error)

func GetHistogram

func GetHistogram(meter metric.Meter, name HistogramType) (metric.Int64Histogram, error)

func GetResource

func GetResource(ctx context.Context, nodeID, serviceName, serviceCommit, serviceVersion, serviceInstanceID string, additional ...attribute.KeyValue) (*resource.Resource, error)

func GetUpDownCounter

func GetUpDownCounter(meter metric.Meter, name UpDownCounterType) (metric.Int64UpDownCounter, error)

func NewEventWriter

func NewEventWriter(ctx context.Context, name string) io.Writer

func NewMeterExporter

func NewMeterExporter(ctx context.Context, extraOption ...otlpmetricgrpc.Option) (sdkmetric.Exporter, error)

func NewMeterProvider

func NewMeterProvider(metricsExporter sdkmetric.Exporter, metricExportPeriod time.Duration, res *resource.Resource, extraOption ...sdkmetric.Option) (metric.MeterProvider, error)

func NewPprofMux

func NewPprofMux() *http.ServeMux

NewPprofMux returns a ServeMux with pprof handlers registered on a dedicated mux rather than http.DefaultServeMux, preventing accidental exposure.

Mirrors the five handlers that `_ "net/http/pprof"` registers in its init(). The Index handler already serves all runtime/pprof profiles (heap, goroutine, allocs, block, mutex, threadcreate, etc.) by name from the URL path.

func NewPprofServer

func NewPprofServer() *http.Server

func NewSpanExporter

func NewSpanExporter(ctx context.Context, extraOption ...otlptracegrpc.Option) (sdktrace.SpanExporter, error)

func NewTextPropagator

func NewTextPropagator() propagation.TextMapPropagator

func NewTracerProvider

func NewTracerProvider(spanExporter sdktrace.SpanExporter, res *resource.Resource) trace.TracerProvider

func OTELCollectorGRPCEndpoint

func OTELCollectorGRPCEndpoint() string

func ParseEdgeTraceID

func ParseEdgeTraceID(gcpHeader, awsHeader string) (string, bool)

ParseEdgeTraceID extracts a trace ID from cloud-provider trace headers. These headers are untrusted and are only used for cross-service correlation.

func PrecomputeAttrs

func PrecomputeAttrs(kv ...attribute.KeyValue) metric.MeasurementOption

PrecomputeAttrs builds a reusable MeasurementOption from the given attribute key-values. The option must include all attributes (including "result"). Use with Stopwatch.Record to avoid per-call attribute allocation.

func ReportCriticalError

func ReportCriticalError(ctx context.Context, message string, err error, attrs ...attribute.KeyValue)

func ReportError

func ReportError(ctx context.Context, message string, err error, attrs ...attribute.KeyValue)

func ReportErrorByCode

func ReportErrorByCode(ctx context.Context, code int, message string, err error, attrs ...attribute.KeyValue)

func ReportEvent

func ReportEvent(ctx context.Context, name string, attrs ...attribute.KeyValue)

func SetAttributes

func SetAttributes(ctx context.Context, attrs ...attribute.KeyValue)

func WithBuildID

func WithBuildID(buildID string) attribute.KeyValue

func WithClusterID

func WithClusterID(clusterID uuid.UUID) attribute.KeyValue

func WithEdgeTraceID

func WithEdgeTraceID(traceID string) attribute.KeyValue

func WithEnvdVersion

func WithEnvdVersion(envdVersion string) attribute.KeyValue

func WithFirecrackerVersion

func WithFirecrackerVersion(firecrackerVersion string) attribute.KeyValue

func WithKernelVersion

func WithKernelVersion(kernelVersion string) attribute.KeyValue

func WithMaskedAPIKey

func WithMaskedAPIKey(maskedAPIKey string) attribute.KeyValue

func WithMaskedAccessToken

func WithMaskedAccessToken(maskedAccessToken string) attribute.KeyValue

func WithNodeID

func WithNodeID(nodeID string) attribute.KeyValue

func WithSandboxID

func WithSandboxID(sandboxID string) attribute.KeyValue

func WithServiceInstanceID

func WithServiceInstanceID(serviceInstanceID string) attribute.KeyValue

func WithTeamID

func WithTeamID(teamID string) attribute.KeyValue

func WithTemplateID

func WithTemplateID(templateID string) attribute.KeyValue

func WithUserID

func WithUserID(userID string) attribute.KeyValue

Types

type Client

type Client struct {
	MetricExporter  sdkmetric.Exporter
	MeterProvider   metric.MeterProvider
	SpanExporter    sdktrace.SpanExporter
	TracerProvider  trace.TracerProvider
	TracePropagator propagation.TextMapPropagator
	LogsProvider    LogProvider
}

func New

func New(ctx context.Context, nodeID, serviceName, serviceCommit, serviceVersion, serviceInstanceID string, additional ...attribute.KeyValue) (*Client, error)

New creates a telemetry client that exports traces, metrics, and logs via gRPC. Telemetry is enabled when the OTEL_COLLECTOR_GRPC_ENDPOINT environment variable is set (e.g. "localhost:4317"). When unset, a noop client is returned with zero overhead.

func NewAnonymous

func NewAnonymous(ctx context.Context, serviceName string) (*Client, error)

NewAnonymous creates a telemetry client for tools and CLI commands that don't have build-time injected metadata (commitSHA, version, nodeID). serviceName is the primary identifier used for filtering traces and metrics in observability tools (e.g. Grafana). The remaining resource attributes are filled with sensible defaults (hostname, "unknown" commit, "dev" version).

func NewNoopClient

func NewNoopClient() *Client

func (*Client) Shutdown

func (t *Client) Shutdown(ctx context.Context) error

func (*Client) StartRuntimeInstrumentation

func (t *Client) StartRuntimeInstrumentation() error

StartRuntimeInstrumentation registers OTEL Go runtime metric callbacks.

Collected metrics (semantic-convention names):

  • go.memory.used
  • go.memory.limit
  • go.memory.allocated
  • go.memory.allocations
  • go.memory.gc.goal
  • go.goroutine.count
  • go.processor.limit
  • go.config.gogc

The callbacks are invoked by the MeterProvider and stop automatically when it shuts down — no separate goroutine is spawned.

type CounterType

type CounterType string
const (
	ApiOrchestratorCreatedSandboxes CounterType = "api.orchestrator.created_sandboxes"
	SandboxCreateMeterName          CounterType = "api.env.instance.started"

	TeamSandboxCreated CounterType = "e2b.team.sandbox.created"

	EnvdInitCalls CounterType = "orchestrator.sandbox.envd.init.calls"

	ApiRedisStoragePublisherPublished CounterType = "api.redis_storage.publisher.published"
	ApiRedisStoragePublisherDropped   CounterType = "api.redis_storage.publisher.dropped"
)
const (
	// Build result counters
	BuildResultCounterName      CounterType = "template.build.result"
	BuildCacheResultCounterName CounterType = "template.build.cache.result"

	// TCP Firewall counters
	TCPFirewallConnectionsTotal CounterType = "orchestrator.tcpfirewall.connections.total"
	TCPFirewallErrorsTotal      CounterType = "orchestrator.tcpfirewall.errors.total"
	TCPFirewallDecisionsTotal   CounterType = "orchestrator.tcpfirewall.decisions.total"

	// Ingress proxy counters
	IngressProxyConnectionsBlockedTotal CounterType = "orchestrator.proxy.connections.blocked.total"

	// cmux counters
	CmuxErrorsTotal CounterType = "orchestrator.cmux.errors.total"

	// Firecracker net counters — global totals, no sandbox_id (low cardinality).
	// All carry a direction=tx/rx attribute. Per-sandbox distributions are histograms below.
	SandboxFCNetFails         CounterType = "orchestrator.sandbox.fc.net.fails"
	SandboxFCNetNoAvailBuffer CounterType = "orchestrator.sandbox.fc.net.no_avail_buffer"
	SandboxFCNetTapIOFails    CounterType = "orchestrator.sandbox.fc.net.tap_io_fails"

	// Firecracker block counters — global totals, no sandbox_id (low cardinality).
	// Carry a direction=read/write attribute where applicable.
	SandboxFCBlockFails         CounterType = "orchestrator.sandbox.fc.block.fails"
	SandboxFCBlockNoAvailBuffer CounterType = "orchestrator.sandbox.fc.block.no_avail_buffer"
)

type EventWriter

type EventWriter struct {
	// contains filtered or unexported fields
}

func (*EventWriter) Write

func (w *EventWriter) Write(p []byte) (n int, err error)

type GaugeFloatType

type GaugeFloatType string
const (
	SandboxCpuUsedGaugeName GaugeFloatType = "e2b.sandbox.cpu.used"
)

type GaugeIntType

type GaugeIntType string

type HistogramType

type HistogramType string
const (
	// Build timing histograms
	BuildDurationHistogramName      HistogramType = "template.build.duration"
	BuildPhaseDurationHistogramName HistogramType = "template.build.phase.duration"
	BuildStepDurationHistogramName  HistogramType = "template.build.step.duration"

	// Sandbox timing histograms
	OrchestratorSandboxCreateDurationName HistogramType = "orchestrator.sandbox.create.duration"
	WaitForEnvdDurationHistogramName      HistogramType = "orchestrator.sandbox.envd.init.duration"

	// TCP Firewall histograms
	TCPFirewallConnectionDurationHistogramName    HistogramType = "orchestrator.tcpfirewall.connection.duration"
	TCPFirewallConnectionsPerSandboxHistogramName HistogramType = "orchestrator.tcpfirewall.connections.per_sandbox"

	// Ingress proxy histograms
	IngressProxyConnectionDurationHistogramName    HistogramType = "orchestrator.proxy.connection.duration"
	IngressProxyConnectionsPerSandboxHistogramName HistogramType = "orchestrator.proxy.connections.per_sandbox"
)
const (
	ApiRedisStoragePublisherPublishDuration HistogramType = "api.redis_storage.publisher.publish.duration"

	// Firecracker net histograms — per-sandbox distribution per metrics flush, no sandbox_id.
	// Firecracker serializes SharedIncMetric as per-flush deltas (default flush interval: 60 s).
	// Symmetric TX/RX metrics carry a direction=tx/rx attribute; TX-only metrics always use direction=tx.
	SandboxFCNetBytes                HistogramType = "orchestrator.sandbox.fc.net.bytes"
	SandboxFCNetPackets              HistogramType = "orchestrator.sandbox.fc.net.packets"
	SandboxFCNetCount                HistogramType = "orchestrator.sandbox.fc.net.count"
	SandboxFCNetRateLimiterThrottled HistogramType = "orchestrator.sandbox.fc.net.rate_limiter_throttled"
	// TX-only: no RX equivalent in Firecracker metrics.
	SandboxFCNetRateLimiterEventCount HistogramType = "orchestrator.sandbox.fc.net.rate_limiter_event_count"
	SandboxFCNetRemainingReqs         HistogramType = "orchestrator.sandbox.fc.net.remaining_reqs"

	// Firecracker block histograms — per-sandbox distribution per metrics flush, no sandbox_id.
	// Symmetric read/write metrics carry a direction=read/write attribute.
	SandboxFCBlockBytes                 HistogramType = "orchestrator.sandbox.fc.block.bytes"
	SandboxFCBlockCount                 HistogramType = "orchestrator.sandbox.fc.block.count"
	SandboxFCBlockRateLimiterThrottled  HistogramType = "orchestrator.sandbox.fc.block.rate_limiter_throttled"
	SandboxFCBlockRateLimiterEventCount HistogramType = "orchestrator.sandbox.fc.block.rate_limiter_event_count"
	SandboxFCBlockIOEngineThrottled     HistogramType = "orchestrator.sandbox.fc.block.io_engine_throttled"
	SandboxFCBlockRemainingReqs         HistogramType = "orchestrator.sandbox.fc.block.remaining_reqs"

	SnapshotDiffBytes  HistogramType = "orchestrator.sandbox.snapshot.diff.bytes"
	SnapshotDiffRatio  HistogramType = "orchestrator.sandbox.snapshot.diff.ratio"
	SnapshotTotalBytes HistogramType = "orchestrator.sandbox.snapshot.total.bytes"

	UploadUncompressedBytes HistogramType = "orchestrator.sandbox.upload.uncompressed.bytes"
	UploadCompressedBytes   HistogramType = "orchestrator.sandbox.upload.compressed.bytes"
	UploadCompressionRatio  HistogramType = "orchestrator.sandbox.upload.compression.ratio"
)

type LogProvider

type LogProvider interface {
	log.LoggerProvider
	Shutdown(ctx context.Context) error
}

LogProvider extends log.LoggerProvider with a Shutdown method so the batch processor and exporter are properly flushed on exit.

func NewLogProvider

func NewLogProvider(ctx context.Context, res *resource.Resource, extraOpts ...otlploggrpc.Option) (LogProvider, error)

func NewNoopLogProvider

func NewNoopLogProvider() LogProvider

type ObservableCounterType

type ObservableCounterType string
const (
	ApiOrchestratorSbxCreateSuccess ObservableCounterType = "api.orchestrator.sandbox.create.success"
	ApiOrchestratorSbxCreateFailure ObservableCounterType = "api.orchestrator.sandbox.create.failure"
)

type ObservableUpDownCounterType

type ObservableUpDownCounterType string
const (
	OrchestratorSandboxCountMeterName ObservableUpDownCounterType = "orchestrator.env.sandbox.running"

	ClientProxyServerConnectionsMeterCounterName ObservableUpDownCounterType = "client_proxy.proxy.server.connections.open"
	ClientProxyPoolConnectionsMeterCounterName   ObservableUpDownCounterType = "client_proxy.proxy.pool.connections.open"
	ClientProxyPoolSizeMeterCounterName          ObservableUpDownCounterType = "client_proxy.proxy.pool.size"

	OrchestratorProxyServerConnectionsMeterCounterName ObservableUpDownCounterType = "orchestrator.proxy.server.connections.open"
	OrchestratorProxyPoolConnectionsMeterCounterName   ObservableUpDownCounterType = "orchestrator.proxy.pool.connections.open"
	OrchestratorProxyPoolSizeMeterCounterName          ObservableUpDownCounterType = "orchestrator.proxy.pool.size"

	BuildCounterMeterName       ObservableUpDownCounterType = "api.env.build.running"
	EvictionsRunningCounterName ObservableUpDownCounterType = "api.evictor.evictions.running"

	TCPFirewallActiveConnections ObservableUpDownCounterType = "orchestrator.tcpfirewall.connections.active"

	ApiRedisStoragePublisherQueueDepth ObservableUpDownCounterType = "api.redis_storage.publisher.queue.depth"
)

type Stopwatch

type Stopwatch struct {
	// contains filtered or unexported fields
}

func (Stopwatch) Failure

func (t Stopwatch) Failure(ctx context.Context, total int64, kv ...attribute.KeyValue)

func (Stopwatch) RecordRaw

func (t Stopwatch) RecordRaw(ctx context.Context, total int64, precomputedAttrs metric.MeasurementOption)

RecordRaw records an operation using a precomputed attribute option, it does not include any previous attributes passed at Begin(). Zero-allocation alternative to Success/Failure for hot paths.

func (Stopwatch) Success

func (t Stopwatch) Success(ctx context.Context, total int64, kv ...attribute.KeyValue)

type TimerFactory

type TimerFactory struct {
	// contains filtered or unexported fields
}

func NewTimerFactory

func NewTimerFactory(
	blocksMeter metric.Meter,
	metricName, durationDescription, bytesDescription, counterDescription string,
) (TimerFactory, error)

func (*TimerFactory) Begin

func (f *TimerFactory) Begin(kv ...attribute.KeyValue) *Stopwatch

type UpDownCounterType

type UpDownCounterType string

type ZapFieldToOTELAttributeEncoder

type ZapFieldToOTELAttributeEncoder struct {
	attribute.KeyValue
}

func (*ZapFieldToOTELAttributeEncoder) AddArray

func (*ZapFieldToOTELAttributeEncoder) AddBinary

func (z *ZapFieldToOTELAttributeEncoder) AddBinary(key string, value []byte)

func (*ZapFieldToOTELAttributeEncoder) AddBool

func (z *ZapFieldToOTELAttributeEncoder) AddBool(key string, value bool)

func (*ZapFieldToOTELAttributeEncoder) AddByteString

func (z *ZapFieldToOTELAttributeEncoder) AddByteString(key string, value []byte)

func (*ZapFieldToOTELAttributeEncoder) AddComplex64

func (z *ZapFieldToOTELAttributeEncoder) AddComplex64(key string, value complex64)

func (*ZapFieldToOTELAttributeEncoder) AddComplex128

func (z *ZapFieldToOTELAttributeEncoder) AddComplex128(key string, value complex128)

func (*ZapFieldToOTELAttributeEncoder) AddDuration

func (z *ZapFieldToOTELAttributeEncoder) AddDuration(key string, value time.Duration)

func (*ZapFieldToOTELAttributeEncoder) AddFloat32

func (z *ZapFieldToOTELAttributeEncoder) AddFloat32(key string, value float32)

func (*ZapFieldToOTELAttributeEncoder) AddFloat64

func (z *ZapFieldToOTELAttributeEncoder) AddFloat64(key string, value float64)

func (*ZapFieldToOTELAttributeEncoder) AddInt

func (z *ZapFieldToOTELAttributeEncoder) AddInt(key string, value int)

func (*ZapFieldToOTELAttributeEncoder) AddInt8

func (z *ZapFieldToOTELAttributeEncoder) AddInt8(key string, value int8)

func (*ZapFieldToOTELAttributeEncoder) AddInt16

func (z *ZapFieldToOTELAttributeEncoder) AddInt16(key string, value int16)

func (*ZapFieldToOTELAttributeEncoder) AddInt32

func (z *ZapFieldToOTELAttributeEncoder) AddInt32(key string, value int32)

func (*ZapFieldToOTELAttributeEncoder) AddInt64

func (z *ZapFieldToOTELAttributeEncoder) AddInt64(key string, value int64)

func (*ZapFieldToOTELAttributeEncoder) AddObject

func (*ZapFieldToOTELAttributeEncoder) AddReflected

func (z *ZapFieldToOTELAttributeEncoder) AddReflected(key string, value any) error

func (*ZapFieldToOTELAttributeEncoder) AddString

func (z *ZapFieldToOTELAttributeEncoder) AddString(key, value string)

func (*ZapFieldToOTELAttributeEncoder) AddTime

func (z *ZapFieldToOTELAttributeEncoder) AddTime(key string, value time.Time)

func (*ZapFieldToOTELAttributeEncoder) AddUint

func (z *ZapFieldToOTELAttributeEncoder) AddUint(key string, value uint)

func (*ZapFieldToOTELAttributeEncoder) AddUint8

func (z *ZapFieldToOTELAttributeEncoder) AddUint8(key string, value uint8)

func (*ZapFieldToOTELAttributeEncoder) AddUint16

func (z *ZapFieldToOTELAttributeEncoder) AddUint16(key string, value uint16)

func (*ZapFieldToOTELAttributeEncoder) AddUint32

func (z *ZapFieldToOTELAttributeEncoder) AddUint32(key string, value uint32)

func (*ZapFieldToOTELAttributeEncoder) AddUint64

func (z *ZapFieldToOTELAttributeEncoder) AddUint64(key string, value uint64)

func (*ZapFieldToOTELAttributeEncoder) AddUintptr

func (z *ZapFieldToOTELAttributeEncoder) AddUintptr(key string, value uintptr)

func (*ZapFieldToOTELAttributeEncoder) OpenNamespace

func (z *ZapFieldToOTELAttributeEncoder) OpenNamespace(_ string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL