python-sdk/examples/metadata at main · dapr/python-sdk

Example - Inspect Dapr runtime metadata

This example demonstrates the usage of Dapr Metadata API and of the two two methods in that API:

  1. get_metadata: Gets the Dapr sidecar information provided by the Metadata Endpoint.
  2. set_metadata: Adds a custom label to the Dapr sidecar information stored by the Metadata endpoint.

It creates a client using DaprClient, uses a set of components defined in the ./components/ folder and invokes the two APIs from Metadata API.

Pre-requisites

Install Dapr python-SDK

pip3 install dapr dapr-ext-grpc

Run the example

To run this example, the following code can be utilized:

dapr run --app-id=my-metadata-app --app-protocol grpc --resources-path components/ python3 app.py

The output should be as follows:

First, we will assign a new custom label to Dapr sidecar
Now, we will fetch the sidecar's metadata
And this is what we got:
  application_id: my-metadata-app
  active_actors_count: {}
  registered_components:
    name=lockstore type=lock.redis version= capabilities=[]
    name=pubsub type=pubsub.redis version=v1 capabilities=[]
    name=statestore type=state.redis version=v1 capabilities=['ACTOR', 'ETAG', 'KEYS_LIKE', 'TRANSACTIONAL', 'TTL']
We will update our custom label value and check it was persisted
We added a custom label named [is-this-our-metadata-example]
Its old value was [yes] but now it is [You bet it is!]

Error Handling

The Dapr python-sdk will pass through errors that it receives from the Dapr runtime.