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

Nested http spans from different modules #5572

Closed
amirrmonfared opened this issue May 14, 2024 · 2 comments
Closed

Nested http spans from different modules #5572

amirrmonfared opened this issue May 14, 2024 · 2 comments
Labels
area: instrumentation Related to an instrumentation package instrumentation: otelhttptrace

Comments

@amirrmonfared
Copy link

Description

Hi team!

We have different API modules implementing interfaces that are wrapped inside a caller to do an iteration on those modules and calling the inner APIs. The spans are propagating as expected except one thing which is the spans from different API modules are getting nested as children into each other on each iteration and it will continue until the loops end and in the next loop iteration again the same thing will happen but these loops will never be a child and only each iteration will make the nested children.

Environment

  • Go Version: [1.21]
  • otelhttptrace version: v0.45.0

Steps To Reproduce

You can check the code on how we set the tracing and you can do a loop on HTTP calls from different modules that are using the same function on every httpClient initialization

This SetTracingTransport is called on every API module that uses one parent HTTP client and copy to make their client

func SetTracingTransport(client Client, spanName string, isTracingEnabled bool) Client {
	if !isTracingEnabled {
		return client
	}

	costumClient, ok := client.(*costumClient)
	if !ok || costumClient.client == nil || costumClient.tracingEnabled {
		return client
	}

	updatedCostumClient:= *costumClient
	updatedCostumClient.client.Transport = otelhttp.NewTransport(
		updatedCostumClient.client.Transport,
		otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string {
			return spanName + "/HTTP " + r.Method
		}))
	updatedCostumClient.tracingEnabled = true

	return &updatedCostumClient
}

Expected behavior

We expect each API call have it's own traces instead of being a child of another API

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

This is the expected behavior. Distributed tracing propagation allows marking spans from sub-services as childs of the parent one.
You can use the WithPublicEndpoint, and WithPublicEndpointFn options when you configure otelhttp to mark specific requests as not being childs of the propagated trace.
They will be a root span, with the parent becoming a link.

@dmathieu dmathieu added question Further information is requested and removed bug Something isn't working question Further information is requested labels May 14, 2024
@dmathieu
Copy link
Member

Closing, as my previous comment should answer the question. Feel free to comment again if that's not the case.

@dmathieu dmathieu closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
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 instrumentation: otelhttptrace
Projects
None yet
Development

No branches or pull requests

2 participants