diff --git a/go.mod b/go.mod index 9670f6718..48c686b30 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,7 @@ require ( github.com/pkg/xattr v0.4.12 github.com/prometheus/client_golang v1.23.0 github.com/r3labs/sse/v2 v2.10.0 - github.com/riandyrn/otelchi v0.12.1 + github.com/riandyrn/otelchi v0.12.2 github.com/rogpeppe/go-internal v1.14.1 github.com/rs/cors v1.11.1 github.com/rs/zerolog v1.34.0 diff --git a/go.sum b/go.sum index 8ec9356ba..e93571ab4 100644 --- a/go.sum +++ b/go.sum @@ -1029,8 +1029,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.12.1 h1:FdRKK3/RgZ/T+d+qTH5Uw3MFx0KwRF38SkdfTMMq/m8= -github.com/riandyrn/otelchi v0.12.1/go.mod h1:weZZeUJURvtCcbWsdb7Y6F8KFZGedJlSrgUjq9VirV8= +github.com/riandyrn/otelchi v0.12.2 h1:6QhGv0LVw/dwjtPd12mnNrl0oEQF4ZAlmHcnlTYbeAg= +github.com/riandyrn/otelchi v0.12.2/go.mod h1:weZZeUJURvtCcbWsdb7Y6F8KFZGedJlSrgUjq9VirV8= 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= diff --git a/vendor/github.com/riandyrn/otelchi/CHANGELOG.md b/vendor/github.com/riandyrn/otelchi/CHANGELOG.md index a5cada73d..d189ed600 100644 --- a/vendor/github.com/riandyrn/otelchi/CHANGELOG.md +++ b/vendor/github.com/riandyrn/otelchi/CHANGELOG.md @@ -8,6 +8,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +## [0.12.2] - 2025-09-02 + +### Fixed + +- Use TracerProvider from request context when available ([#92]) +- Fix high-cardinality metrics and allows user control attributes each metric record ([#95]) + ## [0.12.1] - 2025-02-12 ### Fixed @@ -228,6 +235,8 @@ It contains instrumentation for trace and depends on: - Example code for a basic usage. - Apache-2.0 license. +[#95]: https://github.com/riandyrn/otelchi/pull/95 +[#92]: https://github.com/riandyrn/otelchi/pull/92 [#89]: https://github.com/riandyrn/otelchi/pull/89 [#88]: https://github.com/riandyrn/otelchi/pull/88 [#87]: https://github.com/riandyrn/otelchi/pull/87 @@ -260,7 +269,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.12.1...HEAD +[Unreleased]: https://github.com/riandyrn/otelchi/compare/v0.12.2...HEAD +[0.12.2]: https://github.com/riandyrn/otelchi/releases/tag/v0.12.2 [0.12.1]: https://github.com/riandyrn/otelchi/releases/tag/v0.12.1 [0.12.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.12.0 [0.11.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.11.0 diff --git a/vendor/github.com/riandyrn/otelchi/middleware.go b/vendor/github.com/riandyrn/otelchi/middleware.go index bb3d4b09a..b3a1281be 100644 --- a/vendor/github.com/riandyrn/otelchi/middleware.go +++ b/vendor/github.com/riandyrn/otelchi/middleware.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" semconv "go.opentelemetry.io/otel/semconv/v1.20.0" "go.opentelemetry.io/otel/semconv/v1.20.0/httpconv" @@ -23,6 +24,10 @@ const ( tracerName = "github.com/riandyrn/otelchi" ) +func newTracer(tp trace.TracerProvider) trace.Tracer { + return tp.Tracer(tracerName, trace.WithInstrumentationVersion(version.Version())) +} + // 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. @@ -31,13 +36,12 @@ 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() + + var tracer oteltrace.Tracer + if cfg.tracerProvider != nil { + tracer = newTracer(cfg.tracerProvider) } - tracer := cfg.tracerProvider.Tracer( - tracerName, - oteltrace.WithInstrumentationVersion(version.Version()), - ) + if cfg.propagators == nil { cfg.propagators = otel.GetTextMapPropagator() } @@ -167,8 +171,17 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } + tracer := tw.tracer + if tracer == nil { + if span := trace.SpanFromContext(r.Context()); span.SpanContext().IsValid() { + tracer = newTracer(span.TracerProvider()) + } else { + tracer = newTracer(otel.GetTracerProvider()) + } + } + // start span - ctx, span := tw.tracer.Start(ctx, spanName, spanOpts...) + ctx, span := tracer.Start(ctx, spanName, spanOpts...) defer span.End() // put trace_id to response header only when `WithTraceIDResponseHeader` is used diff --git a/vendor/github.com/riandyrn/otelchi/version/version.go b/vendor/github.com/riandyrn/otelchi/version/version.go index 366119da9..fe3d5cac2 100644 --- a/vendor/github.com/riandyrn/otelchi/version/version.go +++ b/vendor/github.com/riandyrn/otelchi/version/version.go @@ -2,5 +2,5 @@ package version // Version is the current release version of otelchi in use. func Version() string { - return "0.12.1" + return "0.12.2" } diff --git a/vendor/modules.txt b/vendor/modules.txt index 22f8edf9e..d805c7915 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1769,7 +1769,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.12.1 +# github.com/riandyrn/otelchi v0.12.2 ## explicit; go 1.22.0 github.com/riandyrn/otelchi github.com/riandyrn/otelchi/version