Context and log format

更新时间:
复制 MD 格式

Custom Container runtimes receive context information from Function Compute through HTTP request headers. All output written to stdout is automatically collected as logs in Simple Log Service (SLS).

Common request headers

Function Compute automatically injects the following headers into every request it sends to a Custom Container runtime. Both event functions and HTTP functions receive these headers. Use the credential headers to access other Alibaba Cloud services, or read the metadata headers to inspect invocation context at runtime.

If you are migrating an existing application to Function Compute and do not need this context, ignore these headers.

Common request headers are automatically generated by Function Compute. These headers contain permission information and basic information about a function.
To access credentials via x-fc-access-key-id, x-fc-access-key-secret, and x-fc-security-token, first configure a role for your function. Function Compute then calls the AssumeRole API to generate temporary credentials and inject them as headers on each invocation.
HeaderDescription
x-fc-request-idThe request ID for this invocation.
x-fc-access-key-idThe temporary AccessKey ID. Requires a role to be configured for the function.
x-fc-access-key-secretThe temporary AccessKey secret. Requires a role to be configured for the function.
x-fc-security-tokenThe temporary security token. Requires a role to be configured for the function.
x-fc-function-handlerThe handler configured for the function. For Custom Container functions, this value is ignored and can be any string.
x-fc-function-memoryThe maximum memory the function is allowed to use.
x-fc-regionThe region where the function runs.
x-fc-account-idThe user ID (UID) of the function owner.
x-fc-qualifierThe service version or alias specified when invoking the function. See Use versions and aliases to implement canary release.
x-fc-version-idThe service version that you specify when you invoke a function.
x-fc-function-nameThe function name.
x-fc-service-logprojectThe Simple Log Service project configured for the service.
x-fc-service-logstoreThe Simple Log Service Logstore configured for the service.
x-fc-control-pathThe invocation type. See the values below.

x-fc-control-path values

ValueMeaning
/invokeAn event function invocation.
/http-invokeAn HTTP function invocation. Function Compute adds the common request headers to the original request (preserving its path, body, and headers) and forwards it to the runtime. The runtime's response headers and body are forwarded back to the client.
/initializeThe Initializer hook call. Function Compute sends this request automatically the first time it creates a runtime environment for the function. Like a class constructor, the Initializer hook runs only once per container lifecycle.

Log format

All output written to stdout in a Custom Container runtime is automatically collected in the Simple Log Service Logstore configured for the service. We recommend that you configure the logging feature when you create the service.

Inline log retrieval (non-custom runtimes)

For runtimes other than custom runtimes and Custom Container runtimes, set the x-fc-log-type: Tail request header to retrieve execution logs inline in the response. When this header is set, the response includes the x-fc-log-result header containing the function execution logs. Each log entry is limited to 4 KB. View logs in the Function Compute console.

The API for setting the log level varies by programming language. For details, see Basics.

What's next