Debugging Dapr application using Tye tool
Tags: dapr, tye, dotnetcore, azure
Published: 2020-03-31 14:19:37

---
title: Debugging Dapr application using Tye tool
published: true
description: This article shows you how to debug the Dapr application using Tye
tags: dapr,tye,dotnetcore,azure
---

Currently, Microsoft has announced and published `Dapr` to simplify the infrastructure tasks on local development and Kubernetes. It built for a developer who only wants to focus on the development of the application which inherently has a lot of complex business logic. 

> Dapr - An event-driven, portable runtime for building microservices on cloud and edge. See more at https://dapr.io

But with `Dapr`, developers also need to care about how to run and compose docker images and a lot of Helm charts which are really complex too. So recently, they have published another tooling with named `tye`.

> Tye - A tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with minimal configuration. See more at https://github.com/dotnet/tye

As a developer, we want to build a great application with the best behavior and usability for end-users. But to build something that great also comes up with a lot of trouble when we are trying to find and fix bugs in the application. Normally, we are using a debug tool to overcome that obstacle. 

At the moment, some guys at Microsoft have published some of the Visual Code extensions for [debug the Dapr app](https://github.com/dapr/docs/tree/master/howto/vscode-debugging-daprd). And one question that just comes to my mind that whether we can debug it using Visual Studio (forgive me because of my habit of using Visual Studio for a long time, and one more reason is using Resharper to increase my productivity in coding and refactoring codes). So I got no clue to find the way to debug the Dapr app on my Visual Studio so far.

But this week, when some of my colleagues at the company keeps talking a lot about `tye` - a tool which helps to simplify the development with `Docker` and without need to use `docker-compose` as well as `Helm` chart. After came home, I gave it a try and found out some of the interesting features of it. I spent sometimes to deep dive into it and raised some questions at [its Github repository](https://github.com/dotnet/tye/issues/246) as well as doing some of [the practice with Dapr](https://github.com/thangchung/practical-dapr). Thank you [@davidfowl](https://twitter.com/davidfowl) for his passion to explain and guide me to start with `tye`. By walking through its documentation, I found out the way to debug the Dapr apps with this new tool. The remaining of this article will show you how to debug the Dapr application with it.

First off, we start with the high-level architecture of my application as below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pwr4etxlxbfkj8p11btb.jpg)

> Plz, forget ports inside the application on the picture above

The project structure is following

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ut0p5bcg8xr1nazzq0n4.JPG)

In this article, I will show you how to debug the `inventory-api` which is hosted as the gRPC protocol on Dapr gRPC Server. And it is called `product-catalog-api`.

The relationship of how our applications, `tye`, and `Dapr` as below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/25bj28fpfwf03xxd9b7l.JPG)

We have `tye.yaml` file at the root of the project as below

```yaml
name: practical-dapr
extensions:
- name: dapr
registry: dapracr.azurecr.io
services:
- name: sqlserver
  image: mcr.microsoft.com/mssql/server:2017-latest
  env:
    - name: SA_PASSWORD
      value: "P@ssw0rd"
    - name: ACCEPT_EULA
      value: "Y"
  bindings:
    - port: 1433
- name: redis
  image: redis
  bindings:
    - port: 6973
- name: graph-api
  project: src/GraphApi/CoolStore.GraphApi/CoolStore.GraphApi.csproj
- name: product-catalog-api
  project: src/ProductCatalog/CoolStore.ProductCatalogApi/CoolStore.ProductCatalogApi.csproj
- name: inventory-api
  project: src/Inventory/CoolStore.InventoryApi/CoolStore.InventoryApi.csproj
```

Open up the terminal and run

```bash
$ tye run
```

It will let you run all services and its docker image related. Open your browser and type `http://localhost:8000`, you should see

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/np6y66rntkzh7wsj365v.JPG)

All the applications with `host` and `port` have already been binding.

Now is the time we debug it. Close it and go back to your terminal and `Ctrl + C`, then type

```bash
$ tye run --debug src/Inventory/CoolStore.InventoryApi
```

> You can type `tye run --debug *` to debug all the applications

Now open up `http://localhost:8000`, again

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9yo9mmc7z1cg04p5v09w.JPG)

What you can see here is the difference between `host` and `port` of all Dapr applications in the project which means `tye` will take care of `dynamic host` and `dynamic port` binding for our application. You don't need to care about declare your ports in your Dapr applications.

Open up your Visual Studio, and type `Ctrl + Alt  + P`, then choose the process with the name `CoolStore.InventoryApi` as the picture below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3cnlsb9x3xe3rvcmemtp.JPG)

Then go to your `inventory-api` to set your debug point as 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hp1pmqmyq1a9x25ar8hh.JPG)

Now, back to your browser and click to `http://localhost:64203`, and it should redirect you to the GraphQL playground, and type as below

```javascript
{
  products {
    edges {
      name
      categoryName
      inventoryLocation
    }
    totalCount
  }
}
```

Click to `Play` button, button as below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/flixt1werhez1oub9sis.JPG)

After clicking it, you should see the debug break-point will appear as below

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/19y2xus086i0i6yeekti.JPG)

Then, you can add a watch as

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/kf7rp5l9kivy4pyikvod.JPG)

Finally, the result should output like

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mdt8u62l5m7ree3pn6dd.JPG)

As you see, we can debug `Dapr` applications with Visual Studio smoothly, it still a `Dapr` application, can communicate with other `Dapr` applications, but it is intercepted by `tye` tool. Brilliant, right? 

- OS

```bash
Windows 10
```
- Dapr

```bash
$ dapr --version
CLI version: 0.5.0
Runtime version: 0.5.0
```

- Tye

```bash
$ tye --version
0.1.0-alpha.20179.5+4f73950de52831e655463851ada7ae366f95b28c
```

You need to have [Docker for Desktop](https://www.docker.com/products/docker-desktop) on your machine to get starting.

Dapr - https://github.com/dapr/docs/tree/master/getting-started
Tye - https://github.com/dotnet/tye/blob/master/docs/getting_started.md

I hope you like this hacking and happy coding. Don't believe what I said, try it!

Source code of our project is at https://github.com/thangchung/practical-dapr/tree/v0.0.1

Thank you for your reading!