Context and log format

Updated at:

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.

Note
  • 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:

  • /invoke: This request is an event function invocation. /invoke indicates an Invoke function invocation request.

  • /http-invoke: This request is an HTTP function invocation. /http-invoke indicates an HTTP invoke function invocation request. Function Compute adds the Common Headers to your request (including the Path, Body, and Headers) and forwards the request to the custom runtime or the custom container image. The response headers and the response body returned by the custom runtime or the custom container image are then returned to the client.

  • /initialize: /initialize indicates that when the execution environment is created for the first time, Function Compute automatically initiates the Initialize function invocation request. Within the lifecycle of the container, it is successfully called once and only once, similar to a class constructor.

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.

Note

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