Dapr API Logs

Understand how API logging works in Dapr and how to view logs

API logging enables you to see the API calls from your application to the Dapr sidecar and debug issues as a result when the flag is set. You can also combine Dapr API logging with Dapr log events (see configure and view Dapr Logs into the output, if you want to use the logging capabilities together.

Overview

The default value of the flag is false.

To enable API logging, you can use the --enable-api-logging command-line option. For example:

  1. ./daprd --enable-api-logging

This starts the Dapr runtime with API logging.

Configuring API logging in self hosted mode

To enable API logging when running your app with the Dapr CLI, pass the enable-api-logging flag:

  1. dapr run --enable-api-logging node myapp.js

Viewing API logs in self hosted mode

When running Dapr with the Dapr CLI, both your app’s log output and the Dapr runtime log output are redirected to the same session, for easy debugging.

The example below shows some API logs:

  1. dapr run --enable-api-logging -- node myapp.js
  2. ℹ️ Starting Dapr with id order-processor on port 56730
  3. You are up and running! Both Dapr and your app logs will appear here.
  4. .....
  5. INFO[0000] HTTP API Called: POST /v1.0/state/statestore app_id=order-processor instance=QTM-SWATHIKIL-1.redmond.corp.microsoft.com scope=dapr.runtime.http type=log ver=edge
  6. == APP == INFO:root:Saving Order: {'orderId': '483'}
  7. INFO[0000] HTTP API Called: GET /v1.0/state/statestore/483 app_id=order-processor instance=QTM-SWATHIKIL-1.redmond.corp.microsoft.com scope=dapr.runtime.http type=log ver=edge
  8. == APP == INFO:root:Getting Order: {'orderId': '483'}
  9. INFO[0000] HTTP API Called: DELETE /v1.0/state/statestore app_id=order-processor instance=QTM-SWATHIKIL-1.redmond.corp.microsoft.com scope=dapr.runtime.http type=log ver=edge
  10. == APP == INFO:root:Deleted Order: {'orderId': '483'}
  11. INFO[0000] HTTP API Called: PUT /v1.0/metadata/cliPID app_id=order-processor instance=QTM-SWATHIKIL-1.redmond.corp.microsoft.com scope=dapr.runtime.http type=log ver=edge

Configuring API logging in Kubernetes

You can enable the API logs for every sidecar by providing the following annotation in your pod spec template:

  1. annotations:
  2. dapr.io/enable-api-logging: "true"

Viewing API logs on Kubernetes

Dapr API logs are written to stdout and stderr and you can view API logs on Kubernetes.

See the kubernetes API logs by executing the below command.

  1. kubectl logs <pod_name> daprd -n <name_space>

The example below show info level API logging in Kubernetes.

  1. time="2022-03-16T18:32:02.487041454Z" level=info msg="HTTP API Called: GET /v1.0/invoke/invoke-receiver/method/my-method" app_id=invoke-caller instance=invokecaller-f4f949886-cbnmt scope=dapr.runtime.http type=log ver=edge
  2. time="2022-03-16T18:32:02.698387866Z" level=info msg="HTTP API Called: GET /v1.0/invoke/invoke-receiver/method/my-method" app_id=invoke-caller instance=invokecaller-f4f949886-cbnmt scope=dapr.runtime.http type=log ver=edge
  3. time="2022-03-16T18:32:02.917629403Z" level=info msg="HTTP API Called: GET /v1.0/invoke/invoke-receiver/method/my-method" app_id=invoke-caller instance=invokecaller-f4f949886-cbnmt scope=dapr.runtime.http type=log ver=edge
  4. time="2022-03-16T18:32:03.137830112Z" level=info msg="HTTP API Called: GET /v1.0/invoke/invoke-receiver/method/my-method" app_id=invoke-caller instance=invokecaller-f4f949886-cbnmt scope=dapr.runtime.http type=log ver=edge
  5. time="2022-03-16T18:32:03.359097916Z" level=info msg="HTTP API Called: GET /v1.0/invoke/invoke-receiver/method/my-method" app_id=invoke-caller instance=invokecaller-f4f949886-cbnmt scope=dapr.runtime.http type=log ver=edge

Last modified May 18, 2022: Upmerge of v1.7 into v1.8 20220518 (#2446) (e1f6e886)