@@ -6,6 +6,8 @@ import { is_form_content_type, negotiate } from '../../../utils/http.js';
66import { HttpError , Redirect , ActionFailure , SvelteKitError } from '../../control.js' ;
77import { handle_error_and_jsonify } from '../utils.js' ;
88import { with_event } from '../../app/server/event.js' ;
9+ import { record_span } from '../../telemetry/record_span.js' ;
10+ import { get_tracer } from '../../telemetry/get_tracer.js' ;
911
1012/** @param {import('@sveltejs/kit').RequestEvent } event */
1113export function is_action_json_request ( event ) {
@@ -51,7 +53,7 @@ export async function handle_action_json_request(event, options, server) {
5153 check_named_default_separate ( actions ) ;
5254
5355 try {
54- const data = await call_action ( event , actions ) ;
56+ const data = await call_action ( event , actions , options . tracing ) ;
5557
5658 if ( __SVELTEKIT_DEV__ ) {
5759 validate_action_return ( data ) ;
@@ -139,9 +141,10 @@ export function is_action_request(event) {
139141/**
140142 * @param {import('@sveltejs/kit').RequestEvent } event
141143 * @param {import('types').SSRNode['server'] | undefined } server
144+ * @param {boolean } tracing
142145 * @returns {Promise<import('@sveltejs/kit').ActionResult> }
143146 */
144- export async function handle_action_request ( event , server ) {
147+ export async function handle_action_request ( event , server , tracing ) {
145148 const actions = server ?. actions ;
146149
147150 if ( ! actions ) {
@@ -164,7 +167,7 @@ export async function handle_action_request(event, server) {
164167 check_named_default_separate ( actions ) ;
165168
166169 try {
167- const data = await call_action ( event , actions ) ;
170+ const data = await call_action ( event , actions , tracing ) ;
168171
169172 if ( __SVELTEKIT_DEV__ ) {
170173 validate_action_return ( data ) ;
@@ -216,9 +219,10 @@ function check_named_default_separate(actions) {
216219/**
217220 * @param {import('@sveltejs/kit').RequestEvent } event
218221 * @param {NonNullable<import('types').ServerNode['actions']> } actions
222+ * @param {boolean } tracing
219223 * @throws {Redirect | HttpError | SvelteKitError | Error }
220224 */
221- async function call_action ( event , actions ) {
225+ async function call_action ( event , actions , tracing ) {
222226 const url = new URL ( event . request . url ) ;
223227
224228 let name = 'default' ;
@@ -247,7 +251,30 @@ async function call_action(event, actions) {
247251 ) ;
248252 }
249253
250- return with_event ( event , ( ) => action ( event ) ) ;
254+ const tracer = await get_tracer ( { is_enabled : tracing } ) ;
255+
256+ return record_span ( {
257+ name : 'sveltekit.action' ,
258+ tracer,
259+ attributes : {
260+ 'sveltekit.action.name' : name ,
261+ 'sveltekit.route.id' : event . route . id || 'unknown'
262+ } ,
263+ fn : async ( action_span ) => {
264+ const result = await with_event ( event , ( ) => action ( event ) ) ;
265+ if ( result instanceof ActionFailure ) {
266+ action_span . setAttributes ( {
267+ 'sveltekit.action.result.type' : 'failure' ,
268+ 'sveltekit.action.result.status' : result . status
269+ } ) ;
270+ } else {
271+ action_span . setAttributes ( {
272+ 'sveltekit.action.result.type' : 'success'
273+ } ) ;
274+ }
275+ return result ;
276+ }
277+ } ) ;
251278}
252279
253280/** @param {any } data */
0 commit comments