otelchi

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

otelchi

ci Go Report Card Documentation

OpenTelemetry instrumentation for go-chi/chi.

Essentialy this is adaptation from otelmux but instead using gorilla/mux, we use go-chi/chi.

Currently it could only instrument traces.

Contributions are welcomed!

Install

$ go get github.com/shah-pf/otelchi

Examples

See examples for details.

Why Port This?

I was planning to make this project as part of Open Telemetry Go instrumentation project. However based on this comment they no longer accept new instrumentation. This is why I maintain this project here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(serverName string, opts ...Option) func(next http.Handler) http.Handler

Middleware sets up a handler to start tracing the incoming requests. The serverName parameter should describe the name of the (virtual) server handling the request.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option specifies instrumentation configuration options.

func WithChiRoutes

func WithChiRoutes(routes chi.Routes) Option

WithChiRoutes specified the routes that being used by application. Its main purpose is to provide route pattern as span name during span creation. If this option is not set, by default the span will be given name at the end of span execution. For some people, this behavior is not desirable since they want to override the span name on underlying handler. By setting this option, it is possible for them to override the span name.

func WithFilter

func WithFilter(filter func(r *http.Request) bool) Option

WithFilter is used for filtering request that should not be traced. This is useful for filtering health check request, etc. A Filter must return true if the request should be traced.

func WithPropagators

func WithPropagators(propagators propagation.TextMapPropagator) Option

WithPropagators specifies propagators to use for extracting information from the HTTP requests. If none are specified, global ones will be used.

func WithRequestMethodInSpanName

func WithRequestMethodInSpanName(isActive bool) Option

WithRequestMethodInSpanName is used for adding http request method to span name. While this is not necessary for vendors that properly implemented the tracing specs (e.g Jaeger, AWS X-Ray, etc...), but for other vendors such as Elastic and New Relic this might be helpful.

See following threads for details:

- https://github.com/shah-pf/otelchi/pull/3#issuecomment-1005883910 - https://github.com/shah-pf/otelchi/issues/6#issuecomment-1034461912

func WithSpanCustomizer

func WithSpanCustomizer(customizer func(r *http.Request, span oteltrace.Span) oteltrace.Span) Option

WithSpanCustomizer is used for customizing span and it's attributes based on custom logic. This is useful for adding additional attributes to the span A SpanCustomizer must return instance of the customized span

func WithTracerProvider

func WithTracerProvider(provider oteltrace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.

Jump to

Keyboard shortcuts

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