Documentation ¶
Overview ¶
Package cloudtrace provides primitives for Cloud Trace integration.
Index ¶
- Constants
- func IDHook(ctx context.Context, traceContext Context) context.Context
- func SetContext(ctx context.Context, ctxx Context) context.Context
- func StartExporter(ctx context.Context, exporterConfig ExporterConfig, ...) (func(context.Context) error, error)
- type Context
- type ExporterConfigdeprecated
- type Middleware
- func (i *Middleware) GRPCServerUnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func (i *Middleware) GRPCStreamServerInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) (err error)
- func (i *Middleware) HTTPServer(next http.Handler) http.Handler
Constants ¶
const ContextHeader = "x-cloud-trace-context"
ContextHeader is the metadata key of the Cloud Trace context header.
const IDKey = "traceId"
IDKey is the log entry key for trace IDs. Experimental: May be removed in a future update.
Variables ¶
This section is empty.
Functions ¶
func IDHook ¶ added in v0.28.0
IDHook adds the trace ID (without the full trace resource name) to the request logger. The trace ID can be used to filter on logs for the same trace across multiple projects. Experimental: May be removed in a future update.
func SetContext ¶ added in v0.30.0
SetContext sets the cloud trace context to the provided context. Deprecated: Use OpenTelemetry middleware for trace extraction.
Types ¶
type Context ¶
type Context struct { // TraceID is a 32-character hexadecimal value representing a 128-bit number. TraceID string // SpanID is the decimal representation of the (unsigned) span ID. SpanID string // Sampled indicates if the trace is being sampled. Sampled bool }
Context represents a Google Cloud Trace context header value.
The format of the X-Cloud-Trace-Context header is:
TRACE_ID/SPAN_ID;o=TRACE_TRUE"
See: https://cloud.google.com/trace/docs/setup
func FromIncomingContext ¶
FromIncomingContext returns the incoming Cloud Trace Context. Deprecated: FromIncomingContext does not handle trace context coming from a HTTP server, use GetContext instead.
func GetContext ¶ added in v0.30.0
GetContext gets the cloud trace context from the provided context if it exists. Deprecated: Use OpenTelemetry trace.SpanContextFromContext.
func (*Context) UnmarshalString ¶
UnmarshalString parses the provided X-Cloud-Trace-Context header.
type ExporterConfig
deprecated
type ExporterConfig = cloudotel.TraceExporterConfig
Deprecated: use cloudotel.TraceExporterConfig.
type Middleware ¶
type Middleware struct { // ProjectID of the project the service is running in. ProjectID string // TraceHook is an optional callback that gets called with the parsed trace context. TraceHook func(context.Context, Context) context.Context }
Middleware that ensures incoming traces are forwarded and included in logging.
func (*Middleware) GRPCServerUnaryInterceptor ¶
func (i *Middleware) GRPCServerUnaryInterceptor( ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (resp interface{}, err error)
GRPCServerUnaryInterceptor provides unary RPC middleware for gRPC servers.
func (*Middleware) GRPCStreamServerInterceptor ¶ added in v0.41.0
func (i *Middleware) GRPCStreamServerInterceptor( srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, ) (err error)
GRPCStreamServerInterceptor adds tracing metadata to streaming RPCs.
func (*Middleware) HTTPServer ¶
func (i *Middleware) HTTPServer(next http.Handler) http.Handler
HTTPServer provides middleware for HTTP servers.