trace

package
v0.0.0-...-693f2a7 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const ServerName = "cosmo-router"

ServerName Default resource name.

Variables

SensitiveAttributes that should be redacted by the OTEL http instrumentation package. Take attention to the right version of the semconv package.

Functions

func AttachErrToSpan

func AttachErrToSpan(span trace.Span, err error)

AttachErrToSpan attaches an error to a span if it is not nil. If called multiple times, every error will be attached.

func CommonRequestFilter

func CommonRequestFilter(r *http.Request) bool

func Extract

Extract extracts the metadata from ctx.

func GetClientHeader

func GetClientHeader(h http.Header, headerNames []string, defaultValue string) string

func GetTraceID

func GetTraceID(ctx context.Context) string

func Inject

func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD)

Inject injects cross-cutting concerns from the ctx into the metadata.

func NewCompositePropagator

func NewCompositePropagator(propagators ...Propagator) (propagation.TextMapPropagator, error)

func NewTracerProvider

func NewTracerProvider(ctx context.Context, config *ProviderConfig) (*sdktrace.TracerProvider, error)

func NewTransport

func NewTransport(base http.RoundTripper, otelHttpOptions []otelhttp.Option, options ...TransportOption) http.RoundTripper

NewTransport wraps the provided http.RoundTripper. Internally it uses otelhttp.NewTransport to instrument the request.

func PrefixRequestFilter

func PrefixRequestFilter(prefixes []string) func(r *http.Request) bool

func TracerFromContext

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

TracerFromContext returns a tracer in ctx, otherwise returns a global tracer.

Types

type Config

type Config struct {
	Enabled bool
	// Name represents the service name for tracing. The default value is cosmo-router.
	Name string
	// Version represents the service version for tracing. The default value is dev.
	Version string
	// WithNewRoot specifies that the Span should be treated as a root Span. Any existing parent span context will be ignored when defining the Span's trace identifiers.
	WithNewRoot bool
	// Sampler represents the sampler for tracing. The default value is 1.
	Sampler float64
	// ParentBasedSampler specifies if the parent-based sampler should be used. The default value is true.
	ParentBasedSampler bool
	// ExportGraphQLVariables defines if and how GraphQL variables should be exported as span attributes.
	ExportGraphQLVariables ExportGraphQLVariables
	Exporters              []*ExporterConfig
	Propagators            []Propagator
	ResourceAttributes     []attribute.KeyValue
	// TestMemoryExporter is used for testing purposes. If set, the exporter will be used instead of the configured exporters.
	TestMemoryExporter  sdktrace.SpanExporter
	ResponseTraceHeader config.ResponseTraceHeader
	Attributes          []config.CustomAttribute
}

Config represents the configuration for the agent.

func DefaultConfig

func DefaultConfig(serviceVersion string) *Config

DefaultConfig returns the default config.

type ExportGraphQLVariables

type ExportGraphQLVariables struct {
	Enabled bool
}

type ExporterConfig

type ExporterConfig struct {
	Disabled bool
	Endpoint string

	Exporter      otelconfig.Exporter
	BatchTimeout  time.Duration
	ExportTimeout time.Duration
	// Headers represents the headers for HTTP transport.
	// For example:
	//  Authorization: 'Bearer <token>'
	Headers map[string]string
	// HTTPPath represents the path for OTLP HTTP transport.
	// For example
	// /v1/traces
	HTTPPath string
}

func DefaultExporter

func DefaultExporter(cfg *Config) *ExporterConfig

type IPAnonymizationConfig

type IPAnonymizationConfig struct {
	Enabled bool
	Method  IPAnonymizationMethod
}

type IPAnonymizationMethod

type IPAnonymizationMethod string
const (
	Hash   IPAnonymizationMethod = "hash"
	Redact IPAnonymizationMethod = "redact"
)

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

func NewMiddleware

func NewMiddleware(options ...MiddlewareOption) *Middleware

func (*Middleware) Handler

func (h *Middleware) Handler(next http.Handler) http.Handler

type MiddlewareOption

type MiddlewareOption func(h *Middleware)

func WithOtelHttp

func WithOtelHttp(otelOpts ...otelhttp.Option) MiddlewareOption

func WithTracePreHandler

func WithTracePreHandler(preHandler func(r *http.Request, w http.ResponseWriter)) MiddlewareOption

type Propagator

type Propagator string
const (
	PropagatorTraceContext Propagator = "tracecontext"
	PropagatorB3           Propagator = "b3"
	PropagatorJaeger       Propagator = "jaeger"
	PropagatorBaggage      Propagator = "baggage"
	PropagatorDatadog      Propagator = "datadog"

	DefaultBatchTimeout  = 10 * time.Second
	DefaultExportTimeout = 30 * time.Second
)

type ProviderConfig

type ProviderConfig struct {
	Logger            *zap.Logger
	Config            *Config
	ServiceInstanceID string
	IPAnonymization   *IPAnonymizationConfig
	// MemoryExporter is used for testing purposes
	MemoryExporter sdktrace.SpanExporter
}

type TransportOption

type TransportOption func(svr *transport)

func WithPreHandler

func WithPreHandler(handler func(r *http.Request)) TransportOption

WithPreHandler allows to set a pre handler function that is called before the request is sent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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