utils

package
v1.19.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StaticPaths = map[string]bool{
	"/dapr/config":    true,
	"/dapr/metrics":   true,
	"/dapr/subscribe": true,
	"/healthz":        true,
}
View Source
var ValidHTTPVerbs = map[string]bool{
	"GET":     true,
	"PUT":     true,
	"POST":    true,
	"PATCH":   true,
	"DELETE":  true,
	"HEAD":    true,
	"OPTIONS": true,
	"CONNECT": true,
	"TRACE":   true,
}

Functions

func AddNewTagKey

func AddNewTagKey(views []*view.View, key *tag.Key) []*view.View

AddNewTagKey adds new tag keys to existing view.

func AddSpanToRequest added in v1.12.0

func AddSpanToRequest(r *http.Request, span trace.Span)

AddSpanToRequest sets span into a request context.

func BinaryFromSpanContext added in v1.9.0

func BinaryFromSpanContext(sc trace.SpanContext) []byte

BinaryFromSpanContext returns the binary format representation of a SpanContext.

If sc is the zero value, Binary returns nil.

func CreateRulesMap added in v1.10.0

func CreateRulesMap(rules []config.MetricsRule) error

CreateRulesMap generates a fast lookup map for metrics regex.

func GetTraceSamplingRate added in v0.7.0

func GetTraceSamplingRate(rate string) float64

GetTraceSamplingRate parses the given rate and returns the parsed rate.

func IsTracingEnabled added in v0.8.0

func IsTracingEnabled(rate string) bool

IsTracingEnabled parses the given rate and returns false if sampling rate is explicitly set 0.

func NewMeasureView

func NewMeasureView(measure stats.Measure, keys []tag.Key, aggregation *view.Aggregation) *view.View

NewMeasureView creates opencensus View instance using stats.Measure.

func NormalizeTagValue

func NormalizeTagValue(name string, key tag.Key, value string) string

NormalizeTagValue applies the configured metric rules (regex label rewrites) for the measure and tag key to value, exactly as the per-record WithTags path does.

func SpanContextFromBinary added in v1.9.0

func SpanContextFromBinary(b []byte) (sc trace.SpanContext, ok bool)

SpanContextFromBinary returns the SpanContext represented by b.

If b has an unsupported version ID or contains no TraceID, SpanContextFromBinary returns with ok==false.

func SpanFromContext added in v0.8.0

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext returns the Span stored in a context, or nil or trace.noopSpan{} if there isn't one.

func WithTags

func WithTags(name string, opts ...any) []tag.Mutator

WithTags converts tag key and value pairs to tag.Mutator array. WithTags(key1, value1, key2, value2) returns []tag.Mutator{tag.Upsert(key1, value1), tag.Upsert(key2, value2)}.

Types

type CachedFloat64Recorder

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

CachedFloat64Recorder records float64 measurements (histograms, gauges) through cached tag maps: one small slice allocation per record.

func NewCachedFloat64Recorder

func NewCachedFloat64Recorder(meter stats.Recorder, measure *stats.Float64Measure, base ...any) *CachedFloat64Recorder

NewCachedFloat64Recorder builds the recorder; base holds the constant tag pairs.

func (*CachedFloat64Recorder) Record0

func (c *CachedFloat64Recorder) Record0(v float64)

Record0 records with only the base tags.

func (*CachedFloat64Recorder) Record1

func (c *CachedFloat64Recorder) Record1(k tag.Key, tv string, v float64)

Record1 records with one varying tag.

func (*CachedFloat64Recorder) Record2

func (c *CachedFloat64Recorder) Record2(k1 tag.Key, v1 string, k2 tag.Key, v2 string, v float64)

Record2 records with two varying tags.

type CachedInt64Counter

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

CachedInt64Counter records a constant-increment counter through cached tag maps: zero allocations on the cached path.

func NewCachedInt64Counter

func NewCachedInt64Counter(meter stats.Recorder, measure *stats.Int64Measure, base ...any) *CachedInt64Counter

NewCachedInt64Counter builds the counter recorder; base holds the constant tag pairs.

func (*CachedInt64Counter) Record1

func (c *CachedInt64Counter) Record1(k tag.Key, v string)

Record1 records +1 with one varying tag.

func (*CachedInt64Counter) Record2

func (c *CachedInt64Counter) Record2(k1 tag.Key, v1 string, k2 tag.Key, v2 string)

Record2 records +1 with two varying tags.

func (*CachedInt64Counter) Zero1

func (c *CachedInt64Counter) Zero1(k tag.Key, v string)

Zero1 records 0 with one varying tag, pre-registering the series so it is exported at value 0 before its first increment. Only meaningful for views with a Sum aggregation: under Count every record, including a zero, counts.

type CachedInt64Recorder

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

CachedInt64Recorder records variable int64 measurements (byte sizes) through cached tag maps: one small slice allocation per record.

func NewCachedInt64Recorder

func NewCachedInt64Recorder(meter stats.Recorder, measure *stats.Int64Measure, base ...any) *CachedInt64Recorder

NewCachedInt64Recorder builds the recorder; base holds the constant tag pairs.

func (*CachedInt64Recorder) Record1

func (c *CachedInt64Recorder) Record1(k tag.Key, tv string, v int64)

Record1 records with one varying tag.

type CachedTagMaps

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

CachedTagMaps caches fully-built *tag.Map values keyed by their varying tag values, so hot-path metric records can call stats.Recorder.Record directly instead of paying the RecordWithOptions chain (mutator closures, option closures, a fresh tag map and value context) on every record: ~18-20 allocations per record down to zero for cached counters.

Base tags (typically app_id and namespace, constant for the process) are applied once per rules generation. Cache keys are the RULE-NORMALIZED values, so the cache's cardinality mirrors the exported view's even when a cardinality rule collapses many raw values into one label, and a rules installation after construction rebuilds the base tags and drops stale entries. Intended for low-cardinality exported discriminators (statuses, kinds, bounded method sets).

func NewCachedTagMaps

func NewCachedTagMaps(measureName string, base ...any) *CachedTagMaps

NewCachedTagMaps builds the cache with constant base tag pairs (key1, value1, key2, value2, ...).

func (*CachedTagMaps) Base

func (c *CachedTagMaps) Base() *tag.Map

Base returns the tag map holding only the constant base tags, for measures with no varying discriminator.

func (*CachedTagMaps) Get1

func (c *CachedTagMaps) Get1(k tag.Key, v string) *tag.Map

Get1 returns the cached tag map for one varying tag. Zero allocations on the cached path.

func (*CachedTagMaps) Get2

func (c *CachedTagMaps) Get2(k1 tag.Key, v1 string, k2 tag.Key, v2 string) *tag.Map

Get2 returns the cached tag map for two varying tags. The composite key concatenation allocates one small string per call; use nested caches if even that matters.

type NullExporter added in v1.11.0

type NullExporter struct{}

NullExporter implements an open telemetry span exporter that discards all telemetry.

func NewNullExporter added in v1.11.0

func NewNullExporter() *NullExporter

NewNullExporter returns a NullExporter

func (*NullExporter) ExportSpans added in v1.11.0

func (e *NullExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

ExportSpans implements the open telemetry span exporter interface.

func (*NullExporter) Shutdown added in v1.11.0

func (e *NullExporter) Shutdown(ctx context.Context) error

Shutdown implements the open telemetry span exporter interface.

type StdoutExporter added in v0.10.0

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

StdoutExporter implements an open telemetry span exporter that writes to stdout.

func NewStdOutExporter added in v1.9.0

func NewStdOutExporter() *StdoutExporter

NewStdOutExporter returns a StdOutExporter

func (*StdoutExporter) ExportSpans added in v1.9.0

func (e *StdoutExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error

ExportSpans implements the open telemetry span exporter interface.

func (*StdoutExporter) Shutdown added in v1.9.0

func (e *StdoutExporter) Shutdown(ctx context.Context) error

Shutdown implements the open telemetry span exporter interface.

Jump to

Keyboard shortcuts

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