visibility

package
v0.0.0-...-c797b29 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dimensionless string = "1"

	// Time
	UnitDays         string = "d"
	UnitHours        string = "h"
	UnitMinutes      string = "min"
	UnitSeconds      string = "s"
	UnitMilliseconds string = "ms"
	UnitMicroseconds string = "us"
	UnitNanoseconds  string = "ns"

	// Bytes
	UnitKibiBytes string = "KiBy"
	UnitMebiBytes string = "MiBy"
	UnitGibiBytes string = "GiBy"
	UnitTibiBytes string = "TiBy"

	UnitBytes     string = "B"
	UnitKiloBytes string = "KB"
	UnitMegaBytes string = "MB"
	UnitGigaBytes string = "GB"
	UnitTeraBytes string = "TB"

	// Network Speed
	UnitKibiBytesSec string = "KiBy/s"
	UnitMebiBytesSec string = "MiBy/s"
	UnitGibiBytesSec string = "GiBy/s"
	UnitTibiBytesSec string = "TiBy/s"

	UnitBytesSec     string = "B/s"
	UnitKiloBytesSec string = "KB/s"
	UnitMegaBytesSec string = "MB/s"
	UnitGigaBytesSec string = "GB/s"
	UnitTeraBytesSec string = "TB/s"

	// SI
	UnitMetersPerSec string = "m/s"
	UnitMeters       string = "m"
	UnitVolts        string = "V"
	UnitAmperes      string = "A"
	UnitJoules       string = "J"
	UnitWatts        string = "W"
	UnitGrams        string = "g"

	// Misc
	UnitCelsius string = "Cel"
	UnitHertz   string = "Hz"
	UnitPercent string = "%"
	UnitDollars string = "$"
)

OTEL only defines these metrics: const (

Dimensionless string = "1"
Bytes         Unit = "By"
Milliseconds  Unit = "ms"

) We add some additional units that are not defined in OTEL headers, but are supported by Prometheus and other collectors. For Prometheus see: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/10028

View Source
const CanaryAttributeName = "canary"
View Source
const CanaryBaggageKey = "canary"

Variables

View Source
var MetricTagKey = utils.NewMutableContextKey[map[string]string]("metricTags")

Functions

func BeginNewSpan

func BeginNewSpan(ctx context.Context, obs *Observer, name string,
	options ...BeginSpanOption) (trace.Span, context.Context)

func BeginNewSpanWithConfig

func BeginNewSpanWithConfig(ctx context.Context, obs *Observer,
	config BeginSpanConfig) (trace.Span, context.Context)

func CleanupSpan

func CleanupSpan(span trace.Span)

func CleanupWithErr

func CleanupWithErr(span trace.Span, err error)

func ContextWithMetricHelper

func ContextWithMetricHelper(ctx context.Context, m *MetricHelper) context.Context

func DatadogLogDerivation

func DatadogLogDerivation(span trace.Span) []zap.Field

func IsCanaryRequest

func IsCanaryRequest(ctx context.Context) bool

func MarkAsCanary

func MarkAsCanary(ctx context.Context, isCanary bool) context.Context

func NewCryptoSafeRandIdGenerator

func NewCryptoSafeRandIdGenerator(xrayTimePrefixed bool) sdktrace.IDGenerator

func NewRecordingObserver

func NewRecordingObserver(rootLogger *zap.Logger) (*Observer, *Recorder)

Types

type BeginSpanConfig

type BeginSpanConfig struct {
	SpanName         string
	LibraryName      string
	StartSpanOptions []trace.SpanStartOption

	AddMetrics     bool
	MetricPrefix   string
	MetricNameBase string

	WithoutLeakCheck bool

	GraftedParent *trace.SpanContext
}

BeginSpanConfig is used for the span configuration

type BeginSpanOption

type BeginSpanOption func(cfg *BeginSpanConfig)

BeginSpanOption is used to customize the span options

func WithCustomLibraryName

func WithCustomLibraryName(name string) BeginSpanOption

WithCustomLibraryName overrides the "instrumentation library name". Instrumented Library and Instrumentation Library may be the same library if it has built-in OpenTelemetry instrumentation.

The inspiration of the OpenTelemetry project is to make every library and application observable out-of-the-box by having them call OpenTelemetry API directly. However, many libraries will not have such integration, and as such there is a need for a separate library which would inject such calls, using mechanisms such as wrapping interfaces, subscribing to library-specific callbacks, or translating existing telemetry into the OpenTelemetry model.

A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.

An instrumentation library should be named to follow any naming conventions of the instrumented library (e.g. middleware for a web framework).

func WithCustomMetricNameBase

func WithCustomMetricNameBase(base string) BeginSpanOption

WithCustomMetricNameBase overrides the span name for the success/error/fault metrics

func WithCustomMetricPrefix

func WithCustomMetricPrefix(prefix string) BeginSpanOption

WithCustomMetricPrefix customizes the span metrics prefix

func WithGraftedParent

func WithGraftedParent(traceId trace.TraceID, spanId trace.SpanID, remote bool) BeginSpanOption

WithGraftedParent sets the parent of the span, overriding any existing parents that might be passed from the context. This is useful for spans that are created asynchronously, even after their parent request may be completed.

func WithLink(traceId trace.TraceID, spanId trace.SpanID, remote bool) BeginSpanOption

WithLink see WithLinkedContext

func WithLinkedContext

func WithLinkedContext(spc trace.SpanContext) BeginSpanOption

WithLinkedContext adds the specified trace.SpanContext as a span link. It can be used to link untrusted remote spans.

func WithMetrics

func WithMetrics() BeginSpanOption

WithMetrics turns on the automatic metrics for the span. It will create a new metric context and submit the following metrics: <CustomMetricsPrefix><SpanName>Success=1 in case the span succeeds <CustomMetricsPrefix><SpanName>Error=1 in case the span fails <CustomMetricsPrefix><SpanName>Fault=1 in case the span panics

func WithSpanStartOptions

func WithSpanStartOptions(options ...trace.SpanStartOption) BeginSpanOption

WithSpanStartOptions allows customizing the span start options

func WithoutLeakCheck

func WithoutLeakCheck() BeginSpanOption

WithoutLeakCheck disables the span leak checker. Leak checker imposes a slight overhead that might be inappropriate for very tight inner loops (but then, why do you want to run them as separate spans?)

type MetricHelper

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

func GetMetricHelperFromContext

func GetMetricHelperFromContext(ctx context.Context) *MetricHelper

func NewMetricContext

func NewMetricContext(ctx context.Context, meter metric.Meter) *MetricHelper

func NewMetricContextWithPrefix

func NewMetricContextWithPrefix(ctx context.Context, meter metric.Meter, metricPrefix string) *MetricHelper

func TryGetMetricHelperFromContext

func TryGetMetricHelperFromContext(ctx context.Context) *MetricHelper

func (*MetricHelper) Add

func (m *MetricHelper) Add(nm NamedMetric, val float64)

func (*MetricHelper) AddCount

func (m *MetricHelper) AddCount(nm string, val float64)

func (*MetricHelper) Close

func (m *MetricHelper) Close()

Close submits all the remaining zero-valued metrics

func (*MetricHelper) ExportToSpan

func (m *MetricHelper) ExportToSpan(span trace.Span)

func (*MetricHelper) Init

func (m *MetricHelper) Init(metrics ...NamedMetric)

func (*MetricHelper) InitCounts

func (m *MetricHelper) InitCounts(metrics ...string)

type NamedMetric

type NamedMetric struct {
	Name string
	Unit string
}

func Named

func Named(nm string, un string) NamedMetric

type Observer

type Observer struct {
	Logger *zap.Logger

	// The name of the application or library that is being traced.
	// E.g. if you are instrumenting YourCoolApp then set this to "YourCoolApp"
	DefaultLibraryName string
	Resource           *resource.Resource

	TraceProvider   trace.TracerProvider
	MeterController metric.MeterProvider

	LogFieldsForSpan func(span trace.Span) []zap.Field

	Shutdown func(ctx context.Context)
}

func NewObserver

func NewObserver(rootLogger *zap.Logger, opts ObserverOptions) (*Observer, error)

func (*Observer) ContextWithLogger

func (o *Observer) ContextWithLogger(parent context.Context, name string, fields ...zap.Field) context.Context

func (*Observer) MakeMetricHelper

func (o *Observer) MakeMetricHelper(ctx context.Context) *MetricHelper

func (*Observer) MakeMetricHelperWithPrefix

func (o *Observer) MakeMetricHelperWithPrefix(ctx context.Context, prefix string) *MetricHelper

func (*Observer) MakeTracer

func (o *Observer) MakeTracer() trace.Tracer

type ObserverOptions

type ObserverOptions struct {
	MetricsEndpoint string // localhost:4317 is the default
	TracingEndpoint string // localhost:4317 is the default

	// The name of the application or library that is being traced.
	// E.g. if you are instrumenting YourCoolApp then set this to "YourCoolApp"
	LibraryName string
	Resource    *resource.Resource

	// The ID generator for the spans, can be customized to produce predictable IDs
	IdGenerator sdktrace.IDGenerator
}

func NewBlindObserverOptions

func NewBlindObserverOptions() ObserverOptions

func NewDefaultObserverOptions

func NewDefaultObserverOptions(libraryName, serviceName, envName string) (ObserverOptions, error)

type PredictableIdGen

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

func NewPredictableIdGen

func NewPredictableIdGen(seed int64) *PredictableIdGen

func (*PredictableIdGen) NewIDs

NewIDs returns a non-zero trace ID and a non-zero span ID from the pre-seeded pseudorandom source

func (*PredictableIdGen) NewSpanID

func (g *PredictableIdGen) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID

NewSpanID returns a non-zero span ID from the pre-seeded pseudorandom source

type Record

type Record struct {
	Metrics map[string]float64
	Spans   []trace.ReadOnlySpan
}

type Recorder

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

func (*Recorder) Get

func (r *Recorder) Get() Record

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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