Google Cloud Logging 擴充功能

您正在查看 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

2.0.0 版

將項目寫入 Cloud Logging 記錄。

本內容提供設定和使用此擴充功能的參考資訊。

必要條件

在透過 API 代理程式使用這個擴充功能前,您必須:

  1. 在 IAM 中,將「Logging」>「Logs Writer」角色指派給代表 Cloud Logging 系統擴充功能的專案成員。如需授予角色的操作說明,請參閱「將角色授予特定資源的服務帳戶」一節。如要進一步瞭解記錄角色,請參閱存取權控管指南

  2. 使用 Google Cloud 控制台為服務帳戶產生金鑰

  3. 使用設定參考資料新增及設定擴充功能時,請使用產生的 JSON 金鑰檔案內容。

這個擴充功能支援由位於 PostClientFlow 中的 ExtensionCallout 政策呼叫。如果您想使用ExtensionCallout 政策,從 PostClientFlow 呼叫這個擴充功能,請確認 features.allowExtensionsInPostClientFlow 標記已在貴機構中設為 true

  • 如果您是 Apigee Edge for Public Cloud 客戶,請務必與 Apigee Edge 支援團隊聯絡,確保您的機構中的 features.allowExtensionsInPostClientFlow 標記設為 true

  • 如果您是 Apigee Edge for Private Cloud 客戶,請使用 Update organization properties API 將 features.allowExtensionsInPostClientFlow 標記設為 true

關於 Cloud Logging

Cloud Logging 是 Google Cloud 作業套件的一部分。其中包括記錄檔的儲存空間、稱為記錄檔檢視器的使用者介面,以及以程式化方式管理記錄的 API。您可以使用 Cloud Logging 讀取及寫入記錄項目、搜尋及篩選記錄、匯出記錄,以及建立記錄指標。

Cloud Logging 擴充功能目前會將項目寫入記錄。詳情請參閱 Cloud Logging 說明文件

範例

以下範例說明如何使用「ExtensionCallout」政策設定 Cloud Logging 擴充功能動作支援功能。

全域記錄

以下政策會將訊息 This is a test 寫入 Cloud Global 資源中名為 example-log 的記錄。實際使用時,您可能會將訊息包含在資料流變數中,而該變數的值則是在 API 代理程式的其他位置設定。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Logging-Extension">
    <DisplayName>Logging Connector</DisplayName>
    <Connector>cloud-extension-sample</Connector>
    <Action>log</Action>
    <Input><![CDATA[{
        "logName": "example-log",
        "metadata": {
            "resource": {
                "type": "global",
                "labels": {
                    "project_id": "my-test"
                }
            }
        },
        "message": "This is a test."
    }]]></Input>
</ConnectorCallout>

這篇文章提供設定和使用此擴充功能的參考資訊。如要瞭解使用 Apigee 控制台設定擴充功能的步驟,請參閱「新增及設定擴充功能」。

動作

log

將訊息寫入記錄。

這項動作會寫入 Cloud Logging 記錄項目。記錄項目包含中繼資料和項目資料。如要進一步瞭解記錄項目,請參閱項目參考資料。如要瞭解 metadata 屬性內容,請參閱 Cloud Logging 說明文件中的 LogEntry 物件。

語法

<Action>log</Action>
<Input><![CDATA[{
  "logName" : "cloud-log-name-to-use",
  "metadata" : JSON-structured-metadata,
  "message" : "data-to-log-as-entry"
}]]></Input>

範例:字串

<Action>log</Action>
<Input><![CDATA[{
  "logName" : "example-log",
  "metadata" : { "resource" : { "type" : "global" } },
  "message": "This is a test."
}]]></Input>

範例:JSON

<Action>log</Action>
<Input><![CDATA[{
  "logName" : "example-log",
  "metadata" : { "resource" : { "type" : "global" } },
  "message" : { "info" :  "This is a test." }
}]]></Input>

要求參數

參數 說明 類型 預設 必填
logName 此項目所屬的記錄名稱。 字串
metadata 記錄項目的中繼資料。
如要進一步瞭解如何在 metadata 中設定 typelabels,以及相關選項,請參閱 MonitoredResource
JSON
message 做為此記錄項目值的資料。您可以指定簡單的字串,或使用 JSON 記錄更具結構化的訊息。 字串或 JSON

回應

None 訊息是否已寫入記錄。否則,要求會傳回錯誤。另請參閱「偵錯擴充功能」。

設定參考資料

如要設定及部署此擴充功能,以便在 API 代理程式中使用,請使用下列說明。

常見的擴充功能屬性

每個擴充功能都有下列屬性。

屬性 說明 預設 必要
name 您要為這項擴充功能設定的名稱。 相容
packageName Apigee Edge 指定的擴充功能套件名稱。 相容
version 擴充功能的擴充功能套件版本號碼。 相容
configuration 您要新增的擴充功能專屬的設定值。請參閱「這個擴充功能套件的屬性」一文 相容

這個擴充功能套件的屬性

請為下列專屬於此擴充功能的設定屬性指定值。

屬性 說明 預設 必填
projectId 應建立記錄的 Google Cloud 專案 ID。
credentials 輸入 Apigee Edge 主控台時,這就是服務帳戶金鑰檔案的內容。透過管理 API 傳送時,這會是從服務帳戶金鑰檔案產生的 base64 編碼值。