chore(deps): bump github.com/riandyrn/otelchi from 0.10.1 to 0.11.0

Bumps [github.com/riandyrn/otelchi](https://github.com/riandyrn/otelchi) from 0.10.1 to 0.11.0.
- [Release notes](https://github.com/riandyrn/otelchi/releases)
- [Changelog](https://github.com/riandyrn/otelchi/blob/master/CHANGELOG.md)
- [Commits](https://github.com/riandyrn/otelchi/compare/v0.10.1...v0.11.0)

---
updated-dependencies:
- dependency-name: github.com/riandyrn/otelchi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2024-11-29 06:12:50 +00:00
committed by Ralf Haferkamp
parent 6782c2473d
commit ecff193847
8 changed files with 55 additions and 54 deletions

2
go.mod
View File

@@ -72,7 +72,7 @@ require (
github.com/pkg/xattr v0.4.10
github.com/prometheus/client_golang v1.20.5
github.com/r3labs/sse/v2 v2.10.0
github.com/riandyrn/otelchi v0.10.1
github.com/riandyrn/otelchi v0.11.0
github.com/rogpeppe/go-internal v1.13.1
github.com/rs/cors v1.11.1
github.com/rs/zerolog v1.33.0

4
go.sum
View File

@@ -977,8 +977,8 @@ github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKc
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/riandyrn/otelchi v0.10.1 h1:x86f8M0pGvjW3tJUxpva4cpdNtMydLPnarIXHssYUy4=
github.com/riandyrn/otelchi v0.10.1/go.mod h1:SWarhA5rdeiCNq+Ygc4p59ZGM5AtYCiyPU/3Q5rzT0M=
github.com/riandyrn/otelchi v0.11.0 h1:x9MFoTgHcwCC2DdWkTEEZ2ZQFkbl6z7GXLQtTANN6Gk=
github.com/riandyrn/otelchi v0.11.0/go.mod h1:FlBYmG9fBQu0jFRvZZrATP4mDvLX2H5gwELfpZvNlxY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=

View File

@@ -8,6 +8,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased]
## [0.11.0] - 2024-11-27
### Added
- Add metric package as middleware `go-chi/chi`, support `request_duration_millis`, `requests_inflight`, and `response_size_bytes` metric. ([#69])
### Changed
- Upgrade `go.opentelemetry.io/otel`, `go.opentelemetry.io/otel/sdk`, & `go.opentelemetry.io/otel/trace` to `v1.32.0`. ([#74])
## [0.10.1] - 2024-10-27
### Changed
@@ -204,7 +214,9 @@ It contains instrumentation for trace and depends on:
- Example code for a basic usage.
- Apache-2.0 license.
[#74]: https://github.com/riandyrn/otelchi/pull/74
[#70]: https://github.com/riandyrn/otelchi/pull/70
[#69]: https://github.com/riandyrn/otelchi/pull/69
[#67]: https://github.com/riandyrn/otelchi/pull/67
[#64]: https://github.com/riandyrn/otelchi/pull/64
[#63]: https://github.com/riandyrn/otelchi/pull/63
@@ -231,7 +243,8 @@ It contains instrumentation for trace and depends on:
[#2]: https://github.com/riandyrn/otelchi/pull/2
[#1]: https://github.com/riandyrn/otelchi/pull/1
[Unreleased]: https://github.com/riandyrn/otelchi/compare/v0.10.1...HEAD
[Unreleased]: https://github.com/riandyrn/otelchi/compare/v0.11.0...HEAD
[0.11.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.11.0
[0.10.1]: https://github.com/riandyrn/otelchi/releases/tag/v0.10.1
[0.10.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.10.0
[0.9.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.9.0

View File

@@ -8,7 +8,7 @@ OpenTelemetry instrumentation for [go-chi/chi](https://github.com/go-chi/chi).
Essentially this is an adaptation from [otelmux](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation/github.com/gorilla/mux/otelmux) but instead of using `gorilla/mux`, we use `go-chi/chi`.
Currently, this library can only instrument traces.
Currently, this library can only instrument traces and metrics.
Contributions are welcomed!

View File

@@ -16,14 +16,14 @@ const (
// config is used to configure the mux middleware.
type config struct {
TracerProvider oteltrace.TracerProvider
Propagators propagation.TextMapPropagator
ChiRoutes chi.Routes
RequestMethodInSpanName bool
Filters []Filter
TraceIDResponseHeaderKey string
TraceSampledResponseHeaderKey string
PublicEndpointFn func(r *http.Request) bool
tracerProvider oteltrace.TracerProvider
propagators propagation.TextMapPropagator
chiRoutes chi.Routes
requestMethodInSpanName bool
filters []Filter
traceIDResponseHeaderKey string
traceSampledResponseHeaderKey string
publicEndpointFn func(r *http.Request) bool
}
// Option specifies instrumentation configuration options.
@@ -46,7 +46,7 @@ type Filter func(*http.Request) bool
// ones will be used.
func WithPropagators(propagators propagation.TextMapPropagator) Option {
return optionFunc(func(cfg *config) {
cfg.Propagators = propagators
cfg.propagators = propagators
})
}
@@ -54,7 +54,7 @@ func WithPropagators(propagators propagation.TextMapPropagator) Option {
// If none is specified, the global provider is used.
func WithTracerProvider(provider oteltrace.TracerProvider) Option {
return optionFunc(func(cfg *config) {
cfg.TracerProvider = provider
cfg.tracerProvider = provider
})
}
@@ -66,7 +66,7 @@ func WithTracerProvider(provider oteltrace.TracerProvider) Option {
// is possible for them to override the span name.
func WithChiRoutes(routes chi.Routes) Option {
return optionFunc(func(cfg *config) {
cfg.ChiRoutes = routes
cfg.chiRoutes = routes
})
}
@@ -81,7 +81,7 @@ func WithChiRoutes(routes chi.Routes) Option {
// - https://github.com/riandyrn/otelchi/issues/6#issuecomment-1034461912
func WithRequestMethodInSpanName(isActive bool) Option {
return optionFunc(func(cfg *config) {
cfg.RequestMethodInSpanName = isActive
cfg.requestMethodInSpanName = isActive
})
}
@@ -93,7 +93,7 @@ func WithRequestMethodInSpanName(isActive bool) Option {
// simple and fast.
func WithFilter(filter Filter) Option {
return optionFunc(func(cfg *config) {
cfg.Filters = append(cfg.Filters, filter)
cfg.filters = append(cfg.filters, filter)
})
}
@@ -125,14 +125,14 @@ type TraceHeaderConfig struct {
// be used for the respective headers.
func WithTraceResponseHeaders(cfg TraceHeaderConfig) Option {
return optionFunc(func(c *config) {
c.TraceIDResponseHeaderKey = cfg.TraceIDHeader
if c.TraceIDResponseHeaderKey == "" {
c.TraceIDResponseHeaderKey = DefaultTraceIDResponseHeaderKey
c.traceIDResponseHeaderKey = cfg.TraceIDHeader
if c.traceIDResponseHeaderKey == "" {
c.traceIDResponseHeaderKey = DefaultTraceIDResponseHeaderKey
}
c.TraceSampledResponseHeaderKey = cfg.TraceSampledHeader
if c.TraceSampledResponseHeaderKey == "" {
c.TraceSampledResponseHeaderKey = DefaultTraceSampledResponseHeaderKey
c.traceSampledResponseHeaderKey = cfg.TraceSampledHeader
if c.traceSampledResponseHeaderKey == "" {
c.traceSampledResponseHeaderKey = DefaultTraceSampledResponseHeaderKey
}
})
}
@@ -174,6 +174,6 @@ func WithPublicEndpoint() Option {
// more flexibility.
func WithPublicEndpointFn(fn func(r *http.Request) bool) Option {
return optionFunc(func(cfg *config) {
cfg.PublicEndpointFn = fn
cfg.publicEndpointFn = fn
})
}

View File

@@ -30,44 +30,32 @@ func Middleware(serverName string, opts ...Option) func(next http.Handler) http.
for _, opt := range opts {
opt.apply(&cfg)
}
if cfg.TracerProvider == nil {
cfg.TracerProvider = otel.GetTracerProvider()
if cfg.tracerProvider == nil {
cfg.tracerProvider = otel.GetTracerProvider()
}
tracer := cfg.TracerProvider.Tracer(
tracer := cfg.tracerProvider.Tracer(
tracerName,
oteltrace.WithInstrumentationVersion(Version()),
)
if cfg.Propagators == nil {
cfg.Propagators = otel.GetTextMapPropagator()
if cfg.propagators == nil {
cfg.propagators = otel.GetTextMapPropagator()
}
return func(handler http.Handler) http.Handler {
return traceware{
serverName: serverName,
tracer: tracer,
propagators: cfg.Propagators,
handler: handler,
chiRoutes: cfg.ChiRoutes,
reqMethodInSpanName: cfg.RequestMethodInSpanName,
filters: cfg.Filters,
traceIDResponseHeaderKey: cfg.TraceIDResponseHeaderKey,
traceSampledResponseHeaderKey: cfg.TraceSampledResponseHeaderKey,
publicEndpointFn: cfg.PublicEndpointFn,
config: cfg,
serverName: serverName,
tracer: tracer,
handler: handler,
}
}
}
type traceware struct {
serverName string
tracer oteltrace.Tracer
propagators propagation.TextMapPropagator
handler http.Handler
chiRoutes chi.Routes
reqMethodInSpanName bool
filters []Filter
traceIDResponseHeaderKey string
traceSampledResponseHeaderKey string
publicEndpointFn func(r *http.Request) bool
config
serverName string
tracer oteltrace.Tracer
handler http.Handler
}
type recordingResponseWriter struct {
@@ -144,7 +132,7 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rctx := chi.NewRouteContext()
if tw.chiRoutes.Match(rctx, r.Method, r.URL.Path) {
routePattern = rctx.RoutePattern()
spanName = addPrefixToSpanName(tw.reqMethodInSpanName, r.Method, routePattern)
spanName = addPrefixToSpanName(tw.requestMethodInSpanName, r.Method, routePattern)
spanAttributes = append(spanAttributes, semconv.HTTPRoute(routePattern))
}
}
@@ -200,7 +188,7 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
routePattern = chi.RouteContext(r.Context()).RoutePattern()
span.SetAttributes(semconv.HTTPRoute(routePattern))
spanName = addPrefixToSpanName(tw.reqMethodInSpanName, r.Method, routePattern)
spanName = addPrefixToSpanName(tw.requestMethodInSpanName, r.Method, routePattern)
span.SetName(spanName)
}

View File

@@ -2,5 +2,5 @@ package otelchi
// Version is the current release version of otelchi in use.
func Version() string {
return "0.10.1"
return "0.11.0"
}

2
vendor/modules.txt vendored
View File

@@ -1667,7 +1667,7 @@ github.com/r3labs/sse/v2
# github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
## explicit
github.com/rcrowley/go-metrics
# github.com/riandyrn/otelchi v0.10.1
# github.com/riandyrn/otelchi v0.11.0
## explicit; go 1.22.0
github.com/riandyrn/otelchi
# github.com/rivo/uniseg v0.4.7