Skip to content

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

Open
@MarcusDunn

Description

@MarcusDunn

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions