Skip to content

Commit 148d21b

Browse files
authored
Merge pull request containerd#9480 from dmcgowan/fix-otel-http
Fix otel version incompatibility
2 parents 194a1fd + cf4b579 commit 148d21b

File tree

30 files changed

+2793
-593
lines changed

30 files changed

+2793
-593
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ require (
5858
github.com/vishvananda/netlink v1.2.1-beta.2
5959
go.etcd.io/bbolt v1.3.7
6060
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
61+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0
6162
go.opentelemetry.io/otel v1.19.0
6263
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
6364
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
@@ -87,6 +88,7 @@ require (
8788
github.com/containerd/containerd v1.7.8 // indirect
8889
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
8990
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
91+
github.com/felixge/httpsnoop v1.0.3 // indirect
9092
github.com/go-logr/logr v1.3.0 // indirect
9193
github.com/go-logr/stdr v1.2.2 // indirect
9294
github.com/godbus/dbus/v5 v5.1.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
253253
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
254254
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
255255
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
256+
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
257+
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
256258
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
257259
github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss=
258260
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -695,6 +697,8 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
695697
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
696698
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 h1:RsQi0qJ2imFfCvZabqzM9cNXBG8k6gXMv1A0cXRmH6A=
697699
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM=
700+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg=
701+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q=
698702
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
699703
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
700704
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=

remotes/docker/resolver.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,18 +595,13 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
595595
return nil
596596
}
597597
}
598-
_, httpSpan := tracing.StartSpan(
599-
ctx,
600-
tracing.Name("remotes.docker.resolver", "HTTPRequest"),
601-
tracing.WithHTTPRequest(req),
602-
)
603-
defer httpSpan.End()
598+
599+
tracing.UpdateHTTPClient(client, tracing.Name("remotes.docker.resolver", "HTTPRequest"))
600+
604601
resp, err := client.Do(req)
605602
if err != nil {
606-
httpSpan.SetStatus(err)
607603
return nil, fmt.Errorf("failed to do request: %w", err)
608604
}
609-
httpSpan.SetAttributes(tracing.HTTPStatusCodeAttributes(resp.StatusCode)...)
610605
log.G(ctx).WithFields(responseFields(resp)).Debug("fetch response received")
611606
return resp, nil
612607
}

tracing/plugin/otlp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"go.opentelemetry.io/otel/propagation"
3737
"go.opentelemetry.io/otel/sdk/resource"
3838
"go.opentelemetry.io/otel/sdk/trace"
39-
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
39+
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
4040
)
4141

4242
const exporterPlugin = "otlp"

tracing/tracing.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020
"context"
2121
"net/http"
2222

23+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2324
"go.opentelemetry.io/otel"
2425
"go.opentelemetry.io/otel/attribute"
2526
"go.opentelemetry.io/otel/codes"
26-
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
27-
httpconv "go.opentelemetry.io/otel/semconv/v1.17.0/httpconv"
27+
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
2828
"go.opentelemetry.io/otel/trace"
2929
)
3030

@@ -35,15 +35,14 @@ type StartConfig struct {
3535

3636
type SpanOpt func(config *StartConfig)
3737

38-
// WithHTTPRequest marks span as a HTTP request operation from client to server.
39-
// It'll append attributes from the HTTP request object and mark it with `SpanKindClient` type.
40-
func WithHTTPRequest(request *http.Request) SpanOpt {
41-
return func(config *StartConfig) {
42-
config.spanOpts = append(config.spanOpts,
43-
trace.WithSpanKind(trace.SpanKindClient), // A client making a request to a server
44-
trace.WithAttributes(httpconv.ClientRequest(request)...), // Add HTTP attributes
45-
)
46-
}
38+
// UpdateHTTPClient updates the http client with the necessary otel transport
39+
func UpdateHTTPClient(client *http.Client, name string) {
40+
client.Transport = otelhttp.NewTransport(
41+
client.Transport,
42+
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
43+
return name
44+
}),
45+
)
4746
}
4847

4948
// StartSpan starts child span in a context.

vendor/github.com/felixge/httpsnoop/.gitignore

Whitespace-only changes.

vendor/github.com/felixge/httpsnoop/.travis.yml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/felixge/httpsnoop/LICENSE.txt

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/felixge/httpsnoop/Makefile

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/felixge/httpsnoop/README.md

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)