tracing

package
v0.0.0-...-3736fb9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package tracing provides functions for starting and stopping our Open Telemetry tracing. This package is intended to be used from main and is simple to use. We offer a few choices on where traces export to. Here is an example to trace to stderr for all requests:

func main() {
	ctx := context.Background()
	// Set us up to always sample. The "trace" package is: "petstore/server/SearchPets/latency"
	tracing.Sampler.Switch(trace.AlwaysSample())
	// Start our tracing and pass the empty Stderr tracing arguments.
	// Stderr{} has no required fields.
	stop, err := tracing.Start(ctx, tracing.Stderr{})
	if err != nil {
		log.Fatalf("problem starting telemetry: %s", err)
	}

	// Stop kills our exporter when main() ends.
	defer stop()
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// Tracer is the tracer initialized by Start().
	Tracer trace.Tracer // *sdktrace.TracerProvider //otlptrace.Exporter
	// Sampler is our *sampler.Sampler used by the Tracer.
	Sampler *sampler.Sampler
)

Tracer is the tracer initialized by Start().

Functions

This section is empty.

Types

type Exporter

type Exporter interface {
	// contains filtered or unexported methods
}

Exporter represents the exporter to send telemetry to.

type File

type File struct {
	// Path is the path to the file.
	Path string
}

File exports trace data to a file. If the file exists, it is overwritten.

type OTELGRPC

type OTELGRPC struct {
	// Addr is the local address to export on.
	Addr string
}

OTELGRPC represents exporting to the go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc exporter.

type Stderr

type Stderr struct{}

Stderr exports trace data to os.Stderr.

type Stop

type Stop func()

Stop stops our Open Telemetry exporter.

func Start

func Start(ctx context.Context, e Exporter) (Stop, error)

Start creates the OTEL exporter and configures the trace providers. It returns a Stop() which will stop the exporter.

Directories

Path Synopsis
Package sampler offers a Sampler that looks for a TraceID.Valid() == true or a gRPC metadata key called "trace" and if they exist will sample.
Package sampler offers a Sampler that looks for a TraceID.Valid() == true or a gRPC metadata key called "trace" and if they exist will sample.

Jump to

Keyboard shortcuts

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