Debug an Asset Compute worker
Asset Compute workers can be debugged in several ways, from simple debug log statements, to attached VS Code as a remote debugger, to pulling logs for activations in Adobe I/O Runtime initiated from AEM as a Cloud Service.
Logging
The most basic form of debugging Asset Compute workers uses traditional console.log(..)
statements in the worker code. The console
JavaScript object is an implicit, global object so there is no need to import or require it, as it is always present in all contexts.
These log statements are available for review differently based on how the Asset Compute worker is executed:
- From
aio app run
, logs print to standard out and the Development Tool’s Activation Logs
- From
aio app test
, logs print to/build/test-results/test-worker/test.log
- Using
wskdebug
, logs statements print to the VS Code Debug Console (View > Debug Console), standard out
- Using
aio app logs
, log statements print to the activation log output
Remote debugging via attached debugger
The wskdebug npm module, supports attaching a debugger to Asset Compute workers, including the ability to set breakpoints in VS Code and step through the code.
Click-through of debugging an Asset Compute worker using wskdebug (No audio)
-
Ensure Docker Desktop and the supporting Docker images are installed and running
-
Close any active running instances of Development Tool.
-
Deploy the latest code using
aio app deploy
and record the deployed action name (name between the[...]
). This is used to update thelaunch.json
in step 8.code language-none ℹ Info: Deploying package [wkndAemAssetCompute-0.0.1]...
-
Start a new instance of Asset Compute Development Tool using the command
npx adobe-asset-compute devtool
-
In VS Code, tap the Debug icon in the left navigation
- If prompted, tap create a launch.json file > Node.js to create a new
launch.json
file. - Else, tap the Gear icon to the right of the Launch Program dropdown to open the existing
launch.json
in the editor.
- If prompted, tap create a launch.json file > Node.js to create a new
-
Add the following JSON object configuration to the
configurations
array:code language-json { "type": "pwa-node", "request": "launch", "name": "wskdebug", "attachSimplePort": 0, "runtimeExecutable": "wskdebug", "args": [ "wkndAemAssetCompute-0.0.1/__secured_worker", // Version must match your Asset Compute worker's version "${workspaceFolder}/actions/worker/index.js", // Points to your worker "-l", "--ngrok" ], "localRoot": "${workspaceFolder}", "remoteRoot": "/code", "outputCapture": "std", "timeout": 30000 }
-
Select the new wskdebug from the dropdown
-
Tap the green Run button to the left of wskdebug dropdown
-
Open
/actions/worker/index.js
and tap to the left of the line numbers to add break points 1. Navigate to the Asset Compute Development Tool Web browser window opened in step 6 -
Tap the Run button to execute the worker
-
Navigate back to VS Code, to
/actions/worker/index.js
and step through the code -
To exit the debug-able Development Tool, tap
Ctrl-C
in the terminal that rannpx adobe-asset-compute devtool
command in step 6
Accessing logs from Adobe I/O Runtime aio-app-logs
AEM as a Cloud Service leverages Asset Compute workers via Processing Profiles by directly invoking them in Adobe I/O Runtime. Because these invocations do not involve local development, their executions cannot be debugged using local tooling such as Asset Compute Development Tool or wskdebug. Instead, the Adobe I/O CLI can be be used to fetch logs from the worker executed in a particular workspace in Adobe I/O Runtime.
-
Ensure the workspace-specific environment variables are set via
AIO_runtime_namespace
andAIO_runtime_auth
, based on the workspace requiring debugging. -
From the command line, execute
aio app logs
- If the workspace is incurring heavy traffic, expand the number of activation logs via the
--limit
flag:$ aio app logs --limit=25
- If the workspace is incurring heavy traffic, expand the number of activation logs via the
-
The most recent (up to the provided
--limit
) activations logs are returned as the output of the command for review.