Documentation ¶
Index ¶
- Constants
- Variables
- func AttachErrToSpan(span trace.Span, err error)
- func CommonRequestFilter(r *http.Request) bool
- func Extract(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) (baggage.Baggage, sdktrace.SpanContext)
- func GetClientHeader(h http.Header, headerNames []string, defaultValue string) string
- func GetTraceID(ctx context.Context) string
- func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD)
- func NewCompositePropagator(propagators ...Propagator) (propagation.TextMapPropagator, error)
- func NewTracerProvider(ctx context.Context, config *ProviderConfig) (*sdktrace.TracerProvider, error)
- func NewTransport(base http.RoundTripper, otelHttpOptions []otelhttp.Option, ...) http.RoundTripper
- func PrefixRequestFilter(prefixes []string) func(r *http.Request) bool
- func TracerFromContext(ctx context.Context) (tracer trace.Tracer)
- type Config
- type ExportGraphQLVariables
- type ExporterConfig
- type IPAnonymizationConfig
- type IPAnonymizationMethod
- type Middleware
- type MiddlewareOption
- type Propagator
- type ProviderConfig
- type TransportOption
Constants ¶
const ServerName = "cosmo-router"
ServerName Default resource name.
Variables ¶
var SensitiveAttributes = []attribute.Key{ semconv17.HTTPClientIPKey, semconv17.NetSockPeerAddrKey, }
SensitiveAttributes that should be redacted by the OTEL http instrumentation package. Take attention to the right version of the semconv package.
Functions ¶
func AttachErrToSpan ¶
AttachErrToSpan attaches an error to a span if it is not nil. If called multiple times, every error will be attached.
func CommonRequestFilter ¶
func Extract ¶
func Extract(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) ( baggage.Baggage, sdktrace.SpanContext)
Extract extracts the metadata from ctx.
func GetClientHeader ¶
func GetTraceID ¶
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.
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 ¶
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
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.