IBM Cloud Docs
Viewing logs

Viewing logs

IBM Cloud® Functions is deprecated. Existing Functions entities such as actions, triggers, or sequences will continue to run, but as of 28 December 2023, you can’t create new Functions entities. Existing Functions entities are supported until October 2024. Any Functions entities that still exist on that date will be deleted. For more information, see Deprecation overview.

Logging is automatically enabled in IBM Cloud® Functions to help you troubleshoot issues. You can also use the IBM Cloud® Activity Tracker service to track how users and applications interact with the Cloud Functions service. Finally, you can view logs in IBM Log Analysis.

Viewing action logs as they occur

Cloud Functions actions can be invoked by other users, in response to various events, or as part of an action sequence. To get information about when actions were invoked and what the output was, it can be useful to monitor the action logs.

Activation data is only accessible through the Cloud Functions API (CLI or REST) for 24 hours after the action finishes processing. In addition, the activation data is also sent to your logging instance and can be accessed there for longer period of time, depending on the service plan that has been chosen for the logging instance.

You can use the Cloud Functions CLI to watch the output of actions as they are invoked.

  1. Start a polling loop that continuously checks for logs from activations.

    ibmcloud fn activation poll
    
  2. Switch to another window and invoke an action.

    ibmcloud fn action invoke /whisk.system/samples/helloWorld --param payload Bob
    

    Example output

    ok: invoked /whisk.system/samples/helloWorld with id 7331f9b9e2044d85afd219b12c0f1491
    
  3. In the polling window, you can see the activation log.

    Activation: helloWorld (7331f9b9e2044d85afd219b12c0f1491)
        2016-02-11T16:46:56.842065025Z stdout: hello bob!
    

    You might also see the logs for any actions that are run on your behalf in Cloud Functions in real time.

Viewing activation details

Cloud Functions actions can be invoked by other users, in response to various events, or as part of an action sequence. When an action is invoked, an activation record is created for that invocation. To get information about the result of the action invocation, you can get details about activations.

Activation data is only accessible through the Cloud Functions API (CLI or REST) for 24 hours after the action finishes processing. In addition, the activation data is also sent to logging and can be accessed there for a longer period of time, depending on the service plan that you chose for the logging instance. For more information, see Viewing logs in IBM Log Analysis.

You can get all activation record IDs in a namespace by running the following command.

ibmcloud fn activation list

You can get details about a specific activation record that resulted from an action invocation by running the following command. Replace <activation_ID> with the ID of the activation.

ibmcloud fn activation get <activation_ID>

See the following example for the ibmcloud fn activation get <activation_ID> command.

ok: got activation c2b36969fbe94562b36969fbe9856215
{
    "namespace": "<namespace_ID>",
    "name": "hello",
    "version": "0.0.1",
    "subject": "user@email.com",
    "activationId": "c2b36969fbe94562b36969fbe9856215",
    "start": 1532456307768,
    "end": 1532456309838,
    "duration": 2070,
    "response": {
        "status": "success",
        "statusCode": 0,
        "success": true,
        "result": {
            "done": true
        }
    },
    "logs": [],
    "annotations": [
        {
            "key": "path",
            "value": "<namespace_ID>/hello"
        },
        {
            "key": "waitTime",
            "value": 50
        },
        {
            "key": "kind",
            "value": "nodejs:6"
        },
        {
            "key": "limits",
            "value": {
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        },
        {
            "key": "initTime",
            "value": 53
        }
    ],
    "publish": false
}

| namespace | The namespace ID that this activation is in. This namespace might be different than the namespace that the action is in. | | name | The name of the action. | | version | The semantic version of the action. | | subject | The user account that activated the item. | | activationId | ID of this activation record. | | start | Time when the activation began. | | end | Time when the activation completed. | | duration | Time, in milliseconds, that it took for the activation to complete. | | response | - status: The exit status of the activation. \n - statusCode: The status code. If the action resulted in an error, this value is the HTTP error code. \n - success: The result of whether the action completed successfully. \n - result: The return value from the activation. \n For more possible outcomes, see Action executions. | | logs | Logs for this activation. | | annotations | Annotations on this action. For a list of possible activation annotations, see the annotations reference topic. | | publish | The result of whether the action is published. |

Viewing logs in IBM Log Analysis

Action logs are forwarded to an IBM Log Analysis service where they are indexed, enabling full-text search through all generated messages and convenient querying based on specific fields.

To get started, complete the following steps.

  1. Navigate to the IBM Log Analysis service and create an instance in the same region as your Cloud Functions namespace.

  2. Configure the Log Analysis instance to receive platform service logs.

You can also launch logging from your Cloud Functions dashboard by selecting Launch Logging.

Configure IBM Log Analysis

To use the IBM Log Analysis service to view the logs of your Cloud Functions actions, you need to provision an instance first. For more information about additional options, see the Getting started tutorial.

To enable an instance that is receiving Cloud Functions action logs, you need to configure the Platform Service Logs in the logging service.

Cloud Functions sends the action logs to the Log Analysis service in the same region as the Cloud Functions namespace. Actions logs of a Cloud Functions namespace in us-south are sent to a logging instance in us-south.