將數據從 OpenTelemetry 內嵌至 Azure 數據總管

重要

此連接器可用於 Microsoft Fabric 中的即時智慧 。 使用本文中的指示,但有下列例外狀況:

OpenTelemetry (OTel) 是應用程式可觀察性的開放架構。 檢測是由 Cloud Native Computing Foundation (NCF) 所裝載,其提供標準介面供可觀察性數據使用,包括 計量記錄追蹤。 OTel 收集器是由下列三個元件所組成: 接收者 會處理如何將數據放入收集器、 處理器 決定如何處理接收的數據,而 匯出者 負責傳送接收數據的位置。

Azure 數據總 管匯出工具 支援將數據從許多接收者擷取至 Azure 數據總管。

注意

在本文中,您將學會如何:

  • 設定您的環境
  • 設定 Azure 資料總管匯出工具
  • 執行範例應用程式
  • 查詢傳入數據

必要條件

設定您的環境

在本節中,您會準備環境以使用 OTel 導出工具。

建立 Microsoft Entra 應用程式註冊

Microsoft Entra 應用程式驗證用於需要存取 Azure 數據總管且沒有用戶的應用程式。 若要使用 OTel 匯出工具擷取數據,您需要建立並註冊Microsoft Entra 服務主體,然後授權此主體內嵌 Azure 數據總管資料庫的數據。

  1. 使用 Azure 數據總管叢集,請遵循在 Azure 數據總管中建立Microsoft Entra 應用程式註冊中的步驟 1-7。
  2. 儲存下列值,以供後續步驟使用:
    • 應用程式 (用戶端) 識別碼
    • 目錄 (租用戶) 識別碼
    • 用戶端秘密金鑰值

授與Microsoft Entra 應用程式許可權

  1. 在 Web UI 的 [查詢] 索引標籤中,連線到您的叢集。 如需如何連線的詳細資訊,請參閱 新增叢集

  2. 流覽至您要內嵌數據的資料庫。

  3. 執行下列管理命令,取代佔位元。 將 DatabaseName 取代為目標資料庫的名稱,並將 ApplicationID 取代為先前儲存的值。 此命令會授與應用程式 資料庫擷取器 角色。 如需詳細資訊,請參閱 管理資料庫安全性角色

    .add database <DatabaseName> ingestors ('aadapp=<ApplicationID>') 'Azure Data Explorer App Registration'
    

    注意

    最後一個參數是一個字串,當您查詢與資料庫相關聯的角色時,會顯示為附注。 如需詳細資訊,請參閱 檢視現有的安全性角色

建立目標數據表

  1. 流覽至 Azure 數據總管 Web UI

  2. 從左側功能表中選取 [查詢 ]。

  3. 展開左窗格中的目標叢集。

  4. 選取目標資料庫,為您的查詢提供正確的內容。

  5. 執行下列命令來建立傳入資料的數據表和架構對應:

    .create-merge table <Logs-Table-Name> (Timestamp:datetime, ObservedTimestamp:datetime, TraceID:string, SpanID:string, SeverityText:string, SeverityNumber:int, Body:string, ResourceAttributes:dynamic, LogsAttributes:dynamic) 
    
    .create-merge table <Metrics-Table-Name> (Timestamp:datetime, MetricName:string, MetricType:string, MetricUnit:string, MetricDescription:string, MetricValue:real, Host:string, ResourceAttributes:dynamic,MetricAttributes:dynamic) 
    
    .create-merge table <Traces-Table-Name> (TraceID:string, SpanID:string, ParentID:string, SpanName:string, SpanStatus:string, SpanKind:string, StartTime:datetime, EndTime:datetime, ResourceAttributes:dynamic, TraceAttributes:dynamic, Events:dynamic, Links:dynamic) 
    

設定串流擷取

Azure 數據總管有兩種主要的擷取類型:批處理和串流。 如需詳細資訊,請參閱 批處理與串流擷取。 串 方法在 Azure 數據總管匯出工具組態中稱為 Managed 。 如果您需要近乎即時的記錄和追蹤,串流擷取可能是不錯的選擇。 不過,串流擷取會使用比批次擷取更多的資源。 OTel 架構本身會批處理數據,這在選擇要用於擷取的方法時應考慮這些數據。

注意

必須在 Azure 資料總管叢集上啟用串流擷取 ,才能啟用 managed 選項。 您可以使用 .show 資料庫串流擷取原則命令來檢查串流是否已啟用

針對這三個資料表執行下列命令,以啟用串流擷取:

.alter table <Table-Name> policy streamingingestion enable

設定 Azure 資料總管匯出工具

若要將 OpenTelemetry 數據內嵌至 Azure 數據總管,您需要 使用下列 Azure 數據總管匯出工具設定來部署並執行 OpenTelemetry 散發套件。

  1. 使用下列欄位設定 Azure 資料總管匯出工具:

    欄位 描述 建議的設定
    出口商 匯出工具類型 Azure 資料總管
    cluster_uri 保存資料庫和數據表的 Azure 數據總管叢集 URI https:// <cluster.kusto.windows.net>
    application_id Client ID <應用程式識別碼>
    application_key 用戶端密碼 <應用程式金鑰>
    tenant_id 租用戶 <應用程式租使用者>
    db_name 接收記錄的資料庫 db 或其他您已建立的資料庫
    metrics_table_name 資料庫中的目標數據表db_name儲存導出的計量數據。 METRICS
    logs_table_name 資料庫中的目標數據表db_name儲存導出的記錄數據。 ELECTEDLogs
    traces_table_name 資料庫中的目標數據表db_name儲存導出的追蹤數據。 打法
    ingestion_type 擷取類型:Managed(串流)或批次 已管理的
    metrics_table_json_mapping 選擇性的 參數。 默認數據表對應是在根據 OTeL 計量屬性建立資料表期間定義的。 您可以使用此參數來變更預設對應。 <json metrics_table_name對應>
    logs_table_json_mapping 選擇性的 參數。 默認數據表對應是在根據 OTeL 記錄屬性建立資料表期間定義的。 您可以使用此參數來變更預設對應。 <json logs_table_name對應>
    traces_table_json_mapping 選擇性的 參數。 默認數據表對應是在根據 OTeL 追蹤屬性建立資料表期間定義的。 您可以使用此參數來變更預設對應。 <json traces_table_name對應>
    traces 服務:追蹤要啟用的元件 接收者:[otlp]
    處理器:[批次]
    導出者:[azuredataexplorer]
    metrics 服務:要啟用的計量元件 接收者:[otlp]
    處理器:[批次]
    導出者:[azuredataexplorer]
    記錄 服務:記錄要啟用的元件 接收者:[otlp]
    處理器:[批次]
    導出者:[azuredataexplorer]
  2. 使用 「--config」 旗標來執行 Azure 數據總管導出工具。

以下是 Azure 資料總管匯出工具的範例組態:

---
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
processors:
  batch:
exporters:
  azuredataexplorer:
    cluster_uri: "https://<cluster>.kusto.windows.net"
    application_id: "<application id>"
    application_key: "<application key>"
    tenant_id: "<application tenant>"
    db_name: "oteldb"
    metrics_table_name: "OTELMetrics"
    logs_table_name: "OTELLogs"
    traces_table_name: "OTELTraces"
    ingestion_type : "managed"
    metrics_table_json_mapping : "<json metrics_table_name mapping>"
    logs_table_json_mapping  : "<json logs_table_name mapping>"
    traces_table_json_mapping  : "<json traces_table_name mapping>"
service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuredataexplorer]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuredataexplorer]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [azuredataexplorer]

使用範例應用程式收集數據

現在已設定收集器,您必須傳送要擷取的數據。 在此範例中, 您可以使用範例 spring pet 診所 應用程式搭配 java OTeL 收集器代理程式。

  1. 在這裡下載收集器代理程序: 開啟遙測收集器代理程式

  2. 若要啟用範例應用程式的開啟遙測,請設定下列環境變數。 open-telemetry-collector-host 會參考 Azure 數據總管導出工具設定和執行所在的主機。

    $env:OTEL_SERVICE_NAME="pet-clinic-service"
    $env:OTEL_TRACES_EXPORTER="otlp"
    $env:OTEL_LOGS_EXPORTER="otlp "                   
    $env:OTEL_EXPORTER_OTLP_ENDPOINT="http://<open-telemetry-collector-host>:4317"
    
  3. 使用下列命令行自變數執行範例 spring-boot 應用程式:

    java -javaagent:./opentelemetry-javaagent.jar -jar spring-petclinic-<version>-SNAPSHOT.jar    
    

查詢傳入數據

執行範例應用程式之後,您的數據已內嵌至 Azure 數據總管中定義的數據表。 這些數據表是在 OTel 收集器組態 中定義為 db 的資料庫中建立的。 您已建立的數據表定義於 OTel 收集器組態中。 在此範例中,您已建立三個數據表: METRICsSTATICLogsSTATICTraces。 在本節中,您會個別查詢每個數據表,以取得一小部分的可用數據。

  1. 流覽至 Azure 數據總管 Web UI

  2. 從左側功能表中選取 [查詢 ]。

  3. 展開左窗格中的目標叢集。

  4. 選取 db 資料庫,為您的查詢提供正確的內容。

  5. 依序複製/貼上下列查詢,以查看每個資料表的任意數目數據列:

    • 計量

      OTELMetrics
      |take 2
      

      您應該取得類似但與下表完全相同的結果:

      時間戳記 MetricName MetricType MetricUnit MetricDescription MetricValue Host MetricAttributes ResourceAttributes
      2022-07-01T12:55:33Z http.server.active_requests Sum requests 目前在進行中的並行 HTTP 要求數目 0 DESKTOP-SFS7RUQ {“http.flavor”:“1.1”, “http.host”:“localhost:8080”, “scope.name”:“io.opentelemetry.tomcat-7.0”, “scope.version”:“1.14.0-alpha”, “http.method”:“GET”, “http.scheme”:“http”} {“host.name”:“DESKTOP-SFS7RUQ”, “process.command_line”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“, ”process.runtime.description“:”Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6“, ”process.runtime.version“:”18.0.1.1+2-6“, ”telemetry.sdk.language“:”java“, ”host.arch“:”amd64“, ”process.runtime.name“:”Java(TM) SE Runtime Environment“, ”telemetry.auto.version“:”1.14.0“, ”telemetry.sdk.name“:”opentelemetry“, ”os.type“:”windows“, ”os.description“:”Windows 11 10.0“, ”process.executable.path“:”C:\ProgramFiles\Java\jdk-18.0.1.1;站;java.exe“、”process.pid“:5980、”service.name“:”my-service“、”telemetry.sdk.version“:”1.14.0“}
      2022-07-01T12:55:33Z http.server.duration_sum 長條圖 毫秒 輸入 HTTP 要求的持續時間(範例總計總和) 114.9881 DESKTOP-SFS7RUQ {“http.flavor”:“1.1”, “http.host”:“localhost:8080”, “scope.name”:“io.opentelemetry.tomcat-7.0”, “scope.version”:“1.14.0-alpha”, “http.method”:“GET”, “http.scheme”:“http”, “http.route”:“/owners/find”, “http.status_code”:200} {“host.name”:“DESKTOP-SFS7RUQ”, “process.command_line”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“, ”process.runtime.description“:”Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6“, ”process.runtime.version“:”18.0.1.1+2-6“, ”telemetry.sdk.language“:”java“, ”host.arch“:”amd64“, ”process.runtime.name“:”Java(TM) SE Runtime Environment“, ”telemetry.auto.version“:”1.14.0“, ”telemetry.sdk.name“:”opentelemetry“, ”os.type“:”windows“, ”os.description“:”Windows 11 10.0“, ”process.executable.path“:”C:\ProgramFiles\Java\jdk-18.0.1.1;站;java.exe“、”process.pid“:5980、”service.name“:”my-service“、”telemetry.sdk.version“:”1.14.0“}
    • 記錄

      OTELLogs
      |take 2
      

      您應該取得類似但與下表完全相同的結果:

      時間戳記 TraceId SpanId SeverityText SeverityNumber 本文 ResourceAttributes LogsAttributes
      2022-07-01T13:00:39Z INFO 9 在具有 PID 37280 的 DESKTOP-SFS7RUQ上使用 Java 18.0.1.0-SNAPSHOT 啟動 PetClinicApplication v2.7.0-SNAPSHOT (C:\Users\adxuser\Documents\Repos\spring-petclinic\target\spring-petclinic-2.7.0-SNAPSHOT.jar由 C:\Users\adxuser\Documents\Repos\spring-petclinic) {“host.name”:“DESKTOP-SFS7RUQ”, “process.executable.path”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe“、”process.pid“:37280、”process.runtime.description“:”Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6“、”process.runtime.name“:”Java(TM) SE Runtime Environment“、”telemetry.sdk.name“:”opentelemetry“, ”os.type“:”windows“, ”process.runtime.version“:”18.0.1.1+2-6“, ”telemetry.sdk.language“:”java“, ”telemetry.sdk.version“:”1.14.0“, ”process.command_line“:”C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“、”os.description“:”Windows 11 10.0“、”service.name“:”my-service“、”telemetry.auto.version“:”1.14.0“、”host.arch“:”amd64“} {“scope.name”:“org.springframework.samples.petclinic.PetClinicApplication”}
      2022-07-01T13:00:39Z INFO 9 未設定使用中配置檔,回復為1個默認配置檔:“default” {“host.name”:“DESKTOP-SFS7RUQ”, “process.executable.path”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe“、”process.pid“:37280、”process.runtime.description“:”Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6“、”process.runtime.name“:”Java(TM) SE Runtime Environment“、”telemetry.sdk.name“:”opentelemetry“, ”os.type“:”windows“, ”process.runtime.version“:”18.0.1.1+2-6“, ”telemetry.sdk.language“:”java“, ”telemetry.sdk.version“:”1.14.0“, ”process.command_line“:”C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“、”os.description“:”Windows 11 10.0“、”service.name“:”my-service“、”telemetry.auto.version“:”1.14.0“、”host.arch“:”amd64“} {“scope.name”:“org.springframework.samples.petclinic.PetClinicApplication”}
    • 追蹤

      OTELTraces
      |take 2
      

      您應該取得類似但與下表完全相同的結果:

      TraceId SpanId ParentId SpanName SpanStatus SpanKind StartTime EndTime ResourceAttributes TraceAttributes 事件 連結
      573c0e4e002a9f7281f6d63eafe4ef87 dab70d0ba8902c5e 87d003d6-02c1-4f3d-8972-683243c35642 STATUS_CODE_UNSET SPAN_KIND_CLIENT 2022-07-01T13:17:59Z 2022-07-01T13:17:59Z {“telemetry.auto.version”:“1.14.0”, “os.description”:“Windows 11 10.0”, “process.executable.path”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe「、」process.runtime.description」:“Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6”, “service.name”:“my-service”, “process.runtime.name”:“Java(TM) SE Runtime Environment”, “telemetry.sdk.language”:“java”, “telemetry.sdk.name”:“opentelemetry”, “host.arch”:“amd64”, “host.name”:“DESKTOP-SFS7RUQ”, “process.pid”:34316, “process.runtime.version”:“18.0.1.1+2-6”, “os.type”:“windows”, “process.command_line”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“、”telemetry.sdk.version“:”1.14.0“} {“db.user”:“sa”, “thread.id”:1, “db.name”:“87d003d6-02c1-4f3d-8972-683243c35642”, “thread.name”:“main”, “db.system”:“h2”, “scope.name”:“io.opentelemetry.jdbc”, “scope.version”:“1.14.0-alpha”, “db.connection_string”:“h2:mem:”, “db.statement”:“DROP TABLE vet_specialties IF EXISTS”} [] []
      84a9a8c4009d91476da02dfa40746c13 3cd4c0e91717969a 87d003d6-02c1-4f3d-8972-683243c35642 STATUS_CODE_UNSET SPAN_KIND_CLIENT 2022-07-01T13:17:59Z 2022-07-01T13:17:59Z {“telemetry.auto.version”:“1.14.0”, “os.description”:“Windows 11 10.0”, “process.executable.path”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe「、」process.runtime.description」:“Oracle Corporation Java HotSpot(TM) 64 位伺服器 VM 18.0.1.1+2-6”, “service.name”:“my-service”, “process.runtime.name”:“Java(TM) SE Runtime Environment”, “telemetry.sdk.language”:“java”, “telemetry.sdk.name”:“opentelemetry”, “host.arch”:“amd64”, “host.name”:“DESKTOP-SFS7RUQ”, “process.pid”:34316, “process.runtime.version”:“18.0.1.1+2-6”, “os.type”:“windows”, “process.command_line”:“C:\Program Files\Java\jdk-18.0.1.1;站;java.exe -javaagent:./opentelemetry-javaagent.jar“、”telemetry.sdk.version“:”1.14.0“} {“db.user”:“sa”, “thread.id”:1, “db.name”:“87d003d6-02c1-4f3d-8972-683243c35642”, “thread.name”:“main”, “db.system”:“h2”, “scope.name”:“io.opentelemetry.jdbc”, “scope.version”:“1.14.0-alpha”, “db.connection_string”:“h2:mem:”, “db.statement”:“DROP TABLE vets IF EXISTS”} [] []

進一步數據處理

使用更新原則時,可以視應用程式需求進一步處理收集的數據。 如需詳細資訊,請參閱 更新原則概觀

  1. 下列範例會將直方圖計量導出至具有貯體和匯總的直方圖特定數據表。 在 Azure 資料總管 Web UI 的查詢窗格中執行下列命令:

    .create table HistoBucketData (Timestamp: datetime, MetricName: string , MetricType: string , Value: double, LE: double, Host: string , ResourceAttributes: dynamic, MetricAttributes: dynamic )
    
    .create function 
    with ( docstring = "Histo bucket processing function", folder = "UpdatePolicyFunctions") ExtractHistoColumns()
    {
        OTELMetrics
        | where MetricType == 'Histogram' and MetricName has "_bucket"
        | extend f=parse_json(MetricAttributes)
        | extend le=todouble(f.le)
        | extend M_name=replace_string(MetricName, '_bucket','')
        | project Timestamp, MetricName=M_name, MetricType, MetricValue, LE=le, Host, ResourceAttributes, MetricAttributes
    }
    
    .alter table HistoBucketData policy update 
    @'[{ "IsEnabled": true, "Source": "OTELMetrics","Query": "ExtractHistoColumns()", "IsTransactional": false, "PropagateIngestionProperties": false}]'
    
  2. 下列命令會建立數據表,其中只包含直方圖計量類型的計數和總和值,並附加更新原則。 在 Azure 資料總管 Web UI 的查詢窗格中執行下列命令:

     .create table HistoData (Timestamp: datetime, MetricName: string , MetricType: string , Count: double, Sum: double, Host: string , ResourceAttributes: dynamic, MetricAttributes: dynamic)
    
     .create function 
    with ( docstring = "Histo sum count processing function", folder = "UpdatePolicyFunctions") ExtractHistoCountColumns()
    {
       OTELMetrics
        | where MetricType =='Histogram'
        | where MetricName has "_count"
        | extend Count=MetricValue
        | extend M_name=replace_string(MetricName, '_bucket','')
        | join kind=inner (OTELMetrics
        | where MetricType =='Histogram'
        | where MetricName has "_sum"
        | project Sum = MetricValue , Timestamp)
     on Timestamp | project Timestamp, MetricName=M_name, MetricType, Count, Sum, Host, ResourceAttributes, MetricAttributes
    }
    
    .alter table HistoData policy update 
    @'[{ "IsEnabled": true, "Source": "RawMetricsData","Query": "ExtractHistoCountColumns()", "IsTransactional": false, "PropagateInge