otelchi

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 42

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/riandyrn/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.

func Version added in v0.6.0

func Version() string

Version is the current release version of otelchi in use.

Types

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

func WithTraceIDResponseHeader(headerKeyFunc func() string) Option

WithTraceIDResponseHeader enables adding trace id into response header. It accepts a function that generates the header key name. If this parameter function set to `nil` the default header key which is `X-Trace-Id` will be used.

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.

Directories

Path Synopsis
examples
basic Module

Jump to

Keyboard shortcuts

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