Skip to content

Commit 807ddd6

Browse files
milasdmcgowan
authored andcommitted
fix(tracing): use latest version of semconv
All components need to use a consistent `semconv` version or OTel will emit errors about "cannot merge resource due to conflicting Schema URL". Switch to the appropriate semconv version, which requires dropping usage of `httpconv`. Instead, the upstream HTTP client hooks are used directly. (The lower-level functions are no longer exported by OTel.) Signed-off-by: Milas Bowman <[email protected]> (cherry picked from commit ad3b806) Signed-off-by: Derek McGowan <[email protected]>
1 parent 689d07b commit 807ddd6

32 files changed

Lines changed: 2797 additions & 586 deletions

File tree

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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/containerd/containerd/version"
4040
"github.com/opencontainers/go-digest"
4141
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
42+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
4243
)
4344

4445
var (
@@ -585,18 +586,16 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
585586
return nil
586587
}
587588
}
588-
_, httpSpan := tracing.StartSpan(
589-
ctx,
590-
tracing.Name("remotes.docker.resolver", "HTTPRequest"),
591-
tracing.WithHTTPRequest(req),
589+
client.Transport = otelhttp.NewTransport(
590+
client.Transport,
591+
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
592+
return tracing.Name("remotes.docker.resolver", "HTTPRequest")
593+
}),
592594
)
593-
defer httpSpan.End()
594595
resp, err := client.Do(req)
595596
if err != nil {
596-
httpSpan.SetStatus(err)
597597
return nil, fmt.Errorf("failed to do request: %w", err)
598598
}
599-
httpSpan.SetAttributes(tracing.HTTPStatusCodeAttributes(resp.StatusCode)...)
600599
log.G(ctx).WithFields(responseFields(resp)).Debug("fetch response received")
601600
return resp, nil
602601
}

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"go.opentelemetry.io/otel"
2424
"go.opentelemetry.io/otel/attribute"
2525
"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"
26+
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
2827
"go.opentelemetry.io/otel/trace"
2928
)
3029

@@ -37,11 +36,13 @@ type SpanOpt func(config *StartConfig)
3736

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

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)