Context and log format
In a custom container image function, if you need to obtain the context or view execution logs, see the common request headers and log format of the custom container image. You can use this information to build your own custom runtime environment.
Function Compute common request headers
The following table lists the common request headers that a custom container image receives from Function Compute. If you need to access other Alibaba Cloud services, you may need the headers that carry the temporary AccessKey. If you need to migrate an existing application, you can ignore the following content.
-
Both event functions and HTTP functions contain Common Headers.
-
The common request headers are automatically generated by Function Compute and mainly contain permission information and basic information about the function.
|
Header |
Description |
|
x-fc-request-id |
Request ID. |
|
x-fc-access-key-id |
The temporary AccessKey ID. After you configure a role for the function, Function Compute calls the AssumeRole API to obtain this key ID. |
|
x-fc-access-key-secret |
The temporary AccessKey secret. After you configure a role for the function, Function Compute calls the AssumeRole API to obtain this temporary key. |
|
x-fc-security-token |
The temporary security token. After you configure a role for the function, Function Compute calls the AssumeRole API to obtain this temporary key token. |
|
x-fc-function-handler |
The handler of the function. If the runtime itself is a function, such as a custom runtime or a custom container image function, this value is not applicable, and you can set it to a random string. |
|
x-fc-function-memory |
The maximum memory that the function can use. |
|
x-fc-region |
The region in which the function resides. |
|
x-fc-account-id |
The UID of the function owner. |
|
x-fc-qualifier |
The service version or alias specified for the function invocation. For more information, see Implement canary releases with versions and aliases. |
|
x-fc-version-id |
The service version specified for the function invocation. |
|
x-fc-function-name |
The function name. |
|
x-fc-service-logproject |
The log project configured for the service to which the function belongs. |
|
x-fc-service-logstore |
The Logstore configured for the service to which the function belongs. |
|
x-fc-control-path |
The request type of the function. For a custom runtime or a custom container image, you can determine whether a function invocation is an HTTP function invocation or an event function invocation based on the parameters in the Headers. The parameters are as follows:
|
Function log format
(Recommended) Enable the logging feature when you create a service. All logs printed to standard output (Stdout) in the custom container image are automatically collected to the Log Service that you specify. For instructions, see Configure the logging feature.
Function Compute functions invoked in other runtime environments, that is, runtime environments other than a custom runtime or a custom container image, return execution logs in the response header when the request header contains x-fc-log-type: Tail. The x-fc-log-result field in the returned response header contains the log printed when the function is executed. The log is limited to 4 KB. You can view this log in the Function Compute console function execution result.
The interfaces for specifying the log level differ across programming languages. Configure the log level based on your actual runtime environment. For more information, see Function Compute basics.
References
-
When you use a custom container image function, the base environment on which the container image depends introduces additional time for downloading and decompressing data. To reduce the cold start time, see Best practices for cold start optimization.
-
For instructions on how to create a custom container image function, see Create a custom container function.
-
For how a custom container image implements function instance lifecycle hooks, see Instance lifecycle hooks.