Skip to content

Commit

Permalink
Improve logging for runtime init initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
joe4dev committed Oct 16, 2023
1 parent 6b9d9a6 commit 9fabdc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 1 addition & 3 deletions cmd/localstack/custom_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate interop.Server, logCollecto
functionVersion := GetEnvOrDie("AWS_LAMBDA_FUNCTION_VERSION") // default $LATEST
_, _ = fmt.Fprintf(logCollector, "START RequestId: %s Version: %s\n", invokeR.InvokeId, functionVersion)

// TODO: Set X-Ray trace metadata or call .Reserve before invoke
invokeStart := time.Now()
err = server.Invoke(invokeResp, &interop.Invoke{
ID: invokeR.InvokeId,
InvokedFunctionArn: invokeR.InvokedFunctionArn,
Payload: strings.NewReader(invokeR.Payload), // r.Body,
NeedDebugLogs: true,

TraceID: invokeR.TraceId,
TraceID: invokeR.TraceId,
// TODO: set correct segment ID from request
//LambdaSegmentID: "LambdaSegmentID", // r.Header.Get("X-Amzn-Segment-Id"),
//CognitoIdentityID: "",
Expand Down
17 changes: 9 additions & 8 deletions cmd/localstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,24 @@ func main() {
}
go RunHotReloadingListener(interopServer, lsOpts.HotReloadingPaths, fileWatcherContext)

// start runtime init
// start runtime init. It is important to start `InitHandler` synchronously because we need to ensure the
// notification channels and status fields are properly initialized before `AwaitInitialized`
log.Debugln("Starting runtime init.")
InitHandler(sandbox.LambdaInvokeAPI(), GetEnvOrDie("AWS_LAMBDA_FUNCTION_VERSION"), int64(invokeTimeoutSeconds), bootstrap) // TODO: replace this with a custom init

log.Infoln("Await Initialized ...")
log.Debugln("Awaiting initialization of runtime init.")
if err := interopServer.delegate.AwaitInitialized(); err != nil {
log.Errorln("TODO: send execution environment error status to LocalStack")
// TODO: distinguish between ErrInitResetReceived and ErrInitDoneFailed
// Error cases: ErrInitDoneFailed or ErrInitResetReceived
log.Errorln("Runtime init failed to initialize: " + err.Error() + ". Exiting.")
if err := interopServer.localStackAdapter.SendStatus(Error, []byte{}); err != nil {
log.Fatalln("TODO: handle LocalStack not reachable and abort")
log.Fatalln("Failed to send init error to LocalStack " + err.Error() + ". Exiting.")
}
return
}
log.Infoln("Initialized done. Sending status ready to LocalStack")

log.Infoln("Send ready status to LocalStack")
log.Debugln("Completed initialization of runtime init. Sending status ready to LocalStack.")
if err := interopServer.localStackAdapter.SendStatus(Ready, []byte{}); err != nil {
log.Fatalln("TODO: handle LocalStack not reachable and abort")
log.Fatalln("Failed to send status ready to LocalStack " + err.Error() + ". Exiting.")
}

<-exitChan
Expand Down

0 comments on commit 9fabdc9

Please sign in to comment.