You can refer to the common headers and log format of Custom Container runtimes to view the context and execution logs of functions that run in Custom Container runtimes. You can use obtained information to create a custom runtime based on your business requirements.
Common request headers
The following table lists the common request headers that a Custom Container runtime receives from Function Compute. If you want to access other Alibaba Cloud services, you may need to use the request headers that specify a temporary AccessKey pair. If you want to migrate existing applications to Function Compute, ignore the following information.
Note
Both event functions and HTTP functions contain common request headers.
Common request headers are automatically generated by Function Compute. Common request headers contain permission information and basic information about a function.
Header | Description |
x-fc-request-id | The request ID. |
x-fc-access-key-id | The temporary AccessKey ID. |
x-fc-access-key-secret | The temporary AccessKey secret. |
x-fc-security-token | The temporary security token. |
x-fc-function-handler | The handler of the function. If the runtime is a function, such as a custom runtime or a Custom Container function, the value is ignored and can be set to a random string. |
x-fc-function-memory | The maximum memory that a function can use. |
x-fc-region | The region where a function resides. |
x-fc-account-id | The user ID (UID) of a function owner. |
x-fc-qualifier | The service version or alias that you specify when you invoke a function. For more information, see Use versions and aliases to implement canary release. |
x-fc-version-id | The service version that you specify when you invoke a function. |
x-fc-function-name | The function name. |
x-fc-service-logproject | The Simple Log Service project that is configured for the service to which a function belongs. |
x-fc-service-logstore | The Simple Log Service Logstore that is configured for the service to which a function belongs. |
x-fc-control-path | The request type of a function. For a custom runtime or a Custom Container, you can check whether you sent a request to invoke an HTTP function or an event function based on the value of this parameter. Valid values: /invoke: The request is sent to invoke an event function. /http-invoke: The request is sent to invoke an HTTP function. Function Compute adds common headers to your request, which contains the request path, body, and headers, and forwards the request to a custom runtime or a Custom Container runtime. Function Compute also forwards the returned response headers and body to the client. /initialize: The request that is automatically initiated by Function Compute to call an Initializer hook the first time you create a runtime environment. Similar to a class constructor, an Initializer hook is invoked only once in the lifecycle of a container.
|
Log format
We recommend that you enable the logging feature when you create a service in Function Compute. All logs that are printed to stdout in a Custom Container runtime are automatically collected in your specified Simple Log Service Logstore. For more information, see Configure the logging feature.
In Function Compute runtimes other than custom runtimes and Custom Container runtimes, if the request header contains x-fc-log-type" = "Tail"
,the returned content that contains the x-fc-log-result
header are function execution logs. Each log can be up to 4 KB in size. You can view the logs in the results of function invocation in the Function Compute console.
Note
The API you can call to specify the log level varies based on the programming language. For more information, see Basics.
References
If your function runs in a Custom Container runtime, the base environment on which a container image depends requires extra time to download and decompress data. To optimize cold starts, see the "Best practices for cold start optimization" section in the Overview topic.
For more information about how to create a function in a Custom Container runtime, see Create a Custom Container function.
For more information about how to implement lifecycle hooks for function instances in a Custom Container runtime, see Lifecycle hooks for function instances.