observe

package module
v0.0.0-...-4f1734a Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Error LogLevel = 1
	Warn           = 2
	Info           = 3
	Debug          = 4
)

Variables

This section is empty.

Functions

func AddOtelKeyValueInt64

func AddOtelKeyValueInt64(kvs ...*common.KeyValue) *common.KeyValue

func GetOtelAttrFromSpan

func GetOtelAttrFromSpan(attr string, span *trace.Span) (int, *common.KeyValue)

func NewOtelKeyValueInt64

func NewOtelKeyValueInt64(key string, value int64) *common.KeyValue

func NewOtelKeyValueString

func NewOtelKeyValueString(key string, value string) *common.KeyValue

func NewOtelSpan

func NewOtelSpan(traceId string, parentId []byte, name string, start, end time.Time) *trace.Span

Types

type Adapter

type Adapter interface {
	Start(context.Context)
	Stop(wait bool)
	HandleTraceEvent(e TraceEvent)
}

The primary interface that every Adapter needs to follow Start() and Stop() can just call the implementations on AdapterBase or provide some custom logic. HandleTraceEvent is called after an invocation of a wasm module is done and all events are collected.

type AdapterBase

type AdapterBase struct {
	TraceEvents chan TraceEvent
	// contains filtered or unexported fields
}

Shared implementation for all Adapters

func NewAdapterBase

func NewAdapterBase(batchSize int, flushPeriod time.Duration) AdapterBase

func (*AdapterBase) HandleTraceEvent

func (b *AdapterBase) HandleTraceEvent(te TraceEvent)

func (*AdapterBase) MakeOtelCallSpans

func (b *AdapterBase) MakeOtelCallSpans(event CallEvent, parentId []byte, traceId string) []*trace.Span

MakeOtelCallSpans recursively constructs call spans in open telemetry format

func (*AdapterBase) NewTraceCtx

func (a *AdapterBase) NewTraceCtx(ctx context.Context, r wazero.Runtime, wasm []byte, opts *Options) (*TraceCtx, error)

func (*AdapterBase) SetFlusher

func (b *AdapterBase) SetFlusher(f Flusher)

func (*AdapterBase) Start

func (b *AdapterBase) Start(ctx context.Context, a Adapter)

func (*AdapterBase) Stop

func (b *AdapterBase) Stop(wait bool)

Stops the adapter and waits for all flushes to complete. Set wait parameter to false if you don't want to wait

type CallEvent

type CallEvent struct {
	Raw      []RawEvent
	Time     time.Time
	Duration time.Duration
	// contains filtered or unexported fields
}

func (CallEvent) FunctionIndex

func (e CallEvent) FunctionIndex() uint32

func (CallEvent) FunctionName

func (e CallEvent) FunctionName() string

func (CallEvent) RawEvents

func (e CallEvent) RawEvents() []RawEvent

func (*CallEvent) Stop

func (e *CallEvent) Stop(at time.Time)

func (CallEvent) Within

func (e CallEvent) Within() []Event

type CustomEvent

type CustomEvent struct {
	Time     time.Time
	Name     string
	Metadata map[string]interface{}
}

func NewCustomEvent

func NewCustomEvent(name string) CustomEvent

func (CustomEvent) RawEvents

func (e CustomEvent) RawEvents() []RawEvent

type Event

type Event interface {
	RawEvents() []RawEvent
}

type EventBucket

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

EventBucket is a bucket for outgoing TraceEvents. It only schedules flushes when the bucket goes from empty to 1 item. At most the latency to flush the bucket will be flushPeriod. It will also flush the TraceEvents in batches according to batch size

func NewEventBucket

func NewEventBucket(batchSize int, flushPeriod time.Duration) *EventBucket

NewEventBucket creates an EventBucket

func (*EventBucket) Wait

func (b *EventBucket) Wait()

Wait will block until all pending flushes are done

type EventKind

type EventKind int
const (
	Call EventKind = iota
	MemoryGrow
	Custom
	Metric
	SpanTags
	Log
)

type Flusher

type Flusher interface {
	Flush(events []TraceEvent) error
}

type LogEvent

type LogEvent struct {
	Time    time.Time
	Message string
	Level   LogLevel
}

func (LogEvent) RawEvents

func (e LogEvent) RawEvents() []RawEvent

type LogLevel

type LogLevel uint

type MemoryGrowEvent

type MemoryGrowEvent struct {
	Raw  RawEvent
	Time time.Time
}

func (MemoryGrowEvent) FunctionIndex

func (e MemoryGrowEvent) FunctionIndex() uint32

func (MemoryGrowEvent) FunctionName

func (e MemoryGrowEvent) FunctionName() string

func (MemoryGrowEvent) MemoryGrowAmount

func (e MemoryGrowEvent) MemoryGrowAmount() uint32

func (MemoryGrowEvent) RawEvents

func (e MemoryGrowEvent) RawEvents() []RawEvent

type MetricEvent

type MetricEvent struct {
	Time    time.Time
	Format  MetricFormat
	Message string
}

func (MetricEvent) RawEvents

func (e MetricEvent) RawEvents() []RawEvent

type MetricFormat

type MetricFormat uint
const (
	StatsdFormat MetricFormat = 1
)

type Options

type Options struct {
	SpanFilter        *SpanFilter
	ChannelBufferSize int
}

Specify options to change what or how the adapter receives ObserveEvents

func NewDefaultOptions

func NewDefaultOptions() *Options

Create a default configuration

type OtelTrace

type OtelTrace struct {
	TraceId    string
	TracesData *trace.TracesData
}

func NewOtelTrace

func NewOtelTrace(traceId string, serviceName string, spans []*trace.Span) *OtelTrace

func (*OtelTrace) SetMetadata

func (t *OtelTrace) SetMetadata(te *TraceEvent, meta map[string]string)

type RawEvent

type RawEvent struct {
	Kind             RawEventKind
	Stack            []experimental.InternalFunction
	FunctionIndex    uint32
	FunctionName     string
	MemoryGrowAmount uint32
	Time             time.Time
	Duration         time.Duration
}

Represents the raw event in our Observe form. Events are transformed into vendor specific formats in the Adapters.

type RawEventKind

type RawEventKind int
const (
	RawEnter RawEventKind = iota
	RawExit
	RawMemoryGrow
	RawMetric
	RawSpanTags
	RawLog
	RawUnknownEvent
)

type SpanFilter

type SpanFilter struct {
	MinDuration time.Duration
}

Definition of how to filter our Spans to reduce noise

type SpanTagsEvent

type SpanTagsEvent struct {
	Raw  RawEvent
	Time time.Time
	Tags []string
}

func (SpanTagsEvent) RawEvents

func (e SpanTagsEvent) RawEvents() []RawEvent

type TelemetryId

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

This is a shared type for a span or trace id. It's represented by 2 uint64s and can be transformed to different string or int representations where needed.

func NewSpanId

func NewSpanId() TelemetryId

Create a new span id

func NewTraceId

func NewTraceId() TelemetryId

Create a new trace id

func (*TelemetryId) FromBytes

func (t *TelemetryId) FromBytes(id []byte) error

func (*TelemetryId) FromString

func (t *TelemetryId) FromString(id string) error

func (TelemetryId) Lsb

func (id TelemetryId) Lsb() uint64

func (TelemetryId) Msb

func (id TelemetryId) Msb() uint64

func (TelemetryId) ToHex16

func (t TelemetryId) ToHex16() string

Encode this id into a 16 byte hex (32 chars) Uses both 16 byte uint64 values

func (TelemetryId) ToHex8

func (t TelemetryId) ToHex8() string

Encode this id into an 8 byte hex (16 chars) Just uses the least significant of the 16 bytes

func (TelemetryId) ToUint64

func (t TelemetryId) ToUint64() uint64

Some adapters may need a raw representation

type TraceCtx

type TraceCtx struct {
	Options *Options
	// contains filtered or unexported fields
}

TraceCtx holds the context for a trace, or wasm module invocation. It collects holds a channel to the Adapter and from the wazero Listener It will collect events throughout the invocation of the function. Calling Finish() will then submit those events to the Adapter to be processed and sent

func (*TraceCtx) Abort

Null implementation of the Abort() method to satisfy the FunctionListener interface.

func (*TraceCtx) After

Null implementation of the After() method to satisfy the FunctionListener interface.

func (*TraceCtx) Before

func (t *TraceCtx) Before(ctx context.Context, _ api.Module, def api.FunctionDefinition, inputs []uint64, stack experimental.StackIterator)

Implements the Before() method to satisfy the FunctionListener interface. This takes events from the wazero runtime and sends them to the `raw` channel on the TraceCtx.

func (*TraceCtx) Finish

func (t *TraceCtx) Finish()

Finish() will stop the trace and send the TraceEvent payload to the adapter

func (*TraceCtx) Metadata

func (t *TraceCtx) Metadata(metadata interface{})

func (*TraceCtx) NewFunctionListener

func (t *TraceCtx) NewFunctionListener(_ api.FunctionDefinition) experimental.FunctionListener

Implements the NewFunctionListener() method to satisfy the FunctionListener interface

func (*TraceCtx) NewListener

Implements the NewListener() method to satisfy the FunctionListener interface

func (*TraceCtx) SetTraceId

func (t *TraceCtx) SetTraceId(id string) error

type TraceEvent

type TraceEvent struct {
	Events      []Event
	TelemetryId TelemetryId
	AdapterMeta interface{}
}

The payload that contains all the Events from a single wasm module invocation

Jump to

Keyboard shortcuts

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