Help us shape the future of Go! Take the 2026 Go Developer Survey

trace

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package trace sets up OpenTelemetry tracing for the process. StartAgent installs the global tracer provider with the exporter the configuration names, and importing the package installs the W3C trace-context and baggage propagators, so traces continue across HTTP calls and queued tasks. The helpers read the trace of a request context; its trace ID is also the request ID the HTTP responses carry (RequestIdKey).

Index

Constants

View Source
const TraceName = "ppanel"

TraceName represents the tracing name.

Variables

View Source
var RequestIdKey = http.CanonicalHeaderKey("x-request-id")

RequestIdKey is the request id header, has a unique association to a trace id. The Request ID uses the UUID format because, first, it is more in line with industry standards, second, it guarantees the privacy and security of the Trace ID, and third, it provides standardization capabilities for subsequent distribution.

Functions

func AddResources

func AddResources(attrs ...attribute.KeyValue)

AddResources add more resources in addition to configured trace name.

func StartAgent

func StartAgent(c Config)

StartAgent starts an opentelemetry agent.

func StopAgent

func StopAgent()

StopAgent shuts down the span processors in the order they were registered, giving up on a collector that does not answer within shutdownTimeout.

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

TraceIDFromContext returns the trace id from ctx, or an empty string.

func TracerFromContext

func TracerFromContext(ctx context.Context) (tracer trace.Tracer)

TracerFromContext returns the tracer of the span in ctx, or the global tracer when ctx has none, so a child span stays with its parent's provider.

Types

type Config

type Config struct {
	Name string `yaml:"Name"`
	// Endpoint is where the batcher sends spans; empty disables exporting.
	// For the jaeger batcher it is Jaeger's OTLP/HTTP receiver, either a URL
	// such as http://jaeger:4318 (posting to /v1/traces unless the URL names
	// another path; the scheme selects TLS) or a bare host:port (like
	// otlphttp). Jaeger has received OTLP natively since 1.35. The endpoints
	// of the former Jaeger Thrift exporter — the agent's udp://host:6831 and
	// the collector's http://host:14268/api/traces — are rewritten to OTLP on
	// port 4318 of the same host, with a warning in the log.
	Endpoint string  `yaml:"Endpoint"`
	Sampler  float64 `yaml:"Sampler" default:"0.1"`
	// Batcher selects the exporter: jaeger (OTLP/HTTP to Jaeger, see
	// Endpoint), zipkin, otlpgrpc, otlphttp or file.
	Batcher string `yaml:"Batcher" default:"jaeger"`
	// OtlpHeaders represents the headers for OTLP gRPC or HTTP transport.
	// For example:
	//  uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'
	OtlpHeaders map[string]string `yaml:"OtlpHeaders"`
	// OtlpHttpPath represents the path for OTLP HTTP transport with a
	// host:port Endpoint.
	// For example
	// /v1/traces
	OtlpHttpPath string `yaml:"OtlpHttpPath"`
	// OtlpHttpSecure represents the scheme to use for OTLP HTTP transport
	// with a host:port Endpoint.
	OtlpHttpSecure bool `yaml:"OtlpHttpSecure"`
	// OtlpGrpcSecure makes the otlpgrpc batcher connect with TLS, verifying
	// the collector against the system roots. False, the default and the
	// only behaviour before the key existed, sends the spans in plaintext,
	// which suits a collector on the same host or private network only.
	OtlpGrpcSecure bool `yaml:"OtlpGrpcSecure"`
	// Disabled indicates whether StartAgent starts the agent.
	Disabled bool `yaml:"Disabled"`
}

A Config is an opentelemetry config.

Jump to

Keyboard shortcuts

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