@@ -313,21 +313,34 @@ func (srv *Server) Run() error {
313
313
// Create WASM Callback Router
314
314
router := callbacks .New (callbacks.Config {
315
315
PreFunc : func (namespace , op string , data []byte ) ([]byte , error ) {
316
+ // Debug logging of callback
317
+ srv .log .WithFields (logrus.Fields {
318
+ "namespace" : namespace ,
319
+ "operation" : op ,
320
+ }).Debugf ("CallbackRouter called" )
321
+
316
322
// Trace logging of callback
317
323
srv .log .WithFields (logrus.Fields {
318
324
"namespace" : namespace ,
319
- "function" : op ,
325
+ "operation" : op ,
320
326
}).Tracef ("CallbackRouter called with payload - %s" , data )
321
327
return []byte ("" ), nil
322
328
},
323
329
PostFunc : func (r callbacks.CallbackResult ) {
324
330
// Measure Callback Execution time and counts
325
331
srv .stats .Callbacks .WithLabelValues (fmt .Sprintf ("%s:%s" , r .Namespace , r .Operation )).Observe (r .EndTime .Sub (r .StartTime ).Seconds ())
326
332
333
+ // Debug logging of callback results
334
+ srv .log .WithFields (logrus.Fields {
335
+ "namespace" : r .Namespace ,
336
+ "operation" : r .Operation ,
337
+ "error" : r .Err ,
338
+ }).Debugf ("Callback returned result after %f seconds" , r .EndTime .Sub (r .StartTime ).Seconds ())
339
+
327
340
// Trace logging of callback results
328
341
srv .log .WithFields (logrus.Fields {
329
342
"namespace" : r .Namespace ,
330
- "function" : r .Operation ,
343
+ "operation" : r .Operation ,
331
344
"input" : r .Input ,
332
345
"error" : r .Err ,
333
346
}).Tracef ("Callback returned result after %f seconds with output - %s" , r .EndTime .Sub (r .StartTime ).Seconds (), r .Output )
@@ -336,7 +349,7 @@ func (srv *Server) Run() error {
336
349
if r .Err != nil {
337
350
srv .log .WithFields (logrus.Fields {
338
351
"namespace" : r .Namespace ,
339
- "function" : r .Operation ,
352
+ "operation" : r .Operation ,
340
353
}).Warnf ("Callback call resulted in error after %f seconds - %s" , r .EndTime .Sub (r .StartTime ).Seconds (), r .Err )
341
354
}
342
355
},
@@ -485,18 +498,20 @@ func (srv *Server) Run() error {
485
498
486
499
// Schedule tasks for scheduled functions
487
500
if r .Type == "scheduled_task" {
501
+ // Capture function name to avoid scope issues
502
+ fname := r .Function
488
503
srv .log .Infof ("Scheduling custom task for function %s with interval of %d" , r .Function , r .Frequency )
489
504
id , err := srv .scheduler .Add (& tasks.Task {
490
505
Interval : time .Duration (r .Frequency ) * time .Second ,
491
506
TaskFunc : func () error {
492
507
now := time .Now ()
493
- srv .log .Tracef ("Executing Scheduled Function %s" , r . Function )
494
- _ , err := srv .runWASM (r . Function , "handler" , []byte ("" ))
508
+ srv .log .Tracef ("Executing Scheduled Function %s" , fname )
509
+ _ , err := srv .runWASM (fname , "handler" , []byte ("" ))
495
510
if err != nil {
496
- srv .stats .Tasks .WithLabelValues (r . Function ).Observe (time .Since (now ).Seconds ())
511
+ srv .stats .Tasks .WithLabelValues (fname ).Observe (time .Since (now ).Seconds ())
497
512
return err
498
513
}
499
- srv .stats .Tasks .WithLabelValues (r . Function ).Observe (time .Since (now ).Seconds ())
514
+ srv .stats .Tasks .WithLabelValues (fname ).Observe (time .Since (now ).Seconds ())
500
515
return nil
501
516
},
502
517
})
@@ -511,9 +526,13 @@ func (srv *Server) Run() error {
511
526
// Setup callbacks for function to function calls
512
527
if r .Type == "function" {
513
528
srv .log .Infof ("Registering Function to Function callback for %s" , r .Function )
514
- router .RegisterCallback ("function" , r .Function , func (b []byte ) ([]byte , error ) {
515
- return srv .runWASM (r .Function , "handler" , b )
516
- })
529
+ // Capture r in local values to avoid scope issues
530
+ fname := r .Function
531
+ f := func (b []byte ) ([]byte , error ) {
532
+ srv .log .Infof ("Executing Function to Function callback for %s" , fname )
533
+ return srv .runWASM (fname , "handler" , b )
534
+ }
535
+ router .RegisterCallback ("function" , fname , f )
517
536
}
518
537
}
519
538
0 commit comments