package module
v0.5.1 Latest Latest

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 9 Imported by: 25



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!


$ go get github.com/riandyrn/otelchi


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.




This section is empty.


This section is empty.


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.


type Option

type Option interface {
	// contains filtered or unexported methods

Option specifies instrumentation configuration options.

func WithChiRoutes added in v0.3.0

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 added in v0.5.0

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 added in v0.4.0

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/riandyrn/otelchi/pull/3#issuecomment-1005883910 - https://github.com/riandyrn/otelchi/issues/6#issuecomment-1034461912

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.


Path Synopsis

Jump to

Keyboard shortcuts

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