feat: As a user, I want to be able to choose "root span name", so that I can better distringuish traces
- Dominant language
- Lua
- Stars
- 17.1k
- Forks
- 2.9k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 63
Description
# Clarification/Context
I have Tempo+Grafana setup, traces are correctly sent to the OTLP endpoint. However, I'd like the "Name" column (in Grafana) to show `"http.target"` / `"url.uri"` (of span attributes) and not `"http.route"`. Because, for multiple endpoints, I'd get the same "Name", e.g., `/api/admin/*`. But it's currently hardcoded in [opentelemetry.lua#L417](https://github.com/apache/apisix/blob/master/apisix/plugins/opentelemetry.lua#L417).
As mentioned [here](https://github.com/apache/apisix/issues/11990#issuecomment-2880664833), frontend application should own/be the parent span. However, when no there is no frontend application, it's not the case. And I'd like to be able to better distinguish one request from another.
# Suggestion
What if we add another parameter to `opentelemetry` plug-in, `span_name_strategy`?
```json
{
"span_name_strategy": "path|target"
}
```
(pseudocode)
```lua
-- Either `metadata_schema` or `schema`...
local schema = {
type = "object",
properties = {
-- ...
span_name_strategy = {
type = "string",
enum = {"path", "target"},
default = "path",
},
-- ...
}
-- ...
local function resolve_span_name(conf, api_ctx)
local span_name_strategy = conf.span_name_strategy or "route"
if strategy == "target" then
return api_ctx.var.uri
end
return api_ctx.curr_req_matched._path
end
-- ...
-- Closer to line 417...
local span_name_suffix = resolve_span_name_suffix(plugin_info, api_ctx)
span_name = span_name .. " " .. span_name_suffix
```
## WIP PR
https://github.com/apache/apisix/pull/13749
I'm not really sure how to affect only root span, and not children.
Contributor guide
Research direction
Start by reading the root-span naming logic around line 417 of apisix/plugins/opentelemetry.lua and review the linked WIP PR #13749. Trace how the opentelemetry plugin distinguishes root and child spans, then verify the requested strategy configuration, its default behavior, and that the resulting name changes only the root span.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100