Skip to content

Commit

Permalink
Properly set the net.host.name and http.url tags in OpenTelemetry…
Browse files Browse the repository at this point in the history
… traces
  • Loading branch information
DarthSim committed Aug 23, 2024
1 parent ba17ed8 commit dc6acc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- (pro) Add [monochrome](https://docs.imgproxy.net/latest/usage/processing#monochrome) processing option.
- (pro) Add [duotone](https://docs.imgproxy.net/latest/usage/processing#duotone) processing option.

# Change
- Properly set the `net.host.name` and `http.url` tags in OpenTelemetry traces.

# Fix
- Fix handling `#` symbols in `local://`, `s3://`, `gcs://`, `abs://`, and `swift://` URLs.
- Fix `IMGPROXY_FALLBACK_IMAGE_HTTP_CODE` value check. Allow `0` value.
Expand Down
12 changes: 9 additions & 3 deletions metrics/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/semconv/v1.17.0/httpconv"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
"go.opentelemetry.io/otel/semconv/v1.20.0/httpconv"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc/credentials"

Expand Down Expand Up @@ -397,10 +397,16 @@ func StartRootSpan(ctx context.Context, rw http.ResponseWriter, r *http.Request)
ctx = propagator.Extract(ctx, propagation.HeaderCarrier(r.Header))
}

server := r.Host
if len(server) == 0 {
server = "imgproxy"
}

ctx, span := tracer.Start(
ctx, "/request",
trace.WithSpanKind(trace.SpanKindServer),
trace.WithAttributes(httpconv.ServerRequest("imgproxy", r)...),
trace.WithAttributes(httpconv.ServerRequest(server, r)...),
trace.WithAttributes(semconv.HTTPURL(r.RequestURI)),
)
ctx = context.WithValue(ctx, hasSpanCtxKey{}, struct{}{})

Expand Down

0 comments on commit dc6acc7

Please sign in to comment.