tracerprovider

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ProcessorBatch  = "batch"
	ProcessorSimple = "simple"

	ErrInvalidSamplePercentage = errors.New("invalid sample percentage")
	ErrInvalidProcessor        = errors.New("invalid processor")
	ErrInvalidToken            = errors.New("invalid token")
)

Functions

This section is empty.

Types

type ExporterGRPC added in v2.1.5

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

type ExporterHTTP added in v2.1.5

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

type Opt

type Opt func(*TracerProvider) error

func WithContext

func WithContext(ctx context.Context) Opt

WithContext sets the context for the tracer provider.

func WithEnvironment added in v2.1.5

func WithEnvironment(environment string) Opt

WithEnvironment sets the deployment environment name attribute for the tracer provider.

func WithGRPCExporter added in v2.1.5

func WithGRPCExporter(endpoint string, credentials credentials.TransportCredentials) Opt

WithGRPCExporter sets gRPC collector endpoint for trace exporter. Endpoint is "host:port" of the collector and you can set transport credentials to "insecure.NewCredentials()" if secure connection is not required.

func WithHTTPExporter added in v2.1.5

func WithHTTPExporter(endpoint string, token string, insecure bool) Opt

WithHTTPExporter sets HTTP exporter endpoint for trace exporter with an authorization token. Endpoint is "host:port" of to the collector and you can set token as "ApiKey <token>" or "Bearer <token>". Set token to empty if not needed. Insecure disables TLS.

func WithIgnore added in v2.1.10

func WithIgnore(ignoreSpans []string) Opt

WithIgnore sets the ignore filter of span names for the tracer provider, e.g. ["/healthz"].

func WithProcessor

func WithProcessor(processorName string) Opt

WithProcessor sets the span processor for the tracer provider. Allowed values are "batch" and "simple", but "simple" should not be used in production.

func WithSamplePercentage

func WithSamplePercentage(percentage int) Opt

WithSamplePercentage sets the percentage of spans to sample. Allowed values are 0-100.

func WithServiceName

func WithServiceName(serviceName string) Opt

WithServiceName sets the service name attribute for the tracer provider.

type SpanFilter added in v2.1.10

type SpanFilter struct {
	trace.SpanProcessor

	// Ignore is the map of dropped span names.
	Ignore map[string]struct{}
}

func (SpanFilter) OnEnd added in v2.1.10

func (f SpanFilter) OnEnd(s trace.ReadOnlySpan)

type TracerProvider

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

func New

func New(opts ...Opt) *TracerProvider

New creates tracer provider module with given options.

Example
package main

import (
	"context"
	"fmt"

	"github.com/elisasre/go-common/v2/service"
	"github.com/elisasre/go-common/v2/service/module/tracerprovider"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	tp := tracerprovider.New(
		tracerprovider.WithSamplePercentage(42),
		tracerprovider.WithGRPCExporter("localhost:4317", insecure.NewCredentials()),
		tracerprovider.WithContext(context.Background()),
		tracerprovider.WithServiceName("test"),
		tracerprovider.WithEnvironment("development"),
		tracerprovider.WithProcessor("processor"),
		tracerprovider.WithIgnore([]string{"/healthz"}),
	)
	err := service.Run(service.Modules{tp})
	if err != nil {
		fmt.Println(err)
	}
}
Output:

failed to initialize module otel.TracerProvider: otel.TracerProvider option error: invalid processor

func (*TracerProvider) Init

func (tp *TracerProvider) Init() error

func (*TracerProvider) Name

func (tp *TracerProvider) Name() string

func (*TracerProvider) Run

func (tp *TracerProvider) Run() error

func (*TracerProvider) Stop

func (tp *TracerProvider) Stop() error

Jump to

Keyboard shortcuts

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