Skip to content

Commit 1d06059

Browse files
optionally load tracing, add remote functions
1 parent 874717f commit 1d06059

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/kit/src/exports/vite/dev/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'node:fs';
1+
import fs, { existsSync } from 'node:fs';
22
import path from 'node:path';
33
import process from 'node:process';
44
import { URL } from 'node:url';
@@ -502,7 +502,9 @@ export async function dev(vite, vite_config, svelte_config) {
502502
return;
503503
}
504504

505-
await vite.ssrLoadModule(tracing.server);
505+
if (existsSync(tracing.server)) {
506+
await vite.ssrLoadModule(tracing.server);
507+
}
506508

507509
// we have to import `Server` before calling `set_assets`
508510
const { Server } = /** @type {import('types').ServerModule} */ (

packages/kit/src/runtime/server/remote.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,32 @@ import { normalize_error } from '../../utils/error.js';
1212
import { check_incorrect_fail_use } from './page/actions.js';
1313
import { DEV } from 'esm-env';
1414
import { get_event_state } from './event-state.js';
15+
import { record_span } from '../telemetry/record_span.js';
16+
import { merge_tracing } from '../utils.js';
17+
18+
/** @type {typeof handle_remote_call_internal} */
19+
export async function handle_remote_call(event, options, manifest, id) {
20+
return record_span({
21+
name: 'sveltekit.remote.call',
22+
attributes: {
23+
'sveltekit.remote.call.id': id
24+
},
25+
fn: async (current) => {
26+
const traced_event = merge_tracing(event, current);
27+
return with_event(traced_event, () =>
28+
handle_remote_call_internal(event, options, manifest, id)
29+
);
30+
}
31+
});
32+
}
1533

1634
/**
1735
* @param {RequestEvent} event
1836
* @param {SSROptions} options
1937
* @param {SSRManifest} manifest
2038
* @param {string} id
2139
*/
22-
export async function handle_remote_call(event, options, manifest, id) {
40+
export async function handle_remote_call_internal(event, options, manifest, id) {
2341
const [hash, name, prerender_args] = id.split('/');
2442
const remotes = manifest._.remotes;
2543

@@ -155,13 +173,27 @@ export async function handle_remote_call(event, options, manifest, id) {
155173
}
156174
}
157175

176+
/** @type {typeof handle_remote_form_post_internal} */
177+
export async function handle_remote_form_post(event, manifest, id) {
178+
return record_span({
179+
name: 'sveltekit.remote.form.post',
180+
attributes: {
181+
'sveltekit.remote.form.post.id': id
182+
},
183+
fn: async (current) => {
184+
const traced_event = merge_tracing(event, current);
185+
return with_event(traced_event, () => handle_remote_form_post_internal(event, manifest, id));
186+
}
187+
});
188+
}
189+
158190
/**
159191
* @param {RequestEvent} event
160192
* @param {SSRManifest} manifest
161193
* @param {string} id
162194
* @returns {Promise<ActionResult>}
163195
*/
164-
export async function handle_remote_form_post(event, manifest, id) {
196+
async function handle_remote_form_post_internal(event, manifest, id) {
165197
const [hash, name, action_id] = id.split('/');
166198
const remotes = manifest._.remotes;
167199
const module = await remotes[hash]?.();

0 commit comments

Comments
 (0)