Coding

Alibabacloud Emas Apm Remotelog

Try it

EMAS APM Remote Log (TLog) CLI Skill. Use for remote log retrieval, task management, and log query operations via Alibaba Cloud CLI. Triggers: "EMAS APM", "r...

What it does

EMAS APM Remote Log (TLog) CLI Skill. Use for remote log retrieval, task management, and log query operations via Alibaba Cloud CLI. Triggers: "EMAS APM", "remote log", "tlog", "log retrieval", "log collection", "get-tlog-device-list", "create-tlog-task", "search-tlog", "mobile app log".

The skill document

EMAS APM Remote Log (TLog) CLI Skill

Scenario Description

This skill enables remote log retrieval (TLog) operations for mobile applications managed by Alibaba Cloud EMAS APM (Application Performance Monitoring). It provides a complete workflow to:

  1. Resolve target devices by device ID, user nickname, user ID, or custom ID
  2. Create remote log retrieval tasks to trigger log collection from end-user devices
  3. Track task progress including overall task status and per-device collection status
  4. Query log details by device and time window with level and keyword filtering
  5. Query actively submitted logs for user-initiated log uploads

Architecture: EMAS Console + Mobile App (with TLog SDK) + EMAS APM Service + Alibaba Cloud CLI (emas-appmonitor plugin)

Key Components:

  • Device Side: Mobile apps integrated with EMAS TLog SDK (Android/iOS)
  • Server Side: EMAS APM backend service for task dispatch and log storage
  • Client Side: Alibaba Cloud CLI with aliyun-cli-emas-appmonitor plugin for API operations

Installation

Pre-check: Alibaba Cloud CLI >= 3.3.3 required

aliyun version
# If not installed or version too low (script served by Alibaba Cloud official CDN over HTTPS):
curl -fsSL --connect-timeout 10 --max-time 120 https://aliyuncli.alicdn.com/setup.sh | bash
aliyun version

Security note — the one-liner above pipes a remote script directly into bash. The script is hosted on Alibaba Cloud's official CDN (aliyuncli.alicdn.com) and served over HTTPS, so transit is authenticated. However, if your environment requires inspecting installer scripts before execution (security-hardened CI, regulated workloads, multi-tenant hosts), use the safer two-step flow in references/cli-installation-guide.md — download → inspect → execute. Do not run this command with elevated privileges (e.g. as root); the installer does not require it.

Pre-check: Alibaba Cloud CLI plugin update required

aliyun configure set --auto-plugin-install true
aliyun plugin update

Install EMAS APM Plugin

aliyun plugin install --names aliyun-cli-emas-appmonitor
aliyun plugin list | grep emas-appmonitor  # Verify version >= 0.3.1

For detailed installation instructions, see references/cli-installation-guide.md

AI-Mode Lifecycle Management

[MUST] AI-Mode — AI-mode is required for Agent Skill execution. Run the following commands before any CLI invocation:

aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-emas-apm-remotelog"

[MUST] Disable AI-Mode at EVERY exit point — Before delivering the final response for ANY reason, always disable AI-mode first.

aliyun configure ai-mode disable

Credential Verification

Pre-check: Alibaba Cloud Credentials Required

Security Rules:

  • NEVER read, echo, or print AK/SK values (e.g., echo $ALIBABA_CLOUD_ACCESS_KEY_ID is FORBIDDEN)
  • NEVER ask the user to input AK/SK directly in the conversation or command line
  • NEVER use aliyun configure set with literal credential values
  • ONLY use aliyun configure list to check credential status
aliyun configure list

Check the output for a valid profile (AK, STS, or OAuth identity).

If no valid profile exists, STOP here.

  1. Obtain credentials from Alibaba Cloud Console
  2. Configure credentials outside of this session (via aliyun configure in terminal or environment variables in shell profile)
  3. Return and re-run after aliyun configure list shows a valid profile

Data Safety: Do not save real AccessKeys in command-line parameters, scripts, or logs. Authentication is fully delegated to CLI profiles.

RAM Policy

Required Permissions: See references/ram-policies.md for the complete list of RAM permissions required by each API.

Quick Reference:

PermissionAPI
apm:GetTlogDeviceListQuery available devices
apm:GetTlogDeviceInfoGet device details
apm:CreateTlogTaskCreate log retrieval task
apm:GetTlogTaskInfoQuery task status
apm:GetTlogTaskCollectionsQuery device collection status
apm:SearchTlogQuery log details
apm:GetTlogCollectListQuery active submission records

System Policies: AliyunEMASFullAccess or AliyunEMASReadOnlyAccess

[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:

  1. Read references/ram-policies.md to get the full list of permissions required by this SKILL
  2. Use ram-permission-diagnose skill to guide the user through requesting the necessary permissions
  3. Pause and wait until the user confirms that the required permissions have been granted

Parameters Requiring User Confirmation

IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters (e.g., AppKey, OS type, device identifiers, task names, time windows, etc.) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.

[MUST] RegionId is fixed — EMAS APM service is ONLY available in cn-shanghai. Always pass --region cn-shanghai regardless of the credential's default region (e.g., even if aliyun configure list shows cn-hangzhou). Do NOT ask the user to confirm RegionId, and do NOT try other regions on failure.

ParameterRequiredDescriptionExample
RegionIdYes (fixed)EMAS APM service region — must be cn-shanghai (only supported region)cn-shanghai
AppKeyYesApplication key from EMAS console123456789
OSYesMobile OS type: android or iphoneosandroid
UserNickConditionalUser nickname for device lookuptestuser01
DeviceIdConditionalDevice unique ID (UTDID)Z1234567890ABCDEF
KeywordConditionalUser ID or custom ID for lookupuser_12345
TaskNameYes (create task)Name for the log retrieval tasktask-2024-01-15-user01
DaysYes (create task)Number of days of log history to retrieve1
OperatorNameYes (create task)Operator name (AliYunName)admin
DeviceJsonYes (create task)Device metadata JSON arraySee workflow
BeginDateYes (query logs)Start time in Unix milliseconds (13 digits)1700000000000
EndDateYes (query logs)End time in Unix milliseconds (13 digits)1700086400000
TaskIdConditionalTask ID returned from create operationtlog_task_xxxxx
PageIndexNoPage number for paginated results1
PageSizeNoNumber of results per page10
LevelJsonNo (query logs)Log level filter as JSON array["error","warning"]
KeywordNo (query logs)Log content search keywordNullPointerException
SourceTypeYes (collect list)Source type: USER or POSITIVEPOSITIVE

Core Workflow

IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.

Workflow 1: Known User — Create Retrieval Task and Query Logs

Use when you know a user's identity and need to retrieve their device logs.

Step 1: Resolve Device by Identity

# By user nickname (fuzzy/prefix match)
aliyun emas-appmonitor get-tlog-device-list \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --user-nick  \
  --page-index 1 \
  --page-size 10

# By user ID or custom ID (exact match)
aliyun emas-appmonitor get-tlog-device-list \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --keyword  \
  --page-index 1 \
  --page-size 10

# By device ID (exact match)
aliyun emas-appmonitor get-tlog-device-list \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --utdid  \
  --page-index 1 \
  --page-size 10

Optional: Query single device details:

aliyun emas-appmonitor get-tlog-device-info \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --device-id 

Step 2: Preview Task Parameters (Dry-Run)

IMPORTANT: create-tlog-task will create a real task and trigger device-side log collection. You MUST use --cli-dry-run first to preview the request body and confirm parameters.

aliyun emas-appmonitor create-tlog-task \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --ali-yun-name  \
  --days  \
  --task-name  \
  --source-type USER \
  --device-json '[{"appId":"@","appKey":"","deviceId":"","os":"","osVersion":"","appVersion":"","userName":"","brand":"","deviceModel":"","geo":""}]' \
  --cli-dry-run

Step 3: Create Task (After Confirmation)

Remove --cli-dry-run after confirming parameters:

aliyun emas-appmonitor create-tlog-task \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --ali-yun-name  \
  --days  \
  --task-name  \
  --source-type USER \
  --device-json '[{"appId":"@","appKey":"","deviceId":"","os":"","osVersion":"","appVersion":"","userName":"","brand":"","deviceModel":"","geo":""}]'

Note: On success, Model returns the taskId as a plain string (not a JSON object).

Step 4: Poll Task Status

Query overall task status:

aliyun emas-appmonitor get-tlog-task-info \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --task-id 
StatusMeaning
NORMALTask in progress
SUCCEEDEDTask completed successfully
FAILEDTask failed
SUSPENDEDTask expired
CANCELLEDTask cancelled

[MUST] Defensive existence checkget-tlog-task-info may return Success: true with an empty placeholder model even when the taskId does not exist (no TaskNotFound error). The placeholder looks like: status=NORMAL, dayNum=0, progress="0/0/0/0", collectionNums=0, and a fresh createTime equal to "now". Do NOT trust Model.status alone. Confirm the task is real by ALL of:

  • Model.dayNum > 0 (real tasks always have a configured day window)
  • Model.taskName / Model.author non-empty
  • Model.createTime is older than the request time (real tasks are not created at query time)

If the placeholder pattern is detected, treat it as task does not exist: surface this clearly to the user, and do NOT proceed to get-tlog-task-collections or search-tlog. The most common cause is a malformed or truncated taskId (e.g. a hyphen in the taskId mistakenly parsed as a CLI flag delimiter — always pass taskId quoted).

Query per-device collection status:

aliyun emas-appmonitor get-tlog-task-collections \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --task-id 
Collection StatusMeaning
STARTTask created, device has not pulled
PULL_REPLIEDDevice has task, token not applied
TOKEN_APPLIEDToken issued, waiting for upload
FILE_SENDEDFile metadata saved, waiting for parsing
FINISHEDLogs are queryable
FAIL_OVERCollection failed
SUSPENDEDTask expired
CANCELLEDTask cancelled

Step 5: Query Logs (When Device Status is FINISHED)

aliyun emas-appmonitor search-tlog \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --device-id  \
  --begin-date  \
  --end-date  \
  --page-index 1 \
  --page-size 100 \
  --level-json '["debug","info","warning","error"]' \
  --keyword 

Time Window Rules:

  • --begin-date: Use task.createTime - days * 86400000 to cover the full retrieval range
  • --end-date: Use at least task.modifyTime (task completion time) or current time; do NOT use task.createTime as this will miss logs generated after the task was created
  • All times are Unix milliseconds (13 digits)

Workflow 2: Known TaskId — Query Task Progress and Logs

Use when you already have a taskId and need to check progress and retrieve logs.

# Step 1: Check overall task status
aliyun emas-appmonitor get-tlog-task-info \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --task-id 

# Step 2: Check per-device collection status
aliyun emas-appmonitor get-tlog-task-collections \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --task-id 

# Step 3: For devices with FINISHED status, query logs
aliyun emas-appmonitor search-tlog \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --device-id  \
  --begin-date  \
  --end-date 

Workflow 3: Query Actively Submitted Logs

For user-initiated log submissions (not manually triggered retrieval):

# Step 1: Query active submission records
aliyun emas-appmonitor get-tlog-collect-list \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --source-type POSITIVE \
  --page-index 1 \
  --page-size 20 \
  --device-id 

# Step 2: For records with FINISHED status, use deviceId + createTime window to query logs
aliyun emas-appmonitor search-tlog \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --device-id  \
  --begin-date  \
  --end-date 

Note: The taskId in active submission records is a system-generated association ID and CANNOT be queried via get-tlog-task-info.

Workflow 4: Direct Log Query by Device and Time

When you already know the device and time range:

aliyun emas-appmonitor search-tlog \
  --region cn-shanghai \
  --app-key  \
  --os  \
  --device-id  \
  --begin-date  \
  --end-date  \
  --level-json '["error","warning"]' \
  --keyword 

Success Verification

For each workflow step, verify success using the methods documented in references/verification-method.md:

StepVerification Method
Plugin Installationaliyun plugin list | grep emas-appmonitor shows version >= 0.3.1
Credentialsaliyun configure list shows valid profile
Device ResolutionResponse Success: true, non-empty device list
Task Creation (Dry-Run)Request body preview matches intended parameters
Task Creation (Actual)Model returns a valid taskId string
Task StatusStatus is one of: NORMAL, SUCCEEDED, FAILED, SUSPENDED, CANCELLED
Device CollectionAt least one device reaches FINISHED status
Log QueryResponse Success: true, log entries returned
Active SubmissionRecords returned with valid status and timestamps

Best Practices

  1. Always dry-run first: Before creating a task, always use --cli-dry-run to preview and confirm request parameters.
  2. Use correct time windows: For search-tlog, calculate --begin-date as createTime - days * 86400000 and --end-date as at least modifyTime or current time.
  3. Poll with appropriate intervals: Task collection may take minutes. Poll get-tlog-task-info every 30-60 seconds.
  4. Handle task IDs correctly: Task IDs from create-tlog-task are plain strings. Active submission record taskIds are system-generated and cannot be queried with get-tlog-task-info.
  5. Use pagination: For large result sets, use --page-index and --page-size to paginate through results.
  6. Filter logs efficiently: Use --level-json and --keyword to narrow down log results.
  7. Security first: Never embed credentials in scripts or command history. Rely on CLI profiles or environment variables.
  8. Check permissions: If API calls fail with permission errors, refer to references/ram-policies.md and use the ram-permission-diagnose skill.

Reference Files

FileDescription
references/cli-installation-guide.mdAliyun CLI installation and configuration guide
references/ram-policies.mdRAM permission requirements for all APIs
references/related-commands.mdComplete CLI command reference
references/acceptance-criteria.mdCorrect/incorrect usage patterns
references/verification-method.mdStep-by-step verification procedures

Related skills

Use when a user asks what the Alibaba Cloud Remote Skills Connector can do, which hosted Alibaba Cloud skills are currently available, or requests Alibaba Cloud capability onboarding; wants to inspect, query, diagnose, audit, create, deploy, configure, update, resize, restart, repair, restore, or delete Alibaba Cloud (阿里云/Aliyun) resources; uses Chinese triggers such as 查询, 诊断, 巡检, 创建, 删除, 更新, 升配, 扩缩容, 重启, and 修复; continues an existing AgentHub task; or troubleshoots this connector's discovery/authentication—even without a product name. Exclude other clouds, general knowledge/architecture/pricing questions, and requests for local CLI/SDK/OpenAPI/Terraform/ROS execution or code.

Alicloud Service Scenario-Based Skill. Use for automating SLS (Log Service) log export to OSS (Object Storage) for cold storage archival. Triggers: "SLS", "OSS", "log export", "log shipping", "cold storage", "log archive", "Security Center log backup", "list LogStore", "view LogStore", "create export task", "delete export task", "stop export task", "start export task", "manage export task", "cleanup export task", "force delete export", "日志导出", "日志投递", "冷存储", "日志归档", "创建导出", "删除导出", "停掉导出", "暂停导出", "关闭导出", "停用导出", "终止导出", "启动导出", "查看导出", "列出导出", "清理导出".

1 installs

Alibaba Cloud SLS (Simple Log Service) log query & analysis skill. Use this skill to help users write, explain, optimize, execute, or troubleshoot SLS index...

17 installs

Route and orchestrate Alibaba Cloud Simple Log Service (SLS) work across specialist skills for application integration, index management, exact querying, exploratory analysis, and visualization. Use when the user asks which SLS skill to use, wants an overview of available SLS skills, gives a broad or ambiguous SLS goal, requests an end-to-end workflow spanning two or more supported domains, or needs a selected SLS specialist that is not installed. For a clearly scoped single-domain request with its specialist available, hand off directly without adding an unnecessary workflow.

Provide Alibaba Cloud SLS / Aliyun Log SDK installation, quickstart, usage guidance, and SDK selection advice across languages. Use when users ask how to ins...

Alibaba Cloud OpenAPI troubleshooting skill. Use this skill when the user needs to diagnose API call failures using Request ID, error codes, or error message...