Documentation
¶
Overview ¶
Package tracer provides convenience functions for OpenTelemetry tracing.
It offers two main capabilities:
1. A "Start" function that simplifies trace creation by automatically determining the tracer and span names from the calling function's package and name.
2. Functions for setting up tracing with Google Cloud Trace, including an HTTP middleware and a TracerProvider that exports to Google Cloud.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGoogleCloudHandler ¶
NewGoogleCloudHandler creates a new HTTP middleware for OpenTelemetry tracing, specifically configured for Google Cloud Trace.
It uses the CloudTraceFormatPropagator and sets the span name to the request URL path. The returned function can be used to wrap an http.Handler to add tracing. Additional otelhttp.Option arguments can be passed to customize the behavior.
Types ¶
type Provider ¶ added in v0.1.0
type Provider struct {
*sdktrace.TracerProvider
}
Provider is an OpenTelemetry Provider. It provides Tracers to instrumentation so it can trace operational flow through a system.
This wrapper is used to keep otel dependency management contained in this package. Cordinating package versions between otel/sdk/resource package and the otel/semconv package is painful, so eliminating the need to import otel as a direct import in your project helps to keep the version cordination in one place.
func NewGoogleCloudTracerProvider ¶
func NewGoogleCloudTracerProvider(loggingProjectID, serviceName string, opts ...sdktrace.TracerProviderOption) (*Provider, error)
NewGoogleCloudTracerProvider creates and configures a new OpenTelemetry TracerProvider for use with Google Cloud Trace. It sets up an exporter to send traces to the specified Google Cloud project.
The created TracerProvider is also set as the global tracer provider for the application.
type Span ¶
Span is the individual component of a trace. It represents a single named and timed operation of a workflow that is traced. A Tracer is used to create a Span and it is then up to the operation the Span represents to properly end the Span when the operation itself ends.
func Start ¶
Start uses runtime reflection to determine the fully qualified package path and the function/method name of the caller.
The Tracer name is set to the fully qualified package path (e.g., "github.com/cccteam/ccc"). The Span name is set to the short function name (e.g., "Struct.Method()").