Instance-level events

Updated at:

Instance-level events give you visibility into the full lifecycle of a function instance — from creation through destruction. Use events to understand what happened during each lifecycle phase and to pinpoint the root cause when a request fails or takes longer than expected.

How instance lifecycle works

Function Compute dynamically creates and destroys instances based on incoming request volume. Each instance passes through three phases:

  1. Creating — Function Compute sets up the instance: pulling code, layers, or images; starting the runtime; and running the initializer hook.

  2. Invoke — The instance processes function invocations. Between invocations, the instance is frozen and does not incur charges.

  3. Destroy — The instance is torn down. Function Compute runs the PreStop callback before destruction.

image

Function Compute records the time of each significant state change within these phases as an instance-level event. Events are visible on the instance details page in the console and are stored in the Logstore you configure for instance-level metrics.

Instance lifecycle phases

Creating phase

When an instance is created, Function Compute completes the following steps in sequence:

  1. Instance Create — Loads your code package, pulls layers, or pulls the container image (for custom container runtimes). Then starts the instance process.

  2. Runtime Init — Starts the runtime and runs a health check.

  3. Init Hook — Runs your initializer hook, if configured.

image

Instance creation is triggered in two scenarios:

  • Elastic scale-out: A new invocation arrives and all existing instances are busy, so Function Compute creates a new instance to handle it. Elastic scale-out may cause cold starts. See Best practices for optimizing Function Compute cold starts for ways to reduce cold start latency.

  • Minimum instance count increase: When you raise the minimum instance count from 0 to 1 or more, Function Compute immediately creates the required instances. These instances may remain idle for some time before receiving their first invocation. See Configure elastic policy for minimum instance count.

Invoke phase

Once running, an instance invokes your function handler to process requests. Concurrency behavior differs by runtime type:

  • Built-in runtimes: Each instance handles one request at a time.

  • Custom runtimes and custom container runtimes: A single instance can handle multiple concurrent requests. Enable this by configuring single-instance concurrency.

Function Compute bills only for actual request and callback execution time. See Billing details.

Instance freeze mechanism

When no requests are pending, Function Compute freezes the instance. Background processes, threads, and coroutines stop running — asynchronous log writes may not complete. The instance is unfrozen when the next request arrives.

image

Freezing occurs at two points:

  • After the Creating phase completes, before the first invocation.

  • After each invocation ends, before the next invocation begins.

Destroy phase

Destruction is triggered in three scenarios:

  • Instance shallow hibernation (formerly idle): The instance receives no invocations for a specific period and is automatically reclaimed.

  • Minimum instance count reduction: When you lower the minimum instance count, excess instances are immediately destroyed.

  • Instance failure: If the instance fails during creation or execution, Function Compute destroys it.

During destruction, Function Compute runs the PreStop callback first, giving your code a chance to flush state or close connections before the instance is removed.

Instance statuses

The following table lists the statuses a function instance can be in and the sub-statuses within the Creating phase.

StatusDescription
CreatingInstance is being created.
↳ ImagePullingContainer image is being pulled (custom container runtimes only).
↳ CodePreparingCode package is being pulled and mounted.
↳ LayerPreparingLayers are being pulled and mounted.
↳ RuntimeInitializingInstance is starting and undergoing the health check.
↳ InitializingInitializer hook is running.
↳ FinishedInstance created successfully.
↳ FailedInstance creation failed.
RunningInstance is running and processing invocations.
DestroyedInstance has been destroyed.
ErrorInstance cannot process invocations and is about to be destroyed.

The following diagram shows how these statuses transition and which events mark each transition.

image

Event types

The following table lists all instance-level events. Warning-level events indicate a problem that requires action.

Event nameEvent codeLevelWhat it meansWhat to do
Instance creatingfc:Instance:CreatingNormalFunction Compute has started creating an instance for your request.
Code loadedfc:Instance:PrepareCodeSuccessNormalCode package pulled and mounted successfully. Function Compute applies optimizations that can make this step very fast.
Code loading failedfc:Instance:PrepareCodeFailedWarningFailed to pull or mount the code package.Join the DingTalk user group (Group ID: 64970014484) for support.
Layer loadedfc:Instance:PrepareLayerSuccessNormalLayers pulled and mounted successfully. Under certain conditions, this occurs at the same time as code loading.
Layer loading failedfc:Instance:PrepareLayerFailedWarningFailed to pull or mount layers.Join the DingTalk user group (Group ID: 64970014484) for support.
Image readyfc:Instance:PullImageSuccessNormalContainer image pulled successfully (custom container runtimes only).
Image preparation failedfc:Instance:PullImageFailedWarningFailed to pull the container image.Join the DingTalk user group (Group ID: 64970014484) for support.
Instance startup successfulfc:Instance:RuntimeInitializationSuccessNormalInstance started and passed the health check.
Instance startup failurefc:Instance:RuntimeInitializationFailedWarningInstance failed the health check after startup.Check instance logs and troubleshoot using the Error handling guide for custom runtime errors.
Initializer execution successfulfc:Instance:InitializationSuccessNormalInitializer hook ran successfully.
Initializer execution failedfc:Instance:InitializationFailedWarningInitializer hook failed.Review the request logs and adjust your initializer hook logic.
Instance creation successfulfc:Instance:CreateSuccessNormalInstance is ready to process invocations.
Instance creation failedfc:Instance:CreateFailedWarningInstance creation failed and the instance is being destroyed.
Instance destroyedfc:Instance:DestroySuccessNormalInstance has been destroyed.

View instance-level events

Prerequisites

Before you begin, ensure that you have:

  • Enabled instance-level metrics. See Configure instance-level metrics. Event data is delivered to the Logstore you specify when configuring instance-level metrics.

View events in the Function Compute console

  1. Log on to the Function Compute console. In the left navigation pane, choose Function Management > Function.

  2. In the top menu bar, select a region. On the Function page, click the target function.

  3. On the function details page, click the Logs tab, then click the Invocation Requests tab.

  4. Click the instance ID of the target request. The instance details panel opens and displays the instance-level events for that instance.

View raw event logs in Simple Log Service

  1. Follow steps 1–3 above to reach the Invocation Requests tab.

  2. In the Actions column of the target request, click Advanced Logs. You are redirected to the Simple Log Service console.

  3. Filter logs by topic name. Topic names follow the format FCInstanceEvents:/<functionname>.

Next steps