cloudtrace

package
v0.79.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cloudtrace provides primitives for Cloud Trace integration.

Index

Constants

View Source
const ContextHeader = "x-cloud-trace-context"

ContextHeader is the metadata key of the Cloud Trace context header.

View Source
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

func IDHook(ctx context.Context, traceContext Context) context.Context

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

func SetContext(ctx context.Context, ctxx Context) context.Context

SetContext sets the cloud trace context to the provided context. Deprecated: Use OpenTelemetry middleware for trace extraction.

func StartExporter

func StartExporter(
	ctx context.Context,
	exporterConfig ExporterConfig,
	resource *resource.Resource,
) (func(context.Context) error, error)

StartExporter starts the OpenTelemetry Cloud Trace exporter. Deprecated: use cloudotel.StartTraceExporter.

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

func FromIncomingContext(ctx context.Context) (Context, bool)

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

func GetContext(ctx context.Context) (Context, bool)

GetContext gets the cloud trace context from the provided context if it exists. Deprecated: Use OpenTelemetry trace.SpanContextFromContext.

func (Context) String

func (c Context) String() string

String returns a string representation of the trace context.

func (*Context) UnmarshalString

func (c *Context) UnmarshalString(value string) error

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.

Jump to

Keyboard shortcuts

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