All Products
Search
Document Center

Cloud Monitor:Live-Debug ServiceTask API reference

Last Updated:Aug 03, 2026

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 cms2 and sls commands 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 --region parameter explicitly for both CMS and SLS commands to avoid relying on the CLI default region.

Note

This topic covers Python applications only (Probe tasks).

API operations

Operation

HTTP method

Path

CLI command

Create a task

POST

/serviceTask/{workspace}/{serviceId}/task

aliyun cms2 apm service-task create

List tasks

GET

/serviceTask/{workspace}/{serviceId}/tasks

aliyun cms2 apm service-task list

Query a task

GET

/serviceTask/{workspace}/{serviceId}/task/{taskId}

aliyun cms2 apm service-task get

Delete a task

DELETE

/serviceTask/{workspace}/{serviceId}/task/{taskId}

aliyun cms2 apm service-task delete

Query capture results

SLS get-logs-v2

(Not a CMS operation)

aliyun sls get-logs-v2

Path parameters

Parameter

Type

Required

Description

workspace

string

Yes

The ARMS workspace ID, such as default-cms-xxx-cn-hangzhou.

serviceId

string

Yes

The application or service ID, such as ggxw4lnjuz@f2fd3a6265a254a052afb.

taskId

string

Yes (Get/Delete)

The task ID returned by the create operation.

Common CLI parameters

Parameter

Description

Default

--region

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

--endpoint

The CMS endpoint. Overrides the endpoint derived from the region.

cms.${regionId}.aliyuncs.com

-o json

Outputs indented JSON. The default text mode outputs compact single-line JSON.

text

CreateServiceTask

Creates a Live-Debug probe task.

Request

POST /serviceTask/{workspace}/{serviceId}/task
Content-Type: application/json

Body parameters

Parameter

Type

Required

Description

type

string

Yes

The task type (taskType). For valid values, see Task type enum.

ip

string

Yes

The target instance IP address. Set this parameter to * to match all instances.

taskConfig

string (JSON text)

Yes

A flat single-probe configuration object. The server stores it as a string. The CLI --task-config parameter accepts a raw JSON object and serializes it to a string automatically.

CLI example

aliyun cms2 apm service-task create \
  --workspace <workspace> --service-id <serviceId> \
  --type <taskType> --ip '<targetIp>' \
  --task-config '<taskConfigJson>' \
  --region <regionId> -o json
  • To match all instances, set --ip to *.

  • 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

data.requestId

The request ID.

data.taskId

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}"
}
Note

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

type

string

Yes

The task type for exact match filtering, such as live_debug_log_probe.

maxResults

int

No

The maximum number of entries to return. Default value: 100. Maximum value: 100.

Response fields

The CLI outputs a data.serviceTasks[] array. Each item contains the following fields:

Field

Description

taskId

The task ID.

type

The task type.

serviceId

The service ID.

ip

The IP address specified during creation, or *.

createTime

The time when the task was created.

updateTime

The time when the task was last updated.

taskConfig

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 json

GetServiceTask

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

type

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 json

DeleteServiceTask

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.

Important

To deactivate a deployed probe, delete the corresponding task.

Request

DELETE /serviceTask/{workspace}/{serviceId}/task/{taskId}?type={taskType}

Query parameters

Parameter

Type

Required

Description

type

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 json

Batch 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
done

Query 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

--project

Yes

The SLS project for the application, such as proj-xtrace-...-cn-hangzhou.

--logstore

Yes

The logstore name. Default value: logstore-apm-logs.

--from / --to

Yes

The query time range in Unix timestamps (seconds).

--region

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

livedebug.report_type = 'status'

Installation status and funnel metrics.

Capture results

livedebug.report_type != 'status'

Actual captured data.

Important

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.

taskType

Probe type

Description

live_debug_log_probe

LOG

Outputs dynamic logs at the target point.

live_debug_snapshot_probe

SNAPSHOT

Captures method snapshots and serializes the object graph.

live_debug_metric_probe

METRIC

Emits custom metrics at the target point.

live_debug_span_probe

SPAN

Creates an OpenTelemetry span for function execution.

live_debug_span_tag_probe

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

probeType

string

Yes

The probe type. Valid values: LOG, SNAPSHOT, METRIC, SPAN, SPAN_TAG.

language

string

Yes

The language. Set this parameter to python.

target

object

Yes

Locates the target method or line.

action

object

Yes

The probe action. The structure varies by probeType.

trigger

object

No

The trigger condition.

rateLimit

object

No

Rate limiting configuration.

ttl

string

At least one of ttl or captureCount

The time to live. Supported formats: 30s, 5m, 2h, 1d, or a number in seconds. Do not use ms.

captureCount

int

At least one of ttl or captureCount

The maximum number of captures. The task terminates when either ttl or captureCount is reached first.

enabled

boolean

No

Typically true when created. Creating a task with enabled: false does not disable an existing probe.

target — locate the target

Field

Type

Required

Description

typeName

string

Recommended for function-level probes

The module name (sys.modules key), such as app.service.order. Set this parameter to __main__ for the main module.

methodName

string

Recommended for function-level probes

The function __qualname__. For class methods, use the format ClassName.method_name. For plain functions, use the function name directly.

sourceFile

string

No (recommended for line-level probes)

The source file name or path suffix.

location

string

No

The hook point. Valid values: enter, exit, exception, line:N. Default value: exit. SPAN probes support function-level only and cannot use line.

instanceIds

string[]

Strongly recommended

The list of instance IDs on which the probe takes effect. Place this parameter inside target, not at the top level of taskConfig. Set to ["*"] for all instances. If empty, the probe does not take effect.

instanceIps

string[]

No

The list of IP addresses on which the probe takes effect. Combined with instanceIds using AND logic.

Line-level probes can primarily rely on sourceFile + location:"line:N".

trigger — trigger condition (optional)

Field

Type

Default

Description

condition

string

-

The probe captures data only when this expression evaluates to true.

callerPattern

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 exit or exception locations, use @return, @duration (milliseconds), or @exception.

  • Do not use OGNL, args[0], returnValue, or durationMs.

  • If the condition references @return or @exception, the probe location must be exit or exception.

rateLimit — rate limiting (optional)

Field

Type

Default

Description

maxExecutionsPerSecond

int

Varies by probe type (see below)

The maximum executions per second (token bucket).

samplingProbability

double

1.0

The random pass-through probability (0 to 1).

executionTimeoutMs

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

type

string

Yes

Set to "LOG".

template

string

Yes

The log template. Use {expression} syntax for dynamic values.

Note

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

type

string

Yes

Set to "SNAPSHOT".

capture

string[]

Yes

The capture dimensions. If not provided or set to [], no object graph is captured.

captureExpressions

string[]

No

Additional expressions to evaluate.

captureConfig

object

No

Object graph serialization limits.

capture enum values

Value

Description

ARGS

Serializes method arguments.

RETURN

Serializes the return value.

THIS

Serializes the current instance.

EXCEPTION

Records exception summary.

LOCALS

Captures local variables (requires debug information).

STACK

Captures the call stack (opt-in, must be explicitly included).

EXECUTION_DETAIL

Aggregates sub-calls within the method body.

captureConfig

Field

Default

Description

maxDepth

3

The maximum object serialization depth.

maxCollectionSize

100

The maximum number of elements in collections or arrays.

maxStringLength

1024

The maximum string length.

maxFieldCount

50

The maximum number of fields per object.

maxTotalSizeBytes

65536

The maximum size of a single snapshot in bytes.

stackTraceDepth

50

The maximum call stack depth.

redactedFieldPatterns

[".*password.*",".*token.*",".*secret.*"]

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

type

string

Yes

Set to "METRIC".

metricName

string

Yes

The metric name, such as livedebug.order.amount.

metricType

string

Yes

The metric type. Valid values: COUNTER, GAUGE, HISTOGRAM, SUMMARY.

valueExpression

string

Yes

A Python expression that evaluates to the metric value.

tags

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

type

string

Yes

Set to "SPAN".

spanName

string

Yes

The span name.

spanTags

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

type

string

Yes

Set to "SPAN_TAG".

tags

array

Yes

A tag array. Each item has the format { "key": "...", "value": "<Python expression>" }.

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

ProjectNotExist

The SLS region is incorrect.

Specify the correct region by using aliyun sls --region. The region must match the project region.

List returns empty results but the task exists

The type parameter does not match the actual task type.

List tasks by the exact task type.

Creating a task with enabled:false does not stop an active probe

This parameter does not affect deployed tasks.

Use DeleteServiceTask to deactivate probes.

Probe captures no data

instanceIds is empty, the module name is incorrect, or no traffic was triggered.

Set instanceIds to ["*"], verify typeName and methodName, and generate traffic before querying status.

SPAN creation fails or is invalid

line:N is used as the location.

Change to function-level enter or exit.

TTL exception

The ms unit is used.

Use s, m, h, d, or a number in seconds.

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