---
schema_version: "1"
id: 3baf43f9c525c60e4d86f46afc0200573599c9e9c9581c39dfcbbf7ed0428254
title: Debugging Custom Policies with the PDK Debugging Playground
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.2/policies-pdk-debug-local.md
canonical_url: https://docs.mulesoft.com/pdk/1.2/policies-pdk-debug-local
source_site: docs.mulesoft.com
content_type: documentation
content_hash: bd78ca8fd20f38924b0c775d404e2e3e82e3af2550687170af1e4cce6e253298
description: MuleSoft Documentation Site
release: "1.2"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.2
---

# Debugging Custom Policies with the PDK Debugging Playground

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

To test the functionality of your policy, Flex Gateway Policy Development Kit (PDK) provides a
pre-configured API instance located in the `<root-directory>/playground/config` directory.

The PDK Debugging Playground only supports Flex Gateway running in Local Mode in a Docker container.
If you plan to deploy or policy to Flex Gateway running in Connected Mode or to a different
platform, you should still first test your policy in PDK by using Flex Gateway running in Local Mode
in a Docker container.

> [!IMPORTANT] You can run Flex Gateway in Local Mode on Docker in Windows only to develop and test
> your policies. However, Flex Gateway does not support Windows in production environments.

To test your policy, complete the following tasks:

1.  [Before You Begin](#before-you-begin)

2.  [Register a Flex Gateway Instance in Local Mode](#register)

3.  [Configure the Policy](#configure-the-policy)

4.  [Add Additional Policies](#add-additional-policies) if necessary

5.  [Deploy the Policy with PDK](#deploy-the-policy-with-pdk)

## Before You Begin

Ensure that you have:

- [Installed Docker](https://www.docker.com/).

- [Compiled your custom policy project](https://docs.mulesoft.com/pdk/1.2/policies-pdk-compile-policies).

## Register a Flex Gateway Instance in Local Mode

To begin using the `make run` command to debug your custom policy, register a Flex Gateway in Local
Mode.

For the `run` command to work, a Flex Gateway `registration.yaml` file must exist in the
`<root-directory>/playground/config` directory. Create this file by running the registration command
in the directory, or move a `registration.yaml` file of a previously registered Flex Gateway to the
directory.

The `make run` command only supports Flex Gateways running in Local Mode in a Docker Container. To
register Flex Gateway, see:

- [Register and Run with a Username and Password in a Docker Container](https://docs.mulesoft.com/gateway/latest/local-reg-run-up#docker)

- [Register and Run with a Connected App in a Docker Container](https://docs.mulesoft.com/gateway/latest/local-reg-run-app#docker)

- [Register and Run with a Token in a Docker Container](https://docs.mulesoft.com/gateway/latest/local-reg-run-token#docker)

> [!IMPORTANT] Run only the registration command. Do not run the Docker start command because the
> `make run` command completes this step.

Create a different registration file on each device testing the policy.

The registration file is ignored for storage in remote repositories and is listed in the
`.gitignore` file located at the root of the project directory.

## Configure the Policy

Depending on the configurations listed in the `definition/gcl.yaml` file you configured in
[Defining a Policy Schema Definition](https://docs.mulesoft.com/pdk/1.2/policies-pdk-create-schema-definition), you may have to
configure some parameters before running the policy locally.

For example, if the `gcl.yaml` file is as follows:

```yaml
apiVersion: gateway.mulesoft.com.v1alpha1
kind: Extension
metadata:
  labels:
    title: my-custom-policy
    category: Security
spec:
  extends:
    - name: extension-definition
  properties:
    user:
      type: string
      default: user1
    password:
      type: string
    description:
      type: string
  required:
    - user
    - password
```

Update the `/playground/config/api.yaml` file with your configuration value:

```yaml
apiVersion: gateway.mulesoft.com/v1alpha1
kind: ApiInstance
metadata:
  name: ingress-http
spec:
  address: http://0.0.0.0:8081
  services:
    upstream:
      address: http://backend
      routes:
        - config:
            destinationPath: /anything/echo/
  policies:
    - policyRef:
        name: my-custom-policy
      config:
        password: 12345678
```

In this example, the `user` is set to the default value `user1`, the `password` is set to
`12345678`, and no description is provided.

## Add Additional Policies

You can also apply additional policies to the test API instance to test your custom policies
behavior alongside other policies.

However, your custom policy under development must be the first policy specified, for example:

```yaml
policies:
  - policyRef:
      name: my-custom-policy
    config:
      password: 12345678
  - policyRef:
      name: additional-policy
    config:
```

## Deploy the Policy with PDK

After you complete the previous steps, run the `make run` command from the policy’s root directory
to deploy policy:

```cmd
make run
```

This command starts the two Docker containers in the
`<root-directory>/playground/docker-compose.yaml` file:

- `Local-flex`: The Flex Gateway instance Docker container that executes the custom policy. This
  Flex Gateway listens for requests made to `localhost:8081`.

- `Backend`: The Docker Container that runs the backend service for the Flex Gateway instance. This
  backend service echoes any request it receives.

> [!NOTE] To stop the Docker containers, press `Cmd+c` or `Ctrl+c` depending on your device from the
> terminal running the containers.

Once the containers are running, you can make requests to the API instance, for example:

```cmd
curl --location --request POST 'http://0.0.0.0:8081/some/route' \
--header 'Token: mytoken'
```

The backend service returns an echo response including the requests’s route, body, and headers sent
with any modification performed by the custom policy or additional policies. Any logs included in
the custom policy’s source code are visible in the terminal running the containers.

## Configure the Loglevel

By default, PDK’s debugging environment enables logs with the `debug` `loglevel` configured.

To change the `loglevel`, edit the `logging.runtimeLogs.logLevel` value in
`<root-directory>/playground/config/logging.yaml`.

To learn more about editing a Flex Gateway’s logging configuration file, see
[Configuring External Logs for Omni Gateway in Local Mode](https://docs.mulesoft.com/gateway/latest/local-third-party-logs-config).

## Use the Rust Debugger

Visual Studio Code (VS Code) includes a Rust debugger that can run unit tests. You cannot use the VS
Code Debugger while the policy is deployed on a Flex Gateway. To create the API mocking, you must
use unit tests for the specific logic you need to debug.

To debug Rust code in VS Code, you must install the
[CodeLLDB Debugger Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)
or a different VS Code extension with the same functionality. To learn more about debugging Rust in
VS Code, see
[Rust in Visual Studio Code](https://code.visualstudio.com/docs/languages/rust#_debugging).

## See Also

- [Writing Integration Tests](https://docs.mulesoft.com/pdk/1.2/policies-pdk-integration-tests)

- [PDK Troubleshooting](https://docs.mulesoft.com/pdk/1.2/policies-pdk-troubleshooting)
