Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why otelhttptrace duplicate? #5562

Closed
zdyj3170101136 opened this issue May 11, 2024 · 6 comments · May be fixed by #5564
Closed

why otelhttptrace duplicate? #5562

zdyj3170101136 opened this issue May 11, 2024 · 6 comments · May be fixed by #5564
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttptrace

Comments

@zdyj3170101136
Copy link

in example:
https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go

client := http.Client{
		Transport: otelhttp.NewTransport(
			http.DefaultTransport,
			otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace {
				return otelhttptrace.NewClientTrace(ctx)
			}),
		),
	}

	bag, _ := baggage.Parse("username=donuts")
	ctx := baggage.ContextWithBaggage(context.Background(), bag)

	var body []byte

	tr := otel.Tracer("example/client")
	err = func(ctx context.Context) error {
		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")
		res, err := client.Do(req)
		if err != nil {
			panic(err)
		}
		body, err = io.ReadAll(res.Body)
		_ = res.Body.Close()

		return err
	}(ctx)

why func otelhttptrace.NewClientTrace have called twice?

which is correct?

@zdyj3170101136 zdyj3170101136 added area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttptrace labels May 11, 2024
@dmathieu
Copy link
Member

Both are not required, but they are there for the sake of the example (we could possibly document that only one is required).

The otelhttp transport will override the client trace from the context in case one is set:

if t.clientTrace != nil {
ctx = httptrace.WithClientTrace(ctx, t.clientTrace(ctx))
}

So setting in the client allows making sure there's one set for every HTTP request that client makes. Setting it in the context is the official recommended way from the httptrace example: https://pkg.go.dev/net/http/httptrace

@Cirilla-zmh
Copy link

@zdyj3170101136
Hello, I'm pleased to have the opportunity to share my perspective with you.

When no modifications are made, it appears that spans are being recorded twice the original count. This happens because two calls to WithClientTrace inject two ClientTrace instances into the current context, resulting in the same hook method being invoked twice. I believe this is unreasonable and perhaps we should address this duplication in the trace.WithClientTrace method through proxies or other means.

Here's the output after removing the registered ClientTrace instances from the transport:

{
        "Name": "http.dns",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "531b95b6360a4b3e",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "a8953109b2404d0a",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.051186+08:00",
        "EndTime": "2024-05-13T15:26:45.165453333+08:00",
        "Attributes": [
                {
                        "Key": "net.host.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost"
                        }
                },
                {
                        "Key": "http.dns.addrs",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.dns",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "180c386e06f73685",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "69dfdbace836c6a7",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.051187+08:00",
        "EndTime": "2024-05-13T15:26:45.165465541+08:00",
        "Attributes": [
                {
                        "Key": "net.host.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost"
                        }
                },
                {
                        "Key": "http.dns.addrs",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.connect",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "0cb4692159921a5a",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "a8953109b2404d0a",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.165493+08:00",
        "EndTime": "2024-05-13T15:26:45.166247666+08:00",
        "Attributes": [
                {
                        "Key": "http.remote",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.conn.start.network",
                        "Value": {
                                "Type": "STRING",
                                "Value": "tcp"
                        }
                },
                {
                        "Key": "http.conn.done.addr",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.conn.done.network",
                        "Value": {
                                "Type": "STRING",
                                "Value": "tcp"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.connect",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "a9f2d73a09d2c14e",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "69dfdbace836c6a7",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.165499+08:00",
        "EndTime": "2024-05-13T15:26:45.166255125+08:00",
        "Attributes": [
                {
                        "Key": "http.remote",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.conn.start.network",
                        "Value": {
                                "Type": "STRING",
                                "Value": "tcp"
                        }
                },
                {
                        "Key": "http.conn.done.addr",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.conn.done.network",
                        "Value": {
                                "Type": "STRING",
                                "Value": "tcp"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.getconn",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "a8953109b2404d0a",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "20b7c0cadbf75f5b",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.050994+08:00",
        "EndTime": "2024-05-13T15:26:45.166275+08:00",
        "Attributes": [
                {
                        "Key": "net.host.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost:7777"
                        }
                },
                {
                        "Key": "http.remote",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.local",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:62318"
                        }
                },
                {
                        "Key": "http.conn.reused",
                        "Value": {
                                "Type": "BOOL",
                                "Value": false
                        }
                },
                {
                        "Key": "http.conn.wasidle",
                        "Value": {
                                "Type": "BOOL",
                                "Value": false
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 2,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.getconn",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "69dfdbace836c6a7",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.050996+08:00",
        "EndTime": "2024-05-13T15:26:45.166278875+08:00",
        "Attributes": [
                {
                        "Key": "net.host.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost:7777"
                        }
                },
                {
                        "Key": "http.remote",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:7777"
                        }
                },
                {
                        "Key": "http.local",
                        "Value": {
                                "Type": "STRING",
                                "Value": "127.0.0.1:62318"
                        }
                },
                {
                        "Key": "http.conn.reused",
                        "Value": {
                                "Type": "BOOL",
                                "Value": false
                        }
                },
                {
                        "Key": "http.conn.wasidle",
                        "Value": {
                                "Type": "BOOL",
                                "Value": false
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 2,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.headers",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "98deb44d804cde94",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "20b7c0cadbf75f5b",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.166472+08:00",
        "EndTime": "2024-05-13T15:26:45.166528083+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.headers",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "e8f9fe57e574bfef",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.166484+08:00",
        "EndTime": "2024-05-13T15:26:45.166533917+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.send",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "43427737bb2f9106",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "20b7c0cadbf75f5b",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.166533+08:00",
        "EndTime": "2024-05-13T15:26:45.166537708+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.send",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "1106d7dbc4d2331e",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.166535+08:00",
        "EndTime": "2024-05-13T15:26:45.166538334+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.receive",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "2872a6caec82c2e1",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "20b7c0cadbf75f5b",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.168494+08:00",
        "EndTime": "2024-05-13T15:26:45.1686265+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "http.receive",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "462db46b96c991c7",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.168498+08:00",
        "EndTime": "2024-05-13T15:26:45.16862875+08:00",
        "Attributes": null,
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 0,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/otel/instrumentation/httptrace",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "HTTP GET",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "20b7c0cadbf75f5b",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 3,
        "StartTime": "2024-05-13T15:26:45.050648+08:00",
        "EndTime": "2024-05-13T15:26:45.168633334+08:00",
        "Attributes": [
                {
                        "Key": "http.method",
                        "Value": {
                                "Type": "STRING",
                                "Value": "GET"
                        }
                },
                {
                        "Key": "http.url",
                        "Value": {
                                "Type": "STRING",
                                "Value": "http://localhost:7777/hello"
                        }
                },
                {
                        "Key": "net.peer.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "localhost"
                        }
                },
                {
                        "Key": "net.peer.port",
                        "Value": {
                                "Type": "INT64",
                                "Value": 7777
                        }
                },
                {
                        "Key": "http.status_code",
                        "Value": {
                                "Type": "INT64",
                                "Value": 200
                        }
                },
                {
                        "Key": "http.response_content_length",
                        "Value": {
                                "Type": "INT64",
                                "Value": 14
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 4,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
                "Version": "0.51.0",
                "SchemaURL": ""
        }
}
{
        "Name": "say hello",
        "SpanContext": {
                "TraceID": "38a6eb199926883136b5394ac83f262c",
                "SpanID": "d5393c24508964e0",
                "TraceFlags": "01",
                "TraceState": "",
                "Remote": false
        },
        "Parent": {
                "TraceID": "00000000000000000000000000000000",
                "SpanID": "0000000000000000",
                "TraceFlags": "00",
                "TraceState": "",
                "Remote": false
        },
        "SpanKind": 1,
        "StartTime": "2024-05-13T15:26:45.050584+08:00",
        "EndTime": "2024-05-13T15:26:45.168635125+08:00",
        "Attributes": [
                {
                        "Key": "peer.service",
                        "Value": {
                                "Type": "STRING",
                                "Value": "ExampleService"
                        }
                }
        ],
        "Events": null,
        "Links": null,
        "Status": {
                "Code": "Unset",
                "Description": ""
        },
        "DroppedAttributes": 0,
        "DroppedEvents": 0,
        "DroppedLinks": 0,
        "ChildSpanCount": 5,
        "Resource": [
                {
                        "Key": "service.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "unknown_service:___1go_build_go_opentelemetry_io_contrib_instrumentation_net_http_httptrace_otelhttptrace_example_client"
                        }
                },
                {
                        "Key": "telemetry.sdk.language",
                        "Value": {
                                "Type": "STRING",
                                "Value": "go"
                        }
                },
                {
                        "Key": "telemetry.sdk.name",
                        "Value": {
                                "Type": "STRING",
                                "Value": "opentelemetry"
                        }
                },
                {
                        "Key": "telemetry.sdk.version",
                        "Value": {
                                "Type": "STRING",
                                "Value": "1.26.0"
                        }
                }
        ],
        "InstrumentationLibrary": {
                "Name": "example/client",
                "Version": "",
                "SchemaURL": ""
        }
}

@dmathieu
Copy link
Member

Ah yes, WithClientTrace appends new tracers, it does not replace.
There is no way to remove already appended client tracers though. So we can't "fix" this per-se.

This probably warrants a documentation change, but the only real fix here is to only use one of the two config methods, not both.

@Cirilla-zmh
Copy link

There is no way to remove already appended client tracers though. So we can't "fix" this per-se.

This probably warrants a documentation change, but the only real fix here is to only use one of the two config methods, not both.

Thanks for your reply.

Maybe we can get do ContextClientTrace while WithClientTrace and replace the fields of the old tracer rather than append a new one?

@Cirilla-zmh
Copy link

Cirilla-zmh commented May 13, 2024

@dmathieu Sorry, my bad. WithClientTrace is actually an SDK from Golang, and it looks like making a straight-up replacement is pretty tough.

Thanks again for your getting back.

@dmathieu
Copy link
Member

Closing, as this issue seems to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: instrumentation Related to an instrumentation package bug Something isn't working instrumentation: otelhttptrace
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants