sveltejs / sveltejs/kit

OpenTelemetry: Add route id to the name of the actual root span

Open
#14,333 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

It is a very great thing that SvelteKit now has first-class support for OpenTelemetry, and it solves some problems we had in the past.

We use OpenTelemetry with the HTTP-Instrumentation (which is also included in the Auto-Instrumentation). Therefore, our root span is a span from this instrumentation, and for example, is named GET (the HTTP verb). In the past, we had a SvelteKit middleware that renamed this span and added the route id, for example, GET /(app)/some/route. This is part of the Semantic conventions for HTTP spans. The HTTP instrumentation cannot know the SvelteKit route id. Therefore, it must be updated later. For example, we need this information for better filtering and dashboard creation in Grafana.

But with the introduction of OpenTelemetry support in SvelteKit, I couldn't find a way to get a reference to the root span, to rename it myself. SvelteKit provides a root span in event.tracing.root, but this is only the first span that SvelteKit creates, and not the actual root span.

I've added a screenshot from one of our traces. The root span that is provided by SvelteKit is the sveltekit.handle.root span. We need to rename the topmost span GET to include the route id.

Image
Describe the proposed solution

One possible solution would be that SvelteKit somehow provides the actual root span of the HTTP instrumentation.

Another solution could be that SvelteKit updates the name of the root span itself.

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SvelteKit's event.tracing.root behavior and the HTTP instrumentation that creates the topmost GET span. Compare the proposed approaches—exposing the actual root span or renaming it—to determine the intended API, with completion indicated by the route id appearing in the root span name.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
observability-sre
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.