Azure Monitor での OpenTelemetry の新しいメトリック機能

Microsoft は、.NET、Node.js、および Python アプリケーション用の Azure Monitor OpenTelemetry Exporter パッケージの一連の更新プログラムをプレビュー用にリリースしました。 新しい機能には、Azure Monitor Application Insights (AMAI) への OpenTelemetry メトリックのエクスポート、トレースとスパンのサンプリングの強化された制御、Azure Monitor Application Insights への一時的な切断時のテレメトリ データのキャッシュと配信の再試行が含まれます。

Azure Monitor は、クラウドおよびオンプレミス環境からインフラストラクチャおよびアプリケーションのテレメトリ データを収集、分析、および対応するための一連のツールです。 AMAI は Azure Monitor 内のツールの 1 つで、ユーザーにアプリケーション パフォーマンス監視 (APM) を提供します。 さらに、Azure Monitor Application Insights は、複数のアプリケーションにわたる、オブザーバビリティ パラダイムの柱の 1 つである分散トレースをサポートしています。

OpenTelemetry は、テレメトリ データを使用、変換、および Observability バックエンドにエクスポートするための、ベンダーに依存しない API、SDK、およびツールを提供するフレームワークです。 2021 年のブログ投稿で、Microsoft は、OpenTelemetry をより広範な Azure Monitor エコシステムと統合するためのロードマップを概説しました。 これの当面の焦点は、OpenTelemetry ベースのアプリケーションから AMAI への直接エクスポーターを構築することでした。これは、OpenTelemetry コレクターを介して OTLP エクスポーターから Azure Monitor への OpenTelemetry のデファクト ルートではありません。

ソース: https://techcommunity.microsoft.com/t5/image/serverpage/image-id/310068i9B27CD875E4A14E0/image-dimensions/1700?v=v2&px=-1

OpenTelemetry トレースが配置された Node.js アプリケーションのダイレクト エクスポーターのサンプルは次のようになります。

const { AzureMonitorTraceExporter } = require("@azure/monitor-opentelemetry-exporter");
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");


const provider = new NodeTracerProvider({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
  }),
});
provider.register();

// Create an exporter instance
const exporter = new AzureMonitorTraceExporter({
  connectionString:
    process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || ""
});

// Add the exporter to the provider
provider.addSpanProcessor(
  new BatchSpanProcessor(exporter, {
    bufferTimeout: 15000,
    bufferSize: 1000
  })
);

Azure Monitor OpenTelemetry Exporter パッケージの新しい更新プログラムのリリースにより、以下に示すように、メトリックを AMAI にエクスポートできるようになりました。

const { MeterProvider, PeriodicExportingMetricReader } = require("@opentelemetry/sdk-metrics");
const { Resource } = require("@opentelemetry/resources");
const { AzureMonitorMetricExporter } = require("@azure/monitor-opentelemetry-exporter");

// Add the exporter into the MetricReader and register it with the MeterProvider
const provider = new MeterProvider();
const exporter = new AzureMonitorMetricExporter({
  connectionString:
    process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "",
});
const metricReaderOptions = {
  exporter: exporter,
};
const metricReader = new PeriodicExportingMetricReader(metricReaderOptions);
provider.addMetricReader(metricReader);
);

Application Insights に送信されるテレメトリ データの量を管理するために、パッケージには、送信されるトレースの割合を制御するサンプラーが含まれるようになりました。 前の Node.js トレースの例では、次のようになります。

import { ApplicationInsightsSampler, AzureMonitorTraceExporter } from "@azure/monitor-opentelemetry-exporter";

// Sampler expects a sample rate of between 0 and 1 inclusive
// A rate of 0.75 means approximately 75% of traces are sent
const aiSampler = new ApplicationInsightsSampler(0.75);
const provider = new NodeTracerProvider({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
  }),
  sampler: aiSampler
});

最後に、AMAI への接続に失敗した場合、ダイレクト エクスポーターはペイロードをローカル ストレージに書き込み、48 時間にわたって定期的に再配信を試みます。 これらの設定は、以下に示すように、エクスポーターのインスタンス化で構成できます。

const exporter = new AzureMonitorTraceExporter({
    connectionString:
        process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"],
    storageDirectory: "C:\SomeDirectory",     // your desired location
    disableOfflineStorage: false               // enabled by default, set to disable
});

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent News

Editor's Pick