From 852c34db2ca5c8b75bbca1f560db2e6cb76339ff Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Mon, 13 May 2024 10:25:43 +0200 Subject: [PATCH 1/5] fix otelhttptrace example to avoid duplicating the generated data --- .../http/httptrace/otelhttptrace/example/client/client.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go index 62630c0d537..85225fafbc3 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go @@ -58,12 +58,7 @@ func main() { flag.Parse() client := http.Client{ - Transport: otelhttp.NewTransport( - http.DefaultTransport, - otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { - return otelhttptrace.NewClientTrace(ctx) - }), - ), + Transport: otelhttp.NewTransport(http.DefaultTransport), } bag, _ := baggage.Parse("username=donuts") From 8bdd01a2176ac280582a0e9650cfe5c483caf255 Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Mon, 13 May 2024 10:39:16 +0200 Subject: [PATCH 2/5] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6fb1b6454a..ac731970c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The gRPC trace filter functions `Any`, `All`, `None`, `Not`, `MethodName`, `MethodPrefix`, `FullMethodName`, `ServiceName`, `ServicePrefix` and `HealthCheck` for interceptor are moved to `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/filters/interceptor`. With this change, the filters in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` are now working for stats handler. (#5196) +### Fixed + +- The double setup in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace/example` that caused duplicate traces. (#5564) + ### Deprecated - The `InterceptorFilter` type in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` is deprecated. (#5196) From 3bccf0321c890ee8a9a7fe948ef3df6073c3ae3b Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Tue, 14 May 2024 10:37:48 +0200 Subject: [PATCH 3/5] switch example to use our own httptrace option --- .../http/httptrace/otelhttptrace/example/client/client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go index 85225fafbc3..757128f2b17 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go @@ -58,7 +58,12 @@ func main() { flag.Parse() client := http.Client{ - Transport: otelhttp.NewTransport(http.DefaultTransport), + Transport: otelhttp.NewTransport( + http.DefaultTransport, + otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { + return otelhttptrace.NewClientTrace(ctx) + }), + ), } bag, _ := baggage.Parse("username=donuts") @@ -71,7 +76,6 @@ func main() { ctx, span := tr.Start(ctx, "say hello", trace.WithAttributes(semconv.PeerService("ExampleService"))) defer span.End() - ctx = httptrace.WithClientTrace(ctx, otelhttptrace.NewClientTrace(ctx)) req, _ := http.NewRequestWithContext(ctx, "GET", *url, nil) fmt.Printf("Sending request...\n") From 99488d8a6576c88a7e271e19a590d7ca85ff5672 Mon Sep 17 00:00:00 2001 From: dmathieu <42@dmathieu.com> Date: Tue, 14 May 2024 10:39:35 +0200 Subject: [PATCH 4/5] document why we use our own option --- .../net/http/httptrace/otelhttptrace/example/client/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go index 757128f2b17..45910b97664 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go @@ -60,6 +60,9 @@ func main() { client := http.Client{ Transport: otelhttp.NewTransport( http.DefaultTransport, + // By setting the otelhttptrace client in this transport, it can be + // injected into the context after the span is started, which makes the + // httptrace spans childs of the transport one. otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { return otelhttptrace.NewClientTrace(ctx) }), From 31e181fe8a6f9970ee33aa32c1a9cfff04fa36fa Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Thu, 30 May 2024 09:00:29 +0200 Subject: [PATCH 5/5] Update instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go Co-authored-by: Tyler Yahn --- .../net/http/httptrace/otelhttptrace/example/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go index 45910b97664..24a98265d4e 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go @@ -62,7 +62,7 @@ func main() { http.DefaultTransport, // By setting the otelhttptrace client in this transport, it can be // injected into the context after the span is started, which makes the - // httptrace spans childs of the transport one. + // httptrace spans children of the transport one. otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { return otelhttptrace.NewClientTrace(ctx) }),