Request-level metrics provide deeper insight into every function invocation and help you understand how your functions perform. Use these metrics to quickly detect and locate issues and analyze application bottlenecks. Enable request-level metrics to better manage and optimize your function applications.
What are request-level metrics
Request-level metrics summarize the execution status of each function request. When enabled, the system collects metrics for every function execution—including performance, exception, and tracing metrics—and delivers them to the Logstore you selected during log configuration.
-
Performance metrics: memory usage, function running time, initialization time, cold start information, and more.
-
Exception metrics: whether the execution failed and error details.
-
Tracing metrics: key-path execution duration, whether distributed tracing sampling is enabled, and for HTTP functions—the path, status code, and client IP address.
After enabling request-level metrics, Function Compute delivers execution metrics for each request to your Logstore in the following format.
activeInstances: 0
activeInstancesPerFunction: 0
durationMs: 1.56
functionName: sync-clone
hasFunctionError: false
hostname: sr-65a76c74-1224f354965f43a...
instanceID: c-65a77eb0-15416274-ff5addb...
invocationStartTimestamp: 1705476027407
invocationType: Sync
invokeFunctionLatencyMs: 2.92
invokeFunctionStartTimestamp: 1705476027406
ipAddress: 21.0
isColdStart: false
memoryMB: 512
memoryUsageMB: 8.99
operation: InvokeFunction
qualifier: LATEST
requestId: 1-65a77fbb-157f3f32-e1ee24b17e49
resourceMode: OnDemand
Scenarios
-
Use request metrics to view function execution details, performance metrics, and error information.
The console provides a request list based on request-level metrics. Use this interface to view detailed information for each request, including execution status, instance ID, execution duration, memory usage, and request logs.
On the Logs tab of the function details page, select the Invocation Requests sub-tab to view the request list. Filters above the list include Show logs only for the current version or alias, Show only function errors, Show only client errors, and Show only cold start requests.
NoteYou can view the request list without enabling request-level metrics, but it may be inaccurate in the following scenarios.
-
When multiple identical RequestIds appear repeatedly—common in asynchronous invocation retry scenarios—you cannot locate logs for a specific request.
-
In custom runtime or custom image runtime environments, if your code prints both
FC Invoke Start RequestId: xxxandFC Invoke End RequestId: xxx, one invocation appears twice in the request list.
-
-
Use request metrics for custom searches and to build custom dashboards.
Request metrics are delivered to your Logstore in
key:valformat. Create custom dashboards based on your business needs. For instructions, see Create a dashboard.
Notes
-
Scope
Request-level metrics logs are a function-level configuration. Once enabled, they apply to the current function, and every execution generates one log entry.
-
Cost
Delivering logs to Simple Log Service incurs storage fees. For pricing details, see Pricing.
Enable request-level metrics
Enable request-level metrics in the console
Prerequisites
-
Function Compute
-
Simple Log Service (SLS)
Procedure
-
Log on to the Function Compute console. In the navigation pane on the left, select .
-
In the top menu bar, select a region. On the Functions page, click the target function.
-
On the function configuration page, select the Configuration tab.
-
Find Advanced Settings and click Modify on its right. In the Advanced Configuration panel, go to the Logging section, enable Instance-level Metrics, and then click Deploy.
The following table describes key configuration items. Keep all other settings at their default values.
Configuration item
Description
Example value
Logging
Whether to store function invocation logs in Simple Log ServiceSLS. For more information, see Configure logging.
Enabled
Log project
Select an existing log project.
aliyun-fc-hangzhou-2238f0df-a742-524f-9f90-976ba*******
Logstore
Select an existing Logstore.
function-log
Log segmentation rule
Whether to enable log segmentation. If enabled, Function Compute splits logs into multiple segments according to the rule and writes each segment to SLS.
Enabled
Request-level metrics
Whether to collect request-level metrics. If enabled, metrics for every function invocation are collected and delivered to the Logstore you specified in log configuration.
Enabled
Instance-level metrics
Whether to enable instance-level metrics. If enabled, instance metrics are delivered to the Logstore you specified in log configuration.
Enabled
Enable request-level metrics using Serverless Devs
Prerequisites
Procedure
-
Create a code directory with the following structure.
. ├── code │ └── index.js └── s.yamlIn the example, the enableRequestMetrics field configures request-level metrics. Before enabling it, first enable logging and set logstore and project to an existing Logstore and log project in your account.
edition: 3.0.0 name: hello-world-app access: "default" vars: # Global variables region: "cn-hangzhou" resources: hello_world: component: fc3 # Component name props: region: ${vars.region} functionName: "start-nodejs-****" description: 'hello world by serverless devs' runtime: "nodejs16" code: ./code handler: index.handler memorySize: 128 timeout: 30 logConfig: # Update logstore and project to match your setup. Alternatively, use logConfig:auto to auto-create them. enableInstanceMetrics: true enableRequestMetrics: true # Enable request-level metrics to collect execution metrics for every invocation logBeginRule: DefaultRegex logstore: 'your-logstore' project: 'your-project' -
Run the following command to deploy the application.
sudo s deploy -yAfter successful deployment, log on to the Function Compute console to confirm that request-level metrics are enabled for your deployed function.
Log query
Log format
Request-level metrics logs use the topic format: FCRequestMetrics:/functionName. In Simple Log Service, use the query condition __topic__: "FCRequestMetrics:/functionName" to filter all request-level metrics logs. For more information, see Quick guide to querying and analysis.
Metric fields
Request-level metrics record the following information.
|
Metric name |
Description |
Example value |
Recorded for every invocation? |
|
functionName |
Function name. |
my-function |
Yes |
|
versionId |
Version name. |
12 |
Yes |
|
qualifier |
Service alias. Default is LATEST. |
prod |
Yes |
|
requestId |
Request ID. |
db72ce53-ccbe-4216-af55-642622e01494 |
Yes |
|
operation |
Action name. |
InvokeFunction |
Yes |
|
invocationType |
There are two call types. Sync: synchronous call Async: asynchronous invocation |
Sync |
Yes |
|
memoryMB |
Function memory limit. |
512 |
Yes |
|
memoryUsageMB |
Memory consumed during function execution. |
410 |
Yes |
|
durationMs |
Request execution time. |
20.20 |
Yes |
|
isColdStart |
Whether this is a cold start. Note
A cold start occurs when Function Compute receives a request but has no ready function instance to handle it. The system must create a new instance, download code, and initialize the runtime environment. We define a cold start request as one that goes through the full process of instance creation, code download, and runtime initialization. Function Compute optimizes cold starts by pre-warming instances. If a request arrives while an instance is being created and finds a pre-warmed instance ready, it is not considered a cold start. |
false |
Yes |
|
instanceEvent |
Instance event. Currently only ColdStart, recorded for cold start requests. |
ColdStart |
No |
|
hasFunctionError |
Whether the function execution encountered an error. |
false |
Yes |
|
errorType |
Function errors fall into the following three types:
|
FunctionUnhandledError |
No. Recorded only when |
|
invokeFunctionLatencyMs |
Function execution time. |
99.00 |
Yes. Recorded for every invocation. |
|
traceContext |
Distributed tracing context. |
371d3ff242fcee9:371d3ff242fcee9:0:1 |
No. Recorded only when distributed tracing is configured. |
|
isSampled |
Whether the request was sampled for distributed tracing. |
true |
No. Recorded only when distributed tracing is configured. |
|
resourceMode |
Instance type used for the request:
|
OnDemand |
Yes |
|
instanceID |
Instance ID. |
c-65603d8c-37e1bf7123054a77**** |
Yes |
|
hostname |
Instance hostname. |
c-65603d8c-37e1bf7123054a77**** |
Yes |
|
ipAddress |
Instance IP address. Note: This is the internal IP used to distinguish between instances, not the public IP address. |
21.0.XX.XX |
Yes |
|
activeInstances |
Number of active instances. |
1 |
Yes |
|
activeInstancesPerFunction |
Number of active instances for this function. |
1 |
Yes |
|
scheduleLatencyMs |
Scheduling latency. Longer during cold starts. |
10.07 |
Yes |
|
coldStartStartTimestamp |
Cold start start timestamp. |
1700806029167 |
No. Recorded only during cold starts. |
|
coldStartLatencyMs |
Cold start duration. |
487.65 |
No. Recorded only during cold starts. |
|
prepareCodeStartTimestamp |
Code download start timestamp. 13-digit UNIX timestamp, millisecond precision. |
1700806029167 |
No. Recorded only during cold starts. |
|
prepareCodeLatencyMs |
Code download duration. |
0.18 |
No. Recorded only during cold starts. |
|
runtimeInitializationStartTimestamp |
Runtime initialization start timestamp. |
1700806029168 |
No. Recorded only during cold starts. |
|
runtimeInitializationMs |
Runtime initialization duration. |
487.37 |
No. Recorded only during cold starts. |
|
asyncAttemptStartTimestamp |
For asynchronous invocations, failed executions are retried up to 3 times by default. This parameter is the start timestamp of the ${retryCount}-th retry. |
1700806028084 |
No. Recorded only for asynchronous invocations. |
|
asyncAttemptLatencyMs |
For asynchronous invocations, failed executions are retried up to 3 times by default. This parameter is the duration of the ${retryCount}-th retry. |
1688.74 |
No. Recorded only for asynchronous invocations. |
|
asyncMode |
Asynchronous invocation mode:
|
Stateful |
No. Recorded only for asynchronous invocations. |
|
retryCount |
Number of retries. |
0 |
No. Recorded only for asynchronous invocations. |
Retrieve logs
To retrieve logs, you need indexes. The Function Compute console automatically configures indexes for you. After indexing, use SQL statements in the Simple Log Service console to search and filter requests in your Logstore. Specify the topic to limit results to request-level metrics logs.
For example, to find requests with execution time over 1 second, use this SQL statement.
__topic__: "FCRequestMetrics:/f1" AND qualifier: q1 and operation: InvokeFunction and durationMs>1000
For advanced query syntax, see Quick guide to querying and analysis.
Create a custom dashboard
To create a chart with time (t) on the x-axis and metric values on the y-axis, use a SQL statement like this.
__topic__: "FCRequestMetrics:/f1" AND qualifier: q1 and operation: InvokeFunction | select __time__ - __time__ % 60 as t, count(*) as invocations, avg(durationMs) as avgDurationMs group by t order by t
For more information about creating custom dashboards, see Create a dashboard.