The Dify console lets you configure monitoring for individual applications and integrate them with Cloud Monitor for observability, but does not support batch configuration. You can call APIs to batch-configure Alibaba Cloud observability monitoring for Dify applications.
Background
The process simulates Dify console operations through HTTP APIs to batch-configure monitoring:
-
Obtain logon status: Call the logon API to obtain an authentication token.
-
Retrieve the application list: Get information about all applications under the tenant.
-
Check the application monitoring configuration: Query the current monitoring configuration status of an application.
-
Configure Alibaba Cloud monitoring: Create an Alibaba Cloud observability configuration for an application.
-
Enable the monitoring switch: Turn on application monitoring.
If you deploy Dify from source code, you can also implement batch configuration by following the process above and using the O&M commands in Dify's ext_commands.py file with Click Command.
API batch configuration flow
Step 1: Log on and authenticate
Call the Dify logon API to authenticate and obtain the tenant's logon token.
API: POST {base_url}/console/api/login
Request parameters
{
"email": "your_account@example.com",
"password": "your_password",
"remember_me": false
}
Response
{
"result": "success"
}Set-Cookie: access_token=<JWT>; HttpOnly; Max-Age=3600
Set-Cookie: refresh_token=<random>; HttpOnly; Max-Age=2592000
Set-Cookie: csrf_token=<JWT>; Max-Age=3600
Key information in the response
|
Cookie |
Purpose |
|
|
API authentication credential |
|
|
Credential to renew the access_token |
|
|
Cross-Site Request Forgery (CSRF) credential |
Subsequent requests
In the request header, set:
Cookie: access_token=xxx; refresh_token=xxx; csrf_token=xxx
X-CSRF-Token: <csrf_token>
If you use a library that has session features, the library usually manages cookies automatically. In this case, you only need to add X-CSRF-Token to the header.
Step 2: Get the application list
Retrieve all applications under the current tenant.
API: GET {base_url}/console/api/apps
Request parameters
|
Parameter |
Type |
Default value |
Description |
|
|
int |
1 |
Page number, starting from 1. |
|
|
int |
20 |
Number of items per page. Valid values: 1 to 100. |
|
|
string |
"all" |
Filter by application type. |
|
|
string |
- |
Search by application name. |
Paging instructions:
-
Use the returned
has_morefield to determine whether a next page exists. -
To retrieve all applications, loop the requests until the
has_morefield in the response isfalse.
Response
{
"page": 1,
"limit": 20,
"total": 100,
"has_more": true,
"data": [
{
"id": "app-uuid",
"name": "Application Name",
"mode": "workflow",
"description": "Application Description",
"icon": "",
"icon_type": "emoji",
"created_at": 1234567890,
"updated_at": 1234567890,
"model_config": { /* Model Configuration */ },
"workflow": { /* workflow configuration */ },
"tags": []
}
]
}
Key field descriptions:
-
id: The application ID, required for subsequent monitoring configuration steps. -
name: The application name, required for theapp_nameparameter when configuring monitoring.
Step 3: Check the application monitoring configuration
Query the current monitoring configuration status of an application. Proceed to the next steps only if monitoring is not yet configured.
API: GET {base_url}/console/api/apps/{app_id}/trace
Request parameters
-
app_id: The application ID. You can obtain this ID in Step 2: Retrieve the application list.
Response
{
"enabled": false,
"tracing_provider": null
}{
"enabled": true,
"tracing_provider": "aliyun"
}
Field descriptions:
-
enabled: Indicates whether monitoring is enabled (boolean). -
tracing_provider: The name of the monitoring provider (string).
Step 4: Configure Alibaba Cloud monitoring
Create an Alibaba Cloud observability monitoring configuration for an application.
API: POST {base_url}/console/api/apps/{app_id}/trace-config
Request parameters
{
"tracing_provider": "aliyun",
"tracing_config": {
"app_name": "xxx",
"license_key": "your_aliyun_license_key",
"endpoint": "http://tracing-analysis-dc-bj.aliyuncs.com"
}
}
Field descriptions
|
Field |
Description |
|
|
Fixed as |
|
|
The Alibaba Cloud application name. Each application must have a unique name; identical names are treated as the same observability application. Use the format |
|
|
The Alibaba Cloud License Key. For more information, see DescribeTraceLicenseKey - List LicenseKey. |
|
|
The Alibaba Cloud reporting endpoint. For more information, see Endpoints. |
Response
{
"result": "success"
}
In some Dify versions, monitoring metrics in the console may appear abnormal if you create a configuration without enabling it. The metrics return to normal after you enable the monitoring switch.
Step 5: Enable the monitoring switch
After you configure monitoring, enable the monitoring switch for the settings to take effect.
API: POST {base_url}/console/api/apps/{app_id}/trace
Request parameters
{
"enabled": true,
"tracing_provider": "aliyun"
}
|
Field |
Type |
Description |
|
|
boolean |
Whether to enable monitoring (true/false). |
|
|
string |
The name of the monitoring provider (aliyun). |
Response
{
"result": "success"
}