Skip to content

feat: Initial tracing setup (peer deps + utils) #13899

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

elliott-with-the-longest-name-on-github
Copy link
Contributor

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented Jun 17, 2025

image

Adds spans to load (on the server), server actions, and handle/resolve. It also adds a tracing object with enabled, root, and current to the RequestEvent, ServerLoadEvent, and LoadEvent types. This means you can get access to a span to annotate it pretty much anywhere -- including using getRequestEvent (this could be quite nice for library integrations!).

We're punting on clientside tracing for now, as we do not feel the o11y community has sufficiently converged on approaches (see https://github.com/open-telemetry/community/blob/main/projects/browser-phase-1.md). When OTEL provides a stable and truly browser-native tracing platform, we'll be all over it.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link
Contributor Author

elliott-with-the-longest-name-on-github commented Jun 17, 2025

Copy link

changeset-bot bot commented Jun 18, 2025

🦋 Changeset detected

Latest commit: 4b64316

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github changed the base branch from 06-17-chore_add_universal_ids_to_client_nodes to graphite-base/13899 June 18, 2025 22:53
@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github changed the base branch from graphite-base/13899 to main June 18, 2025 22:53
Copy link

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. As discussed on Slack, it might be nice if users had the ability to modify the root span (e.g. via a requestHook).

Copy link
Contributor

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks a lot for adding this!

Just had a minor concern about performance of dynamically importing @opentelemetry/api multiple times but I think overall, the implementation is great!

Comment on lines 33 to 38
span.recordException({
name: 'HttpError',
message: error.body.message
});
Copy link
Contributor

@Lms24 Lms24 Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a HttpError also have a stack? If so, would be cool to also record the stack trace.

Copy link
Contributor

@Lms24 Lms24 Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, I'm not 100% sure if this applies here but in our SDK, when we capture HttpErrors, we ignore 4xx errors because usually you don't want to record exceptions for bad requests, 404s, etc. Might be worth a thought if they are valuable or too noisy but happy to leave the call up to you!

https://github.com/getsentry/sentry-javascript/blob/8beaa4ea602d3517c272f07b8546325059bcfc21/packages/sveltekit/src/client/load.ts#L23-L38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lemme think about this one -- not sure if we should just exclude all 400s or give users the ability to filter status codes. My initial feeling is just exclude 400s and see if anyone ever asks for the ability to see them

Copy link
Member

@benmccann benmccann Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably share the logic contained in #13848

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think I agree -- this is just about setting the status of the span, not whether we capture the span at all. I adjusted the logic to only set an error status on >=500; otherwise it's captured as a normal span

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github force-pushed the elliott/init-tracing branch 3 times, most recently from c8c11f9 to eca0d11 Compare July 15, 2025 19:22
@svelte-docs-bot
Copy link

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github marked this pull request as ready for review July 17, 2025 04:01
@eltigerchino eltigerchino added the feature / enhancement New feature or request label Jul 23, 2025
…13900)

* feat: Add tracing to `load`, server actions, and `handle`/`resolve`

* feat: add universal IDs to client nodes

* approve otp dep build

* add links for docs

* since tags

* clarify

* explain util

* import the rest of the types through jsdoc import statements

* generate types

---------

Co-authored-by: Chew Tee Ming <chew.tee.ming@nindatech.com>
@eltigerchino
Copy link
Member

eltigerchino commented Jul 23, 2025

Thanks! This looks good. I think all we need is a changeset and some documentation on how to get started. The instructions could be similar to the setup in the demo of #13900 (comment) or we might want to try and get something like #13776 merged next

cc: @manuel3108 @AdrianGonz97 would we want to add some kind of OpenTelemetry or Sentry add-on to the Svelte CLI in the future to make the setup more seamless?

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! mostly looks good but I think we can avoid passing tracer around etc

/**
* Whether to enable server-side [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), and [form actions](https://svelte.dev/docs/kit/form-actions).
* @default undefined
* @since 2.26.0 // TODO: update this before publishing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO


/**
* Access to spans for tracing. If tracing is not enabled or the function is being run in the browser, these spans will do nothing.\
* @since 2.26.0 // TODO: update this before publishing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO


/**
* Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
* @since 2.26.0 // TODO: update this before publishing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also TODO

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful 😍

@Rich-Harris
Copy link
Member

nervous about that test failure, not sure why that's happening suddenly

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rescinding my earlier approval because i was reminded that this should probably have some docs

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

Successfully merging this pull request may close these issues.

6 participants