How-To: Debug Dapr applications with Visual Studio Code
When developing Dapr applications, you typically use the Dapr CLI to start your daprized service similar to this:
One approach to attaching the debugger to your service is to first run daprd with the correct arguments from the command line and then launch your code and attach the debugger. While this is a perfectly acceptable solution, it does require a few extra steps and some instruction to developers who might want to clone your repo and hit the “play” button to begin debugging.
If your application is a collection of microservices, each with a Dapr sidecar, it will be useful to debug them together in Visual Studio Code. This page will use the hello world quickstart to showcase how to configure VSCode to debug multiple Dapr application using .
Prerequisites
- Install the . You will be using the tasks it offers later on.
- Optionally clone the
The file contains launch configurations for a VS Code debug run. This file defines what will launch and how it is configured when the user begins debugging. Configurations are available for each programming language in the .
Scaffold debugging configuration
The offers built-in scaffolding to generate launch.json
and tasks.json
for you.
In the case of the hello world quickstart, two applications are launched, each with its own Dapr sidecar. One is written in Node.JS, and the other in Python. You’ll notice each configuration contains a daprd run
preLaunchTask and a daprd stop
postDebugTask.
Each configuration requires a request
, type
and name
. These parameters help VSCode identify the task configurations in the .vscode/task.json
files.
name
is a unique name for the configuration. This is used for compound configurations when calling multiple configurations in your project.${workspaceFolder}
is a VS Code variable reference. This is the path to the workspace opened in VS Code.- The
preLaunchTask
andpostDebugTask
parameters refer to the program configurations run before and after launching the application. See step 2 on how to configure these.
For more information on VSCode debugging parameters see VS Code launch attributes.
Step 2: Configure task.json
For each task defined in .vscode/launch.json
, a corresponding task definition must exist in .vscode/task.json
.
For the quickstart, each service needs a task to launch a Dapr sidecar with the daprd
type, and a task to stop the sidecar with daprd-down
. The parameters appId
, httpPort
, metricsPort
, label
and type
are required. Additional optional parameters are available, see the .
For this example the compound configuration is:
Step 4: Launch your debugging session
You can now run the applications in debug mode by finding the compound command name you have defined in the previous step in the VS Code debugger:
You are now debugging multiple applications with Dapr!
Below are the supported parameters for VS Code tasks. These parameters are equivalent to daprd
arguments as detailed in :