8000 Merge pull request #9483 from dmcgowan/backport-1.7-fix-otel-http · containerd/containerd@d94f8ff · GitHub
[go: up one dir, main page]

Skip to content

Commit d94f8ff

Browse files
authored
Merge pull request #9483 from dmcgowan/backport-1.7-fix-otel-http
[release/1.7] Fix otel version incompatibility
2 parents 8e06899 + f8f659e commit d94f8ff

File tree

32 files changed

+2805
-587
lines changed

32 files changed

+2805
-587
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ require (
6060
github.com/vishvananda/netlink v1.2.1-beta.2
6161
go.etcd.io/bbolt v1.3.7
6262
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
63+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0
6364
go.opentelemetry.io/otel v1.19.0
6465
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
6566
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
@@ -92,6 +93,7 @@ require (
9293
github.com/containerd/typeurl v1.0.2 // indirect
9394
github.com/containers/ocicrypt v1.1.6 // indirect
9495
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
96+
github.com/felixge/httpsnoop v1.0.3 // indirect
9597
github.com/go-logr/logr v1.2.4 // indirect
9698
github.com/go-logr/stdr v1.2.2 // indirect
9799
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
@@ -397,6 +397,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
397397
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
398398
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
399399
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
400+
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
401+
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
400402
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
401403
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
402404
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
@@ -1025,6 +1027,8 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.2
10251027
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 h1:RsQi0qJ2imFfCvZabqzM9cNXBG8k6gXMv1A0cXRmH6A=
10261028
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM=
10271029
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4=
1030+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg=
1031+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q=
10281032
go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo=
10291033
go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
10301034
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=

integration/client/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/davecgh/go-spew v1.1.1 // indirect
3434
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
3535
github.com/docker/go-units v0.5.0 // indirect
36+
github.com/felixge/httpsnoop v1.0.3 // indirect
3637
github.com/go-logr/logr v1.2.4 // indirect
3738
github.com/go-logr/stdr v1.2.2 // indirect
3839
github.com/godbus/dbus/v5 v5.1.0 // indirect
@@ -54,6 +55,7 @@ require (
5455
github.com/pmezard/go-difflib v1.0.0 // indirect
5556
github.com/sirupsen/logrus v1.9.3 // indirect
5657
go.opencensus.io v0.24.0 // indirect
58+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
5759
go.opentelemetry.io/otel/metric v1.19.0 // indirect
5860
go.opentelemetry.io/otel/trace v1.19.0 // indirect
5961
golang.org/x/mod v0.11.0 // indirect

integration/client/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQL
10011001
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
10021002
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
10031003
github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
1004+
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
10041005
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
10051006
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
10061007
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
@@ -1654,6 +1655,8 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.3
16541655
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0/go.mod h1:vsh3ySueQCiKPxFLvjWC4Z135gIa34TQ/NSqkDTZYUM=
16551656
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.32.0/go.mod h1:5eCOqeGphOyz6TsY3ZDNjE33SM/TFAK3RGuCL2naTgY=
16561657
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.0/go.mod h1:9NiG9I2aHTKkcxqCILhjtyNA1QEiCjdBACv4IvrFQ+c=
1658+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg=
1659+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q=
16571660
go.opentelemetry.io/otel v1.0.1/go.mod h1:OPEOD4jIT2SlZPMmwT6FqZz2C0ZNdQqiWcoK6M0SNFU=
16581661
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
16591662
go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM=

remotes/docker/resolver.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,13 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
585585
return nil
586586
}
587587
}
588-
_, httpSpan := tracing.StartSpan(
589-
ctx,
590-
tracing.Name("remotes.docker.resolver", "HTTPRequest"),
591-
tracing.WithHTTPRequest(req),
592-
)
593-
defer httpSpan.End()
588+
589+
tracing.UpdateHTTPClient(client, tracing.Name("remotes.docker.resolver", "HTTPRequest"))
590+
594591
resp, err := client.Do(req)
595592
if err != nil {
596-
httpSpan.SetStatus(err)
597593
return nil, fmt.Errorf("failed to do request: %w", err)
598594
}
599-
httpSpan.SetAttributes(tracing.HTTPStatusCodeAttributes(resp.StatusCode)...)
600595
log.G(ctx).WithFields(responseFields(resp)).Debug("fetch response received")
601596
return resp, nil
602597
}

tracing/plugin/otlp.go

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

4141
const exporterPlugin = "otlp"

tracing/tracing.go

Lines changed: 17 additions & 5 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

@@ -37,15 +37,27 @@ type SpanOpt func(config *StartConfig)
3737

3838
// WithHTTPRequest marks span as a HTTP request operation from client to server.
3939
// It'll append attributes from the HTTP request object and mark it with `SpanKindClient` type.
40-
func WithHTTPRequest(request *http.Request) SpanOpt {
40+
//
41+
// Deprecated: use upstream functionality from otelhttp directly instead. This function is kept for API compatibility
42+
// but no longer works as expected due to required functionality no longer exported in OpenTelemetry libraries.
43+
func WithHTTPRequest(_ *http.Request) SpanOpt {
4144
return func(config *StartConfig) {
4245
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
46+
trace.WithSpanKind(trace.SpanKindClient), // A client making a request to a server
4547
)
4648
}
4749
}
4850

51+
// UpdateHTTPClient updates the http client with the necessary otel transport
52+
func UpdateHTTPClient(client *http.Client, name string) {
53+
client.Transport = otelhttp.NewTransport(
54+
client.Transport,
55+
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
56+
return name
57+
}),
58+
)
59+
}
60+
4961
// StartSpan starts child span in a context.
5062
func StartSpan(ctx context.Context, opName string, opts ...SpanOpt) (context.Context, *Span) {
5163
config := StartConfig{}

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.

0 commit comments

Comments
 (0)
0