Documentation ¶
Index ¶
- Constants
- Variables
- func BeginNewSpan(ctx context.Context, obs *Observer, name string, options ...BeginSpanOption) (trace.Span, context.Context)
- func BeginNewSpanWithConfig(ctx context.Context, obs *Observer, config BeginSpanConfig) (trace.Span, context.Context)
- func CleanupSpan(span trace.Span)
- func CleanupWithErr(span trace.Span, err error)
- func ContextWithMetricHelper(ctx context.Context, m *MetricHelper) context.Context
- func DatadogLogDerivation(span trace.Span) []zap.Field
- func IsCanaryRequest(ctx context.Context) bool
- func MarkAsCanary(ctx context.Context, isCanary bool) context.Context
- func NewCryptoSafeRandIdGenerator(xrayTimePrefixed bool) sdktrace.IDGenerator
- func NewRecordingObserver(rootLogger *zap.Logger) (*Observer, *Recorder)
- type BeginSpanConfig
- type BeginSpanOption
- func WithCustomLibraryName(name string) BeginSpanOption
- func WithCustomMetricNameBase(base string) BeginSpanOption
- func WithCustomMetricPrefix(prefix string) BeginSpanOption
- func WithGraftedParent(traceId trace.TraceID, spanId trace.SpanID, remote bool) BeginSpanOption
- func WithLink(traceId trace.TraceID, spanId trace.SpanID, remote bool) BeginSpanOption
- func WithLinkedContext(spc trace.SpanContext) BeginSpanOption
- func WithMetrics() BeginSpanOption
- func WithSpanStartOptions(options ...trace.SpanStartOption) BeginSpanOption
- func WithoutLeakCheck() BeginSpanOption
- type MetricHelper
- func GetMetricHelperFromContext(ctx context.Context) *MetricHelper
- func NewMetricContext(ctx context.Context, meter metric.Meter) *MetricHelper
- func NewMetricContextWithPrefix(ctx context.Context, meter metric.Meter, metricPrefix string) *MetricHelper
- func TryGetMetricHelperFromContext(ctx context.Context) *MetricHelper
- func (m *MetricHelper) Add(nm NamedMetric, val float64)
- func (m *MetricHelper) AddCount(nm string, val float64)
- func (m *MetricHelper) Close()
- func (m *MetricHelper) ExportToSpan(span trace.Span)
- func (m *MetricHelper) Init(metrics ...NamedMetric)
- func (m *MetricHelper) InitCounts(metrics ...string)
- type NamedMetric
- type Observer
- func (o *Observer) ContextWithLogger(parent context.Context, name string, fields ...zap.Field) context.Context
- func (o *Observer) MakeMetricHelper(ctx context.Context) *MetricHelper
- func (o *Observer) MakeMetricHelperWithPrefix(ctx context.Context, prefix string) *MetricHelper
- func (o *Observer) MakeTracer() trace.Tracer
- type ObserverOptions
- type PredictableIdGen
- type Record
- type Recorder
Constants ¶
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
const CanaryAttributeName = "canary"
const CanaryBaggageKey = "canary"
Variables ¶
var MetricTagKey = utils.NewMutableContextKey[map[string]string]("metricTags")
Functions ¶
func BeginNewSpan ¶
func BeginNewSpanWithConfig ¶
func CleanupSpan ¶
func CleanupWithErr ¶
func ContextWithMetricHelper ¶
func ContextWithMetricHelper(ctx context.Context, m *MetricHelper) context.Context
func IsCanaryRequest ¶
func NewCryptoSafeRandIdGenerator ¶
func NewCryptoSafeRandIdGenerator(xrayTimePrefixed bool) sdktrace.IDGenerator
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 ¶
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 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 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 ¶
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 (*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 ¶
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