Querying a Trace List
Function
This API is used to query records of operations on resources in the last seven days.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
cts:trace:list
List
-
-
-
-
URI
GET /v3/{project_id}/traces
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Project ID. For details, see Obtaining an Account ID and Project ID. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
trace_type |
Yes |
String |
Trace type. The value can be system (management trace) or data (data trace). The default value is system. |
|
from |
No |
Long |
UTC millisecond timestamp of the query start time. The value contains 13 numbers and the default value is the timestamp of the last hour. Traces generated after the specified timestamp will be queried. The parameters from and to should be used together. |
|
next |
No |
String |
This parameter is used to query traces generated earlier than its specified value. The value can be that of marker in the response. next can be used with from and to. Traces generated in the overlap of the two time ranges specified respectively by next and by from and to will be returned. |
|
to |
No |
Long |
UTC millisecond timestamp of the query end time. The value contains 13 numbers and the default value is the timestamp of the current time. Traces generated before the specified timestamp will be queried. The parameters to and from should be used together. |
|
tracker_name |
No |
String |
When trace_type is set to system, the value of this parameter is system. When trace_type is set to data, set this parameter to the name of a data tracker to query the traces recorded by this tracker. |
|
service_type |
No |
String |
Cloud service on which the recorded operation was performed. The value must be the acronym of a cloud service that has been connected with CTS. It is a word composed of uppercase letters. This parameter is valid only when trace_type is set to system. For cloud services that are connected with CTS, see section "Supported Services and Operations" in the Cloud Trace Service User Guide. |
|
user |
No |
String |
Name of a user whose traces are to be queried. This parameter is valid only when trace_type is set to system. |
|
resource_name |
No |
String |
Name of a resource whose traces are to be queried. This parameter is valid only when trace_type is set to system. The value can contain uppercase letters. |
|
resource_type |
No |
String |
Type of a resource whose traces are to be queried. This parameter is valid only when trace_type is set to system. |
|
resource_id |
No |
String |
ID of a cloud resource whose traces are to be queried. This parameter is valid only when trace_type is set to system. |
|
limit |
No |
Integer |
Maximum number of traces returned in the trace list. The default value is 10 and the maximum value is 200. |
|
trace_id |
No |
String |
Trace ID. If this parameter is specified, other query criteria will not take effect. This parameter is valid only when trace_type is set to system. |
|
trace_name |
No |
String |
Trace name. This parameter is valid only when trace_type is set to system. The value can contain uppercase letters. |
|
trace_rating |
No |
String |
Trace status. The value can be normal, warning, or incident. This parameter is valid only when trace_type is set to system. |
|
access_key_id |
No |
String |
ID of the access key used to query traces. It contains temporary access credentials and permanent access keys. |
|
enterprise_project_id |
No |
String |
ID of an enterprise project whose traces are to be queried. |
Request Parameters
None
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
traces |
Array of Traces objects |
Returned list of traces. |
|
meta_data |
MetaData object |
Number of returned traces and the marker. |
|
Parameter |
Type |
Description |
|---|---|---|
|
resource_id |
String |
ID of the cloud resource on which the recorded operation was performed. |
|
trace_name |
String |
Trace name. The value contains 1 to 64 characters and must start with a letter. Only letters, numbers, hyphens (-), underscores (_), and periods (.) are allowed. |
|
trace_rating |
String |
Trace status. The value can be normal, warning, or incident. |
|
trace_type |
String |
Trace source. For management traces, the value can be ApiCall, ConsoleAction, or SystemAction.For data traces, the value can be ObsSDK or ObsAPI. |
|
request |
String |
Request body of the recorded operation. |
|
response |
String |
Response body of the recorded operation. |
|
code |
String |
Returned HTTP status code of the recorded operation. |
|
api_version |
String |
Version of the API called in the trace. |
|
message |
String |
Remarks added by other cloud services to the trace. |
|
record_time |
Long |
Timestamp when a trace was recorded by CTS. |
|
trace_id |
String |
Trace ID. The value is the UUID generated by the system. |
|
time |
Long |
Timestamp when a trace was generated. |
|
user |
UserInfo object |
Information of the user who performed the operation that triggered the trace. |
|
service_type |
String |
Cloud service on which the recorded operation was performed. The value must be the acronym of a cloud service that has been connected with CTS. It is a word composed of uppercase letters. |
|
resource_type |
String |
Type of the resource on which the recorded operation was performed. |
|
source_ip |
String |
IP address of the tenant who performed the operation that triggered the trace. |
|
resource_name |
String |
Name of the resource on which the recorded operation was performed. |
|
request_id |
String |
ID of the request of the recorded operation. |
|
location_info |
String |
Information required for fault locating after a request error occurred. |
|
endpoint |
String |
Endpoint in the details page URL of the cloud resource on which the recorded operation was performed. |
|
resource_url |
String |
Details page URL (excluding the endpoint) of the cloud resource on which the recorded operation was performed. |
|
enterprise_project_id |
String |
ID of the enterprise project to which the resource belongs. |
|
resource_account_id |
String |
ID of the account to which the resource belongs. This parameter has a value only when resources are operated across tenants. |
|
read_only |
Boolean |
Whether a user request is read-only. |
|
operation_id |
String |
Operation ID of the trace. |
|
Parameter |
Type |
Description |
|---|---|---|
|
id |
String |
User ID. For details, see section "Obtaining an Account ID and Project ID" in Cloud Trace Service API Reference. |
|
name |
String |
Username. |
|
user_name |
String |
Username. |
|
domain |
BaseUser object |
Domain information of the user who performed the operation that triggered the trace. |
|
account_id |
String |
Account ID. For details, see section "Obtaining an Account ID and Project ID" in Cloud Trace Service API Reference. |
|
access_key_id |
String |
Access key ID. |
|
principal_urn |
String |
URN of the operator.
|
|
principal_id |
String |
Identity ID of the operator.
|
|
principal_is_root_user |
String |
Whether the operator is a root user.
|
|
type |
String |
Operator identity type. |
|
invoked_by |
Array of strings |
Name of the service that sends the request. For operations on the console, the value is ["service.console"]. |
|
session_context |
SessionContext object |
Temporary security credential attribute. |
|
Parameter |
Type |
Description |
|---|---|---|
|
id |
String |
Account ID. For details, see section "Obtaining the Account ID and Project ID" in Cloud Trace Service API Reference. |
|
name |
String |
Account name. |
|
Parameter |
Type |
Description |
|---|---|---|
|
attributes |
Attributes object |
Temporary security credential attribute. |
|
Parameter |
Type |
Description |
|---|---|---|
|
created_at |
String |
Timestamp when a temporary security credential was issued. The value is a 13-digit UTC time in milliseconds. |
|
mfa_authenticated |
String |
Whether MFA identity authentication has been passed. |
|
Parameter |
Type |
Description |
|---|---|---|
|
count |
Integer |
Number of returned traces. |
|
marker |
String |
ID of the last trace returned. The value of this parameter can be used as the value of next. If the value of marker is null, all traces have been returned under the specified query criteria. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 403
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 404
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 500
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Status code: 503
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code. Format: CTS.XXX. |
|
error_msg |
String |
Error message. |
Example Requests
-
Querying management traces
GET https://{endpoint}/v3/{project_id}/traces?limit=11&to=1479095278000&from=1478490478000&trace_name=createTracker&resource_type=tracker&service_type=CTS&trace_type=system -
Querying data traces
GET https://{endpoint}/v3/{project_id}/traces?limit=11&to=1479095278000&from=1478490478000&trace_type=data
Example Responses
Status code: 200
The request is successful.
{
"traces" : [ {
"request" : "",
"code" : "204",
"source_ip" : "192.168.0.92",
"trace_type" : "ConsoleAction",
"read_only" : false,
"operation_id" : "DeletePublicip",
"trace_id" : "9650eb5a-f57c-11ef-8503-ef3069828c92",
"trace_name" : "deleteEip",
"resource_type" : "publicip",
"trace_rating" : "normal",
"api_version" : "v3",
"message" : "",
"service_type" : "EIP",
"response" : "",
"resource_id" : "3224b58b-fca5-4902-a2a3-05757f29da22",
"resource_account_id" : "230657***34fcd9",
"time" : 1740710091805,
"resource_name" : "-",
"request_id" : "4eb208ad0b84115d2825c1f1b4482ff1",
"user" : {
"access_key_id" : "HSTAM5***37Z39R",
"invoked_by" : [ "service.console" ],
"account_id" : "230657***34fcd9",
"user_name" : "test",
"domain" : {
"name" : "paas_cts_z00418070_01",
"id" : "230657***34fcd9"
},
"name" : "test",
"session_context" : {
"attributes" : {
"created_at" : "1740710036558",
"mfa_authenticated" : "false"
}
},
"principal_is_root_user" : "false",
"id" : "969ba3***28d3d0",
"principal_urn" : "iam::230657***34fcd9:user:test",
"type" : "User",
"principal_id" : "969ba3***28d3d0"
},
"record_time" : 1740710091805
}, {
"request" : "tag_types=predefine&domainId=230657***34fcd9",
"trace_id" : "7f64160a-f57c-11ef-8503-ef3069828c92",
"code" : "200",
"trace_name" : "getResourceTags",
"resource_type" : "tags",
"trace_rating" : "normal",
"api_version" : "1.0",
"source_ip" : "10.63.127.2",
"trace_type" : "ConsoleAction",
"service_type" : "TMS",
"read_only" : true,
"operation_id" : "GetResourceTags",
"resource_account_id" : "230657***34fcd9",
"time" : 1740710053352,
"user" : {
"access_key_id" : "HSTAM5***37Z39R",
"invoked_by" : [ "service.console" ],
"account_id" : "230657***34fcd9",
"user_name" : "test",
"domain" : {
"name" : "paas_cts_z00418070_01",
"id" : "230657***34fcd9"
},
"name" : "test",
"session_context" : {
"attributes" : {
"created_at" : "1740710036558",
"mfa_authenticated" : "false"
}
},
"principal_is_root_user" : "false",
"id" : "969ba3***28d3d0",
"principal_urn" : "iam::230657***34fcd9:user:test",
"type" : "User",
"principal_id" : "969ba3***28d3d0"
},
"record_time" : 1740710053352
} ],
"meta_data" : {
"count" : 2
}
}
SDK Sample Code
The SDK sample code is as follows.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cts.v3.region.CtsRegion; import com.huaweicloud.sdk.cts.v3.*; import com.huaweicloud.sdk.cts.v3.model.*; public class ListTracesSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); CtsClient client = CtsClient.newBuilder() .withCredential(auth) .withRegion(CtsRegion.valueOf("<YOUR REGION>")) .build(); ListTracesRequest request = new ListTracesRequest(); try { ListTracesResponse response = client.listTraces(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcts.v3.region.cts_region import CtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcts.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = CtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(CtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListTracesRequest() response = client.list_traces(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cts.NewCtsClient( cts.CtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListTracesRequest{} response, err := client.ListTraces(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
The request is successful. |
|
400 |
The query parameters are abnormal. |
|
401 |
The request is rejected due to authentication failure. |
|
403 |
The server understood the request but refused to authorize it. |
|
404 |
The requested trace does not exist. |
|
500 |
The server has received the request but encountered an internal error. |
|
503 |
The requested service is unavailable. The client should not repeat the request without modifications. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot