All Products
Search
Document Center

Function Compute:Context and log format

Last Updated:Feb 02, 2024

If you want to obtain context and view execution logs of a web function, you can create a custom runtime based on common request headers and log formats of custom runtimes.

Common request headers in Function Compute

The following table describes the common request headers that a custom runtime may receive 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 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 function that runs in a custom runtime or a Custom Container runtime, this parameter does not take effect 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 name of the function.

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: /http-invoke: The request is sent to invoke an HTTP function. Function Compute adds common headers to your request, which contains the information about request path, request body, and request headers. Then Function Compute forwards the request to a custom runtime or a Custom Container runtime and forwards the returned response headers and body to a 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.

Function log formats

We recommend that you enable the logging feature when you create a service in Function Compute. This way, all stdout logs that the system generates are stored in the specified project of Simple Log Service. For more information, see Configure the logging feature.

If Function Compute invokes a function in a runtime that is not a custom runtime and the request header contains x-fc-log-type" = "Tail", the response that contains the x-fc-log-result header is the log that the system generates when the system invokes the function. The maximum size of a log is 4 KB. You can view the log in the results of the function invocation in the Function Compute console.

Note

The interface you can call to specify the log level varies based on the programming language. For more information, see Basics.

References

  • For more information about functions in custom runtimes, see Overview.

  • For more information about cold starts and how to configure HTTP servers, see Principles.

  • For more information about how to invoke functions in a custom runtime, see Web functions.

  • For more information about how to implement lifecycle hooks for function instances in a custom runtime, see Lifecycle hooks for function instances.