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

Ktor Client Span names should include url.template when available #13570

Open
MarcusDunn opened this issue Mar 21, 2025 · 1 comment
Open

Ktor Client Span names should include url.template when available #13570

MarcusDunn opened this issue Mar 21, 2025 · 1 comment
Labels
enhancement New feature or request needs triage New issue that requires triage

Comments

@MarcusDunn
Copy link

MarcusDunn commented Mar 21, 2025

Is your feature request related to a problem? Please describe.

When using a Ktor client with https://ktor.io/docs/client-resources.html

@Resource("/api/example/{id}")
data class Example(val id: Int)

HttpClient().get(Example(0))

I would expect the span name to be GET /api/example/{id} per https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#name

I would also expect that the url.template attribute is populated with /api/example/{id} (This attribute is in development so I'm not sure on this projects policy on this)

The current span names makes trawling though traces difficult

Describe the solution you'd like

Instrumentation names the spans and populates url.template when the resources plugin is used.

Describe alternatives you've considered

  1. Accept the span names are what they are.

Additional context

I would be happy to take a stab at implementing this. I would need some guidance on where to start however (or if this is possible)

I think the solution to would be to add String getUrlTemplate(REQUEST request) to HttpCommonAttributesGetter and have the ktor client implement it. To avoid massive changes I would default getUrlTemplate to null. Finally I would have to modify HttpSpanNameExtractor to use getUrlTemplate to name the span. I would also want to set url.template in HttpCommonAttributesExtractor (again using getUrlTemplate)

@MarcusDunn MarcusDunn added enhancement New feature or request needs triage New issue that requires triage labels Mar 21, 2025
@MarcusDunn
Copy link
Author

this is somewhat discussed in #10952 in the context of OkHttp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New issue that requires triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant