Documentation ¶
Index ¶
- Constants
- func ContextWithSpan(ctx context.Context, span Span) context.Context
- func NewHTTPHandler(name string, handler http.Handler, tp Provider, attr ...Attribute) http.Handler
- func NewHTTPTransport(base http.RoundTripper) http.RoundTripper
- type Attribute
- type Logger
- type Option
- func WithConfig(cfg *config.OpenTelemetry) Option
- func WithContainerDetector() Option
- func WithContext(ctx context.Context) Option
- func WithCustomResourceAttributes(attrs ...Attribute) Option
- func WithHostDetector() Option
- func WithLogger(logger Logger) Option
- func WithProcessDetector() Option
- func WithServiceID(id string) Option
- func WithServiceVersion(version string) Option
- type Provider
- type Span
- type Tracer
Constants ¶
const ( SPAN_STATUS_ERROR = codes.Error SPAN_STATUS_UNSET = codes.Unset SPAN_STATUS_OK = codes.Ok )
const ( NOOP_PROVIDER = "noop" OTEL_PROVIDER = "otel" )
Variables ¶
This section is empty.
Functions ¶
func ContextWithSpan ¶ added in v0.0.12
ContextWithSpan returns a child context from ctx with span embedded
func NewHTTPHandler ¶ added in v0.0.4
NewHTTPHandler wraps the provided http.Handler with one that starts a span and injects the span context into the outbound request headers. You need to initialize the TracerProvider first since it utilizes the underlying TracerProvider and propagators. It also utilizes a spanNameFormatter to format the span name r.Method + " " + r.URL.Path.
func NewHTTPTransport ¶ added in v0.0.4
func NewHTTPTransport(base http.RoundTripper) http.RoundTripper
NewHTTPTransport wraps the provided http.RoundTripper with one that starts a span and injects the span context into the outbound request headers.
Types ¶
type Attribute ¶ added in v0.0.8
func NewAttribute ¶ added in v0.0.8
NewAttribute creates a new attribute.KeyValue pair based on the provided key and value. The function supports multiple types for the value parameter including basic types (string, bool, int, int64, float64), their pointer types, slices of basic types, and any type implementing the fmt.Stringer interface.
Usage:
attr := trace.NewAttribute("key1", "value1") fmt.Println(attr) // Output: "key1":"value1"
type Logger ¶ added in v0.0.2
type Logger interface { Info(args ...interface{}) Error(args ...interface{}) }
Logger represents the internal library logger used for error and info messages
type Option ¶ added in v0.0.2
type Option interface {
// contains filtered or unexported methods
}
func WithConfig ¶ added in v0.0.2
func WithConfig(cfg *config.OpenTelemetry) Option
WithConfig sets the configuration options for the tracer provider
Example
config := &config.OpenTelemetry{ Enabled: true, Exporter: "grpc", Endpoint: "localhost:4317", } provider, err := trace.NewProvider(trace.WithConfig(config)) if err != nil { panic(err) }
func WithContainerDetector ¶ added in v0.0.11
func WithContainerDetector() Option
WithContainerDetector adds attributes from the container to the configured resource.
Example
provider, err := trace.NewProvider(trace.WithContainerDetector()) if err != nil { panic(err) }
func WithContext ¶ added in v0.0.2
WithContext sets the context for the tracer provider
Example
ctx := context.Background() provider, err := trace.NewProvider(trace.WithContext(ctx)) if err != nil { panic(err) }
func WithCustomResourceAttributes ¶ added in v0.0.14
WithCustomResourceAttributes adds custom attributes to the configured resource.
Example
attrs := []trace.Attribute{trace.NewAttribute("key", "value")} provider, err := trace.NewProvider(trace.WithCustomResourceAttributes(attrs...)) if err != nil { panic(err) }
func WithHostDetector ¶ added in v0.0.11
func WithHostDetector() Option
WithHostDetector adds attributes from the host to the configured resource.
Example
provider, err := trace.NewProvider(trace.WithHostDetector()) if err != nil { panic(err) }
func WithLogger ¶ added in v0.0.2
WithLogger sets the logger for the tracer provider This is used to log errors and info messages for underlying operations
Example
logger := logrus.New().WithField("component", "trace") provider, err := trace.NewProvider(trace.WithLogger(logger)) if err != nil { panic(err) }
func WithProcessDetector ¶ added in v0.0.11
func WithProcessDetector() Option
func WithServiceID ¶ added in v0.0.11
WithServiceID sets the resource service.id for the tracer provider This is useful to identify service instance on the trace resource.
Example
provider, err := trace.NewProvider(trace.WithServiceID("instance-id")) if err != nil { panic(err) }
func WithServiceVersion ¶ added in v0.0.11
WithServiceVersion sets the resource service.version for the tracer provider This is useful to identify service version on the trace resource.
Example
provider, err := trace.NewProvider(trace.WithServiceVersion("v4.0.5")) if err != nil { panic(err) }
type Provider ¶
type Provider interface { // Shutdown execute the underlying exporter shutdown function Shutdown(context.Context) error // Tracer returns a tracer with pre-configured name. It's used to create spans. Tracer() Tracer // Type returns the type of the provider, it can be either "noop" or "otel" Type() string }
Provider is the interface that wraps the basic methods of a tracer provider. If missconfigured or disabled, the provider will return a noop tracer
func NewProvider ¶
NewProvider creates a new tracer provider with the given options The tracer provider is responsible for creating spans and sending them to the exporter Example provider, err := trace.NewProvider( trace.WithContext(context.Background()), trace.WithConfig(&config.OpenTelemetry{ Enabled: true, Exporter: "grpc", Endpoint: "localhost:4317", }), trace.WithLogger(logrus.New().WithField("component", "tyk")), ) if err != nil { panic(err) }
type Span ¶ added in v0.0.6
func NewSpanFromContext ¶ added in v0.0.6
NewSpanFromContext creates a new span from the given context. If the context already has a span attached to it, the new span will be a child of the existing span. If the context does not have a span attached to it, the new span will be a root span. The tracer name is used to identify the tracer to be used to create the span. If the tracer name is not provided, the default 'tyk' tracer name will be used. Example:
spanCtx, span := trace.NewSpanFromContext(ctx, "my-tracer", "my-span") defer span.End()
func SpanFromContext ¶ added in v0.0.4
SpanFromContext returns the span attached to the given context. If the context does not have a span attached to it, a no-op span will be returned. Example:
span := trace.SpanFromContext(ctx) defer span.End()