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

Draft
wants to merge 1 commit 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

Adds @opentelemetry/api@^1.0.0 as an optional peer dependency of SvelteKit, and adds some utility functions we'll use to add first-party tracing support.

As of this PR, adding @opentelemetry/api to your project will do nothing.


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

⚠️ No Changeset found

Latest commit: 1472161

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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!

import { noop_tracer } from './noop.js';
import * as load_otel from './load_otel.js';

describe('validateHeaders', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If I had to guess, this should be

Suggested change
describe('validateHeaders', () => {
describe('get_tracer', () => {

* @returns {Promise<T>}
*/
export async function record_span({ name, tracer, attributes, fn }) {
const SpanStatusCode = await load_status_code();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since load_status_code always dynamically imports @opentelemetry/api, this might be a performance issue. I'm not 100% sure though because I don't know if dynamic imports are cached. If they are, no problem, if not, you could manually cache the imported module instead instead.

Comment on lines +33 to +36
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants