Manages dynamic code probe tasks for Python applications through the Cloud Monitor (CMS) ServiceTaskController API (version 2024-03-30). Five probe types (LOG, SNAPSHOT, METRIC, SPAN, and SPAN_TAG) are supported, and capture results are stored in Simple Log Service (SLS).
Prerequisites
Alibaba Cloud CLI — The
cms2andslscommands used in this topic require the Alibaba Cloud CLI (command-line interface).Workspace ID — The Application Real-Time Monitoring Service (ARMS) workspace ID, such as
default-cms-xxx-cn-hangzhou.Service ID — The application or service ID, such as
ggxw4lnjuz@f2fd3a6265a254a052afb.SLS project — The SLS project for the application, such as
proj-xtrace-...-cn-hangzhou.Region — Specify the
--regionparameter explicitly for both CMS and SLS commands to avoid relying on the CLI default region.
This topic covers Python applications only (Probe tasks).
API operations
Operation | HTTP method | Path | CLI command |
Create a task |
|
|
|
List tasks |
|
|
|
Query a task |
|
|
|
Delete a task |
|
|
|
Query capture results | SLS | (Not a CMS operation) |
|
Path parameters
Parameter | Type | Required | Description |
| string | Yes | The ARMS workspace ID, such as |
| string | Yes | The application or service ID, such as |
| string | Yes (Get/Delete) | The task ID returned by the create operation. |
Common CLI parameters
Parameter | Description | Default |
| The region. Specify this parameter explicitly for both CMS and SLS commands to avoid relying on the CLI default region. | The default region in Alibaba Cloud CLI configuration |
| The CMS endpoint. Overrides the endpoint derived from the region. |
|
| Outputs indented JSON. The default |
|
CreateServiceTask
Creates a Live-Debug probe task.
Request
POST /serviceTask/{workspace}/{serviceId}/task
Content-Type: application/jsonBody parameters
Parameter | Type | Required | Description |
| string | Yes | The task type ( |
| string | Yes | The target instance IP address. Set this parameter to |
| string (JSON text) | Yes | A flat single-probe configuration object. The server stores it as a string. The CLI |
CLI example
aliyun cms2 apm service-task create \
--workspace <workspace> --service-id <serviceId> \
--type <taskType> --ip '<targetIp>' \
--task-config '<taskConfigJson>' \
--region <regionId> -o jsonTo match all instances, set
--ipto*.Pass a raw JSON object to
--task-config. You do not need to escape the JSON manually.
Response
{
"success": true,
"data": {
"requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"taskId": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
}
}Field | Description |
| The request ID. |
| The task ID. Use this value for SLS queries, Get, and Delete operations. |
HTTP body example (after CLI serialization)
{
"type": "live_debug_log_probe",
"ip": "*",
"taskConfig": "{\"probeType\":\"LOG\",\"language\":\"python\",\"target\":{\"typeName\":\"app.service.order\",\"methodName\":\"OrderService.create_order\",\"location\":\"exit\",\"instanceIds\":[\"*\"]},\"action\":{\"type\":\"LOG\",\"template\":\"id={order_id}\"},\"ttl\":\"30m\",\"captureCount\":100}"
}In the HTTP body, taskConfig is an escaped JSON string. When you pass the parameter through the CLI --task-config, pass the unescaped JSON object. The CLI handles the serialization.
ListServiceTask
Lists Live-Debug probe tasks.
Request
GET /serviceTask/{workspace}/{serviceId}/tasks?type={taskType}&maxResults={n}Query parameters
Parameter | Type | Required | Description |
| string | Yes | The task type for exact match filtering, such as |
| int | No | The maximum number of entries to return. Default value: |
Response fields
The CLI outputs a data.serviceTasks[] array. Each item contains the following fields:
Field | Description |
| The task ID. |
| The task type. |
| The service ID. |
| The IP address specified during creation, or |
| The time when the task was created. |
| The time when the task was last updated. |
| The task configuration (flat probe object). |
CLI example
aliyun cms2 apm service-task list \
--workspace <workspace> --service-id <serviceId> \
--type <taskType> --max-results 100 \
--region <regionId> -o jsonGetServiceTask
Queries the details of a single Live-Debug probe task.
Request
GET /serviceTask/{workspace}/{serviceId}/task/{taskId}?type={taskType}Query parameters
Parameter | Type | Required | Description |
| string | Yes | The task type. Must match the actual task type. |
Response
The CLI outputs a data.serviceTask object. The fields are the same as a single item in the List response.
CLI example
aliyun cms2 apm service-task get \
--workspace <workspace> --service-id <serviceId> \
--task-id <taskId> --type <taskType> \
--region <regionId> -o jsonDeleteServiceTask
Deletes a Live-Debug probe task. After deletion, the server removes the task and syncs the change to the config server. The corresponding probe on the agent side becomes inactive.
To deactivate a deployed probe, delete the corresponding task.
Request
DELETE /serviceTask/{workspace}/{serviceId}/task/{taskId}?type={taskType}Query parameters
Parameter | Type | Required | Description |
| string | Yes | The task type. Must match the actual task type. |
CLI example
aliyun cms2 apm service-task delete \
--workspace <workspace> --service-id <serviceId> \
--task-id <taskId> --type <taskType> \
--region <regionId> -o jsonBatch deletion example
To delete all probe tasks for a service, list and delete tasks for each of the five probe types:
WS=<workspace>; SVC=<serviceId>; REGION=<regionId>
for t in live_debug_log_probe live_debug_snapshot_probe \
live_debug_metric_probe live_debug_span_probe live_debug_span_tag_probe; do
aliyun cms2 apm service-task list \
--workspace "$WS" --service-id "$SVC" --type "$t" --region "$REGION" -o json |
python3 -c 'import sys,json; [print(t["taskId"]) for t in (json.load(sys.stdin)["data"].get("serviceTasks") or [])]' |
while read -r id; do
aliyun cms2 apm service-task delete \
--workspace "$WS" --service-id "$SVC" \
--task-id "$id" --type "$t" --region "$REGION" -o json
done
doneQuery capture results (SLS)
Capture status and results are written to Simple Log Service (SLS) and are not returned by the CMS Get operation.
CLI example
Query data from the last 10 minutes. Replace <taskId> with the task ID returned by the create operation.
FROM=$(( $(date +%s) - 600 )); TO=$(date +%s)
# Task status (installation status, funnel metrics)
aliyun sls get-logs-v2 --region <regionId> --accept-encoding gzip \
--project <slsProject> --logstore logstore-apm-logs \
--from "$FROM" --to "$TO" \
--query "* and \"<taskId>\" | SELECT content FROM log WHERE json_extract_scalar(attributes, '\$[\"livedebug.report_type\"]') = 'status'"
# Capture results (actual captured data)
aliyun sls get-logs-v2 --region <regionId> --accept-encoding gzip \
--project <slsProject> --logstore logstore-apm-logs \
--from "$FROM" --to "$TO" \
--query "* and \"<taskId>\" | SELECT content FROM log WHERE json_extract_scalar(attributes, '\$[\"livedebug.report_type\"]') != 'status'"Query parameters
Parameter | Required | Description |
| Yes | The SLS project for the application, such as |
| Yes | The logstore name. Default value: |
| Yes | The query time range in Unix timestamps (seconds). |
| Yes | The region of the SLS project. Must match the project region. Specify this parameter explicitly. |
Query types
Query type | Filter condition | Description |
Task status |
| Installation status and funnel metrics. |
Capture results |
| Actual captured data. |
SLS projects are isolated by region. An incorrect region parameter causes a ProjectNotExist error.
Task type enum
The following table lists the five probe types supported for Python applications. The naming convention is live_debug_ + lowercase probe semantics + _probe.
| Probe type | Description |
| LOG | Outputs dynamic logs at the target point. |
| SNAPSHOT | Captures method snapshots and serializes the object graph. |
| METRIC | Emits custom metrics at the target point. |
| SPAN | Creates an OpenTelemetry span for function execution. |
| SPAN_TAG | Appends attributes to the current active span. |
Probe taskConfig structure
The flat object passed to --task-config:
{
"probeType": "LOG|SNAPSHOT|METRIC|SPAN|SPAN_TAG",
"language": "python",
"target": { },
"action": { },
"trigger": { },
"rateLimit": { },
"ttl": "1h",
"captureCount": 100,
"enabled": true
}Top-level fields
Field | Type | Required | Description |
| string | Yes | The probe type. Valid values: |
| string | Yes | The language. Set this parameter to |
| object | Yes | Locates the target method or line. |
| object | Yes | The probe action. The structure varies by |
| object | No | The trigger condition. |
| object | No | Rate limiting configuration. |
| string | At least one of | The time to live. Supported formats: |
| int | At least one of | The maximum number of captures. The task terminates when either |
| boolean | No | Typically |
target — locate the target
Field | Type | Required | Description |
| string | Recommended for function-level probes | The module name ( |
| string | Recommended for function-level probes | The function |
| string | No (recommended for line-level probes) | The source file name or path suffix. |
| string | No | The hook point. Valid values: |
| string[] | Strongly recommended | The list of instance IDs on which the probe takes effect. Place this parameter inside |
| string[] | No | The list of IP addresses on which the probe takes effect. Combined with |
Line-level probes can primarily rely on sourceFile + location:"line:N".
trigger — trigger condition (optional)
Field | Type | Default | Description |
| string | - | The probe captures data only when this expression evaluates to true. |
| string | - | Caller filter (rarely used in Python). |
Condition examples:amount > 10000 or @return is None or amount > 10000
Expression rules:
Use parameter names, local variables, or module-level global variables directly.
At
exitorexceptionlocations, use@return,@duration(milliseconds), or@exception.Do not use OGNL,
args[0],returnValue, ordurationMs.If the condition references
@returnor@exception, the probelocationmust beexitorexception.
rateLimit — rate limiting (optional)
Field | Type | Default | Description |
| int | Varies by probe type (see below) | The maximum executions per second (token bucket). |
| double | 1.0 | The random pass-through probability (0 to 1). |
| int | 100 | The timeout for a single capture in milliseconds. |
Default rate limits: LOG, METRIC, SPAN, and SPAN_TAG probes allow approximately 5,000 executions per second. SNAPSHOT probes allow approximately 1 execution per second. Line-level probes have an additional global protection limit of approximately 100 executions per second.
Probe action by type
LOG (taskType: live_debug_log_probe)
Outputs dynamic logs at the target point without object graph serialization.
action fields
Field | Type | Required | Description |
| string | Yes | Set to |
| string | Yes | The log template. Use |
LOG probes only render the template and ignore the capture dimension. To capture parameters, return values, or stack traces, use a SNAPSHOT probe.
Example
{
"probeType": "LOG",
"language": "python",
"target": {
"typeName": "app.service.order",
"methodName": "OrderService.create_order",
"location": "exit",
"instanceIds": ["*"]
},
"action": {
"type": "LOG",
"template": "create_order id={order_id} amount={amount} ret={@return} cost={@duration}ms"
},
"ttl": "30m",
"captureCount": 100
}SNAPSHOT (taskType: live_debug_snapshot_probe)
Captures method snapshots and serializes the object graph.
action fields
Field | Type | Required | Description |
| string | Yes | Set to |
| string[] | Yes | The capture dimensions. If not provided or set to |
| string[] | No | Additional expressions to evaluate. |
| object | No | Object graph serialization limits. |
capture enum values
Value | Description |
| Serializes method arguments. |
| Serializes the return value. |
| Serializes the current instance. |
| Records exception summary. |
| Captures local variables (requires debug information). |
| Captures the call stack (opt-in, must be explicitly included). |
| Aggregates sub-calls within the method body. |
captureConfig
Field | Default | Description |
| 3 | The maximum object serialization depth. |
| 100 | The maximum number of elements in collections or arrays. |
| 1024 | The maximum string length. |
| 50 | The maximum number of fields per object. |
| 65536 | The maximum size of a single snapshot in bytes. |
| 50 | The maximum call stack depth. |
|
| Regular expressions for field name redaction. |
captureExpressions
The syntax is the same as trigger.condition and LOG templates (limited eval). Results are written to context.evaluatedExpressions. Each item has the following format:
{"name": "order_id", "type": "...", "value": "...", "notCapturedReason": null}If evaluation fails, value is set to null and notCapturedReason records the reason. This does not affect other dimensions. captureExpressions and capture are independent of each other.
Example
{
"probeType": "SNAPSHOT",
"language": "python",
"target": {
"typeName": "app.service.order",
"methodName": "OrderService.create_order",
"location": "exit",
"instanceIds": ["*"]
},
"trigger": {
"condition": "@return is None or amount > 10000"
},
"action": {
"type": "SNAPSHOT",
"capture": ["ARGS"],
"captureExpressions": ["order_id", "amount * count", "self.user_id", "@return"],
"captureConfig": {
"maxDepth": 3,
"maxCollectionSize": 100,
"maxStringLength": 1024
}
},
"ttl": "30m",
"captureCount": 50
}METRIC (taskType: live_debug_metric_probe)
Emits custom metrics at the target point.
action fields
Field | Type | Required | Description |
| string | Yes | Set to |
| string | Yes | The metric name, such as |
| string | Yes | The metric type. Valid values: |
| string | Yes | A Python expression that evaluates to the metric value. |
| object | No | A tag map. Values are Python expression strings. |
Example
{
"probeType": "METRIC",
"language": "python",
"target": {
"typeName": "app.service.order",
"methodName": "OrderService.create_order",
"location": "exit",
"instanceIds": ["*"]
},
"action": {
"type": "METRIC",
"metricName": "livedebug.order.amount",
"metricType": "HISTOGRAM",
"valueExpression": "amount",
"tags": {
"is_vip": "str(user_id == 'vip')"
}
},
"ttl": "1h"
}SPAN (taskType: live_debug_span_probe)
Creates an OpenTelemetry span for the target function execution. Marks the span as ERROR and records an exception event if an exception occurs. Function-level only.
action fields
Field | Type | Required | Description |
| string | Yes | Set to |
| string | Yes | The span name. |
| object | No | An attribute map. Values are Python expression strings. |
Example
{
"probeType": "SPAN",
"language": "python",
"target": {
"typeName": "app.service.order",
"methodName": "OrderService.create_order",
"location": "enter",
"instanceIds": ["*"]
},
"action": {
"type": "SPAN",
"spanName": "dyn.create_order",
"spanTags": {
"order.id": "str(order_id)",
"order.amount": "str(amount)"
}
},
"ttl": "1h"
}SPAN_TAG (taskType: live_debug_span_tag_probe)
Appends attributes to the current active span. Silently skips if no active span exists.
action fields
Field | Type | Required | Description |
| string | Yes | Set to |
| array | Yes | A tag array. Each item has the format |
Example
{
"probeType": "SPAN_TAG",
"language": "python",
"target": {
"typeName": "app.service.order",
"methodName": "OrderService.create_order",
"location": "exit",
"instanceIds": ["*"]
},
"action": {
"type": "SPAN_TAG",
"tags": [
{"key": "order.id", "value": "str(order_id)"},
{"key": "order.result", "value": "str(@return)"}
]
},
"ttl": "1h"
}Errors and troubleshooting
Symptom | Possible cause | Solution |
| The SLS region is incorrect. | Specify the correct region by using |
List returns empty results but the task exists | The | List tasks by the exact task type. |
Creating a task with | This parameter does not affect deployed tasks. | Use |
Probe captures no data |
| Set |
SPAN creation fails or is invalid |
| Change to function-level |
TTL exception | The | Use |
Complete workflow example (LOG probe)
# 0. Environment variables
REGION=cn-hangzhou
SLS_PROJECT=proj-xtrace-xxxxxxxxxxxxxxxxxxxxxx-cn-hangzhou
WORKSPACE=default-cms-xxxxxxxxxxxxxxxxxx-cn-hangzhou
SERVICE_ID='ggxw4lnjuz@f2fd3a6265a254a052afb'
# 1. Create a task
RESP=$(aliyun cms2 apm service-task create \
--workspace "$WORKSPACE" --service-id "$SERVICE_ID" \
--type live_debug_log_probe --ip '*' \
--task-config '{"probeType":"LOG","language":"python","target":{"typeName":"app.service.order","methodName":"OrderService.create_order","location":"exit","instanceIds":["*"]},"action":{"type":"LOG","template":"id={order_id} ret={@return}"},"ttl":"30m","captureCount":50}' \
--region "$REGION" -o json)
echo "$RESP"
TASK_ID=$(echo "$RESP" | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"]["taskId"])')
# 2. Verify the task
aliyun cms2 apm service-task get \
--workspace "$WORKSPACE" --service-id "$SERVICE_ID" \
--task-id "$TASK_ID" --type live_debug_log_probe \
--region "$REGION" -o json
# 3. Generate traffic to the instrumented endpoint and query results (last 10 minutes)
FROM=$(( $(date +%s) - 600 )); TO=$(date +%s)
aliyun sls get-logs-v2 --region "$REGION" --accept-encoding gzip \
--project "$SLS_PROJECT" --logstore logstore-apm-logs \
--from "$FROM" --to "$TO" \
--query "* and \"$TASK_ID\" | SELECT content FROM log WHERE json_extract_scalar(attributes, '\$[\"livedebug.report_type\"]') != 'status'"
# 5. Delete the task
aliyun cms2 apm service-task delete \
--workspace "$WORKSPACE" --service-id "$SERVICE_ID" \
--task-id "$TASK_ID" --type live_debug_log_probe \
--region "$REGION" -o json