Google Cloud Logging 擴充功能

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

1.6.1 版

將項目寫入 Cloud Logging 記錄檔。

本文提供設定和使用這個擴充功能的參考資料。

必要條件

從 API Proxy 使用這個擴充功能前,您必須:

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

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

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

這項擴充功能支援位於 PostClientFlow 中的 Extension callout 政策。如要使用 Extension callout 政策,從 PostClientFlow 呼叫這個擴充功能,請確認貴機構的 features.allowExtensionsInPostClientFlow 旗標已設為 true

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

  • 如果您是 Private Cloud 適用的 Apigee Edge,請使用更新機構屬性 API,將 features.allowExtensionsInPostClientFlow 標記設為 true

關於 Cloud Logging

Cloud Logging 是 Google Cloud 作業套件的一部分。當中包含用於儲存記錄檔的使用者介面、名為「記錄檔探索工具」的使用者介面,以及用於透過程式輔助方式管理記錄檔的 API。您可以透過 Cloud Logging 讀取及寫入記錄項目、搜尋及篩選記錄、匯出記錄,以及建立記錄指標。

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

範例

以下範例說明如何使用擴充功能呼叫政策,為 Cloud Logging 擴充功能動作設定支援。

全域記錄檔

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

<?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 控制台設定擴充功能的相關步驟,請參閱「新增及設定擴充功能」。

動作

紀錄/記錄檔

將訊息寫入記錄。

這個動作會寫入 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 Proxy,請按照下列指示操作。

常見擴充功能屬性

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

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

這個擴充功能套件的屬性

指定這個擴充功能的下列設定屬性值。

屬性 說明 預設 需要
projectId 應建立記錄檔的 Google Cloud 專案 ID。
credentials 在 Apigee Edge 控制台中輸入時,這是服務帳戶金鑰檔案的內容。透過 Management API 傳送時,是由服務帳戶金鑰檔案產生的 Base64 編碼值。