Source File
noop.go
Belonging Package
go.opentelemetry.io/otel/trace/noop
// Copyright The OpenTelemetry Authors// SPDX-License-Identifier: Apache-2.0// Package noop provides an implementation of the OpenTelemetry trace API that// produces no telemetry and minimizes used computation resources.//// Using this package to implement the OpenTelemetry trace API will effectively// disable OpenTelemetry.//// This implementation can be embedded in other implementations of the// OpenTelemetry trace API. Doing so will mean the implementation defaults to// no operation for methods it does not implement.package noop // import "go.opentelemetry.io/otel/trace/noop"import ()var (// Compile-time check this implements the OpenTelemetry API._ trace.TracerProvider = TracerProvider{}_ trace.Tracer = Tracer{}_ trace.Span = Span{})// TracerProvider is an OpenTelemetry No-Op TracerProvider.type TracerProvider struct{ embedded.TracerProvider }// NewTracerProvider returns a TracerProvider that does not record any telemetry.func () TracerProvider {return TracerProvider{}}// Tracer returns an OpenTelemetry Tracer that does not record any telemetry.func (TracerProvider) (string, ...trace.TracerOption) trace.Tracer {return Tracer{}}// Tracer is an OpenTelemetry No-Op Tracer.type Tracer struct{ embedded.Tracer }// Start creates a span. The created span will be set in a child context of ctx// and returned with the span.//// If ctx contains a span context, the returned span will also contain that// span context. If the span context in ctx is for a non-recording span, that// span instance will be returned directly.func (Tracer) ( context.Context, string, ...trace.SpanStartOption) (context.Context, trace.Span) {:= trace.SpanFromContext()// If the parent context contains a non-zero span context, that span// context needs to be returned as a non-recording span// (https://github.com/open-telemetry/opentelemetry-specification/blob/3a1dde966a4ce87cce5adf464359fe369741bbea/specification/trace/api.md#behavior-of-the-api-in-the-absence-of-an-installed-sdk).var trace.SpanContextif := .SpanContext(); !.Equal() {if !.IsRecording() {// If the span is not recording return it directly.return ,}// Otherwise, return the span context needs in a non-recording span.= Span{sc: }} else {// No parent, return a No-Op span with an empty span context.= noopSpanInstance}return trace.ContextWithSpan(, ),}var noopSpanInstance trace.Span = Span{}// Span is an OpenTelemetry No-Op Span.type Span struct {embedded.Spansc trace.SpanContext}// SpanContext returns an empty span context.func ( Span) () trace.SpanContext { return .sc }// IsRecording always returns false.func (Span) () bool { return false }// SetStatus does nothing.func (Span) (codes.Code, string) {}// SetAttributes does nothing.func (Span) (...attribute.KeyValue) {}// End does nothing.func (Span) (...trace.SpanEndOption) {}// RecordError does nothing.func (Span) (error, ...trace.EventOption) {}// AddEvent does nothing.func (Span) (string, ...trace.EventOption) {}// AddLink does nothing.func (Span) (trace.Link) {}// SetName does nothing.func (Span) (string) {}// TracerProvider returns a No-Op TracerProvider.func (Span) () trace.TracerProvider { return TracerProvider{} }
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |