Find out how to store and view function logs with OCI Functions.
When a function is invoked, you'll typically want to access the function's logs for troubleshooting. The Oracle Cloud Infrastructure Logging service is the default and recommended option for accessing, searching, and storing function logs. If you enable Oracle Cloud Infrastructure Logging for an application, default invocation logs are created whenever functions in the application are invoked. See Using the Console to Enable and View Function Logs in Oracle Cloud Infrastructure Logging. For more information about the contents of function logs, see Details for Functions.
Alternatively, there might be occasions when you want to send function logs to an external logging destination like Papertrail. To send logs to an external logging destination instead of the Oracle Cloud Infrastructure Logging service, you use the Fn Project CLI to specify a syslog URL. See Using Fn Project CLI Commands to Specify a syslog URL.
Note that to store and view logs for a function (other than default invocation logs stored in the Oracle Cloud Infrastructure Logging service), the function must include print statements. For example:
console.log('Entering Hello Node.js function');
System.err.println("Entering Java Hello World Function");
fmt.Println("Entering Hello Go function")
To enable and view function logs in the Oracle Cloud Infrastructure Logging service:
The log opens in the log group's Log Details page, enabling you to view log data, and sort and filter log data by time.
When searching log data, you can use the data.opcRequestId
field to filter logs by request id. If an API deployment in API Gateway invokes a function on an OCI Functions back end, you can see logs relating to both the API Gateway request and the OCI Functions request by using the same data.opcRequestId
field together with a wildcard, as follows:
"data.opcRequestId"
field in the function log and select Filter matching from the popup menu.
For example, assume the function log contains the field "data.opcRequestId": "/01FJA5VCVM0000000000025M1Z/01FJA5VCVM0000000000025M20"
. The field "data.opcRequestId": "/01FJA5VCVM0000000000025M1Z/01FJA5VCVM0000000000025M20"
is copied into the Log Search (Basic Mode) page as a filter.
"data.opcRequestId"
field value shown in the Query field with the * (asterisk) wildcard.
For example, so that it reads data.opcRequestId: '/01FJA5VCVM0000000000025M1Z/*'
From time to time, new versions of the Fn Project CLI are released. We recommend you regularly check that the latest version is installed. For more information, see Steps to upgrade the Fn Project CLI.
The Oracle Cloud Infrastructure Logging service is the default and recommended option for accessing, searching, and storing function logs.
Alternatively, you can send function logs to an external logging destination like Papertrail instead by using the Fn Project CLI to specify a syslog URL. Note that to use an external logging destination, you must have set up a VCN with public subnets and an internet gateway (see Creating the VCN and Subnets to Use with OCI Functions, if they don't exist already).
To send function logs to an external logging destination by setting the syslog URL:
To create a new application and specify that all functions in the application send their logs to an external logging destination, enter:
fn create app <app-name> --syslog-url <logging-service-url> --annotation oracle.com/oci/subnetIds='["<subnet-ocid>"]'
where:
<app-name>
is the name of the new application. Avoid entering confidential information.<logging-service-url>
is the syslog URL to which to send logs.<subnet-ocid>
is the OCID of the public subnet (or subnets, up to a maximum of six)Â in which to run functions. If a regional subnet has been defined, best practice is to select that subnet to make failover across availability domains simpler to implement. If a regional subnet has not been defined and you need to meet high availability requirements, select multiple subnets (enclose each OCID in double quotes separated by commas, in the format '["<subnet-ocid>","<subnet-ocid>"]'
. We recommend that the public subnets are in the same region as the Docker registry that's specified in the Fn Project CLI context (see Creating an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).For example:
fn create app acmeapp --syslog-url tcp://my.papertrail.com:4242 --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.phx.aaaaaaaacnh..."]'
Note that if you subsequently set up Oracle Cloud Infrastructure Logging to store logs, the existing syslog URL details are retained. So if you later decide to resume sending function logs to the external logging destination, you simply have to disable Oracle Cloud Infrastructure Logging and logs will be sent to the syslog URL again.
To update an existing application and specify that all functions in the application send their logs to an external logging destination, enter:
fn update app <app-name> --syslog-url <logging-service-url>
where:
<app-name>
is the name of the application to update<logging-service-url>
is the syslog URL to which to send logsFor example:
fn update app acmeapp --syslog-url tcp://my.papertrail.com:4242
To update an existing application and remove the external logging destination specified for the syslog URL, enter:
fn update app <app-name> --syslog-url ''
where:
<app-name>
is the name of the application to updateFor example:
fn update app acmeapp --syslog-url ''
In earlier OCI Functions releases (prior to the release of the Oracle Cloud Infrastructure Logging service), you could specify where OCI Functions stores a function's logs by setting up a 'logging policy' for the application containing the function. Previously, you could use the Console to set up a logging policy to:
Store logs as objects in a storage bucket in Oracle Cloud Infrastructure Object Storage by selecting the OCI Logging option.
To view function logs in a storage bucket, the group to which you belong must have been granted access with the following identity policy statements:
Allow group <group-name> to manage object-family in compartment <compartment-name>
Allow group <group-name> to read objectstorage-namespaces in compartment <compartment-name>
(Usually created when configuring your tenancy for function development. See Policy Statements to Give OCI Functions Users Access to Oracle Cloud Infrastructure Registry Repositories.)For an existing application where you have previously already set up a logging policy, the above functionality is still supported and the existing logging policy is applied. However, note the following:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4