Bu kılavuz, Azure Monitor OpenTelemetry dağıtımını kullanarak Azure Monitor Application Insights'ta OpenTelemetry (OTel) yapılandırmanın nasıl yapılacağını açıklamaktadır. Uygun yapılandırma. .NET, Java, Node.jsve Python uygulamalarında tutarlı telemetri verilerinin toplanmasını sağlayarak daha güvenilir izleme ve tanılama sağlar.
Bağlantı dizesi
Application Insights'taki bir bağlantı dizesi, telemetri verilerini göndermek için hedef konumu tanımlar.
bağlantı dizesi yapılandırmak için aşağıdaki üç yoldan birini kullanın:
Dosyanıza UseAzureMonitor()
ekleyinprogram.cs
:
var builder = WebApplication.CreateBuilder(args);
// Add the OpenTelemetry telemetry service to the application.
// This service will collect and send telemetry data to Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
options.ConnectionString = "<Your Connection String>";
});
var app = builder.Build();
app.Run();
Ortam değişkeni ayarlayın.
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
Yapılandırma dosyanıza appsettings.json
aşağıdaki bölümü ekleyin.
{
"AzureMonitor": {
"ConnectionString": "<Your Connection String>"
}
}
Not veya Dikkat
bağlantı dizesi birden fazla yerde ayarlarsanız, aşağıdaki önceliğe bağlıyız:
- Kod
- Ortam değişkeni
- Yapılandırma Dosyası
bağlantı dizesi yapılandırmak için aşağıdaki iki yoldan birini kullanın:
Uygulamanın başlangıcında her OpenTelemetry sinyaline Azure Monitor Exporter'ı ekleyin.
// Create a new OpenTelemetry tracer provider.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAzureMonitorTraceExporter(options =>
{
options.ConnectionString = "<Your Connection String>";
})
.Build();
// Create a new OpenTelemetry meter provider.
// It is important to keep the MetricsProvider instance active throughout the process lifetime.
var metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddAzureMonitorMetricExporter(options =>
{
options.ConnectionString = "<Your Connection String>";
})
.Build();
// Create a new logger factory.
// It is important to keep the LoggerFactory instance active throughout the process lifetime.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(logging =>
{
logging.AddAzureMonitorLogExporter(options =>
{
options.ConnectionString = "<Your Connection String>";
});
});
});
Ortam değişkeni ayarlayın.
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
Not veya Dikkat
bağlantı dizesi birden fazla yerde ayarlarsanız, aşağıdaki önceliğe bağlıyız:
- Kod
- Ortam değişkeni
bağlantı dizesi yapılandırmak için aşağıdaki iki yoldan birini kullanın:
Ortam değişkeni ayarlayın.
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
Bir parametre ayarlayın.
applicationinsights.connection.string=<Your Connection String>
bağlantı dizesi yapılandırmak için aşağıdaki iki yoldan birini kullanın:
Ortam değişkeni ayarlayın.
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
Yapılandırma nesnesi kullanın.
// Import the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions class from the @azure/monitor-opentelemetry package.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
// Create a new AzureMonitorOpenTelemetryOptions object.
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: "<your connection string>"
}
};
// Enable Azure Monitor integration using the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions object.
useAzureMonitor(options);
bağlantı dizesi yapılandırmak için aşağıdaki iki yoldan birini kullanın:
Ortam değişkeni ayarlayın.
APPLICATIONINSIGHTS_CONNECTION_STRING=<Your Connection String>
configure_azure_monitor
işlevini kullanın.
# Import the `configure_azure_monitor()` function from the `azure.monitor.opentelemetry` package.
from azure.monitor.opentelemetry import configure_azure_monitor
# Configure OpenTelemetry to use Azure Monitor with the specified connection string.
# Replace `<your-connection-string>` with the connection string of your Azure Monitor Application Insights resource.
configure_azure_monitor(
connection_string="<your-connection-string>",
)
Bulut Rolü Adını ve Bulut Rolü Örneğini Ayarlama
Desteklenen diller için Azure İzleyici OpenTelemetry Distro kaynak bağlamını otomatik olarak algılar ve bileşeninizin Bulut Rolü Adı ve Bulut Rolü Örneği özellikleri için varsayılan değerler sağlar. Ancak, varsayılan değerleri ekibiniz için anlamlı bir değerle geçersiz kılmak isteyebilirsiniz. Bulut rolü adı değeri, Uygulama Haritası'nda düğümün altındaki ad olarak görünür.
Kaynak öznitelikleri aracılığıyla Bulut Rolü Adını ve Bulut Rolü Örneğini ayarlayın. Bulut Rolü Adı, service.namespace
ve service.name
özniteliklerini kullanır, ancak service.name
ayarlanmadıysa, service.namespace
özniteliğine geri döner. Bulut Rolü Örneği öznitelik değerini kullanır service.instance.id
. Kaynakların standart öznitelikleri hakkında bilgi için bkz . OpenTelemetry Semantic Conventions.
// Setting role name and role instance
// Create a dictionary of resource attributes.
var resourceAttributes = new Dictionary<string, object> {
{ "service.name", "my-service" },
{ "service.namespace", "my-namespace" },
{ "service.instance.id", "my-instance" }};
// Create a new ASP.NET Core web application builder.
var builder = WebApplication.CreateBuilder(args);
// Add the OpenTelemetry telemetry service to the application.
// This service will collect and send telemetry data to Azure Monitor.
builder.Services.AddOpenTelemetry()
.UseAzureMonitor()
// Configure the ResourceBuilder to add the custom resource attributes to all signals.
// Custom resource attributes should be added AFTER AzureMonitor to override the default ResourceDetectors.
.ConfigureResource(resourceBuilder => resourceBuilder.AddAttributes(resourceAttributes));
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
Kaynak öznitelikleri aracılığıyla Bulut Rolü Adını ve Bulut Rolü Örneğini ayarlayın. Bulut Rolü Adı, service.namespace
ve service.name
özniteliklerini kullanır, ancak service.name
ayarlanmadıysa, service.namespace
özniteliğine geri döner. Bulut Rolü Örneği öznitelik değerini kullanır service.instance.id
. Kaynakların standart öznitelikleri hakkında bilgi için bkz . OpenTelemetry Semantic Conventions.
// Setting role name and role instance
// Create a dictionary of resource attributes.
var resourceAttributes = new Dictionary<string, object> {
{ "service.name", "my-service" },
{ "service.namespace", "my-namespace" },
{ "service.instance.id", "my-instance" }};
// Create a resource builder.
var resourceBuilder = ResourceBuilder.CreateDefault().AddAttributes(resourceAttributes);
// Create a new OpenTelemetry tracer provider and set the resource builder.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
// Set ResourceBuilder on the TracerProvider.
.SetResourceBuilder(resourceBuilder)
.AddAzureMonitorTraceExporter()
.Build();
// Create a new OpenTelemetry meter provider and set the resource builder.
// It is important to keep the MetricsProvider instance active throughout the process lifetime.
var metricsProvider = Sdk.CreateMeterProviderBuilder()
// Set ResourceBuilder on the MeterProvider.
.SetResourceBuilder(resourceBuilder)
.AddAzureMonitorMetricExporter()
.Build();
// Create a new logger factory and add the OpenTelemetry logger provider with the resource builder.
// It is important to keep the LoggerFactory instance active throughout the process lifetime.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(logging =>
{
// Set ResourceBuilder on the Logging config.
logging.SetResourceBuilder(resourceBuilder);
logging.AddAzureMonitorLogExporter();
});
});
Bulut rolü adını ayarlamak için:
- Spring Boot yerel görüntü uygulamaları için kullanın
spring.application.name
-
quarkus.application.name
Quarkus yerel görüntü uygulamaları için kullanın
Kaynak öznitelikleri aracılığıyla Bulut Rolü Adını ve Bulut Rolü Örneğini ayarlayın. Bulut Rolü Adı, service.namespace
ve service.name
özniteliklerini kullanır, ancak service.name
ayarlanmadıysa, service.namespace
özniteliğine geri döner. Bulut Rolü Örneği öznitelik değerini kullanır service.instance.id
. Kaynakların standart öznitelikleri hakkında bilgi için bkz . OpenTelemetry Semantic Conventions.
// Import the useAzureMonitor function, the AzureMonitorOpenTelemetryOptions class, the Resource class, and the SemanticResourceAttributes class from the @azure/monitor-opentelemetry, @opentelemetry/resources, and @opentelemetry/semantic-conventions packages, respectively.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
const { Resource } = require("@opentelemetry/resources");
const { SemanticResourceAttributes } = require("@opentelemetry/semantic-conventions");
// Create a new Resource object with the following custom resource attributes:
//
// * service_name: my-service
// * service_namespace: my-namespace
// * service_instance_id: my-instance
const customResource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "my-service",
[SemanticResourceAttributes.SERVICE_NAMESPACE]: "my-namespace",
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: "my-instance",
});
// Create a new AzureMonitorOpenTelemetryOptions object and set the resource property to the customResource object.
const options: AzureMonitorOpenTelemetryOptions = {
resource: customResource
};
// Enable Azure Monitor integration using the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions object.
useAzureMonitor(options);
Kaynak öznitelikleri aracılığıyla Bulut Rolü Adını ve Bulut Rolü Örneğini ayarlayın. Bulut Rolü Adı, service.namespace
ve service.name
özniteliklerini kullanır, ancak service.name
ayarlanmadıysa, service.namespace
özniteliğine geri döner. Bulut Rolü Örneği öznitelik değerini kullanır service.instance.id
. Kaynakların standart öznitelikleri hakkında bilgi için bkz . OpenTelemetry Semantic Conventions.
ve/veya OTEL_RESOURCE_ATTRIBUTES
ortam değişkenlerini kullanarak OTEL_SERVICE_NAME
Kaynak özniteliklerini ayarlayın.
OTEL_RESOURCE_ATTRIBUTES
virgülle ayrılmış bir dizi anahtar-değer çifti alır. Örneğin, Bulut Rolü Adı'nı my-namespace.my-helloworld-service
olarak ve Bulut Rolü Örneği'ni my-instance
olarak ayarlamak için, OTEL_RESOURCE_ATTRIBUTES
ve OTEL_SERVICE_NAME
'ü şu şekilde ayarlayabilirsiniz:
export OTEL_RESOURCE_ATTRIBUTES="service.namespace=my-namespace,service.instance.id=my-instance"
export OTEL_SERVICE_NAME="my-helloworld-service"
Resource özniteliğini service.namespace
ayarlamazsanız, alternatif olarak Bulut Rolü Adı'nı yalnızca OTEL_SERVICE_NAME ortam değişkeni veya service.name
Resource özniteliğiyle ayarlayabilirsiniz. Örneğin, Bulut Rolü Adı'nı my-helloworld-service
olarak ve Bulut Rolü Örneği'ni my-instance
olarak ayarlamak için, OTEL_RESOURCE_ATTRIBUTES
ve OTEL_SERVICE_NAME
'ü şu şekilde ayarlayabilirsiniz:
export OTEL_RESOURCE_ATTRIBUTES="service.instance.id=my-instance"
export OTEL_SERVICE_NAME="my-helloworld-service"
Örneklemeyi Etkinleştir
Veri alımı hacminizi azaltmak ve maliyetlerinizi azaltmak için örneklemeyi etkinleştirmek isteyebilirsiniz. Azure İzleyici, Olayları örnekleme oranıyla dolduran ve Application Insights'ın 'a dönüştürdüğü özel ItemCount
örnekleyici sağlar. Sabit oranlı örnekleyici doğru deneyimler ve olay sayıları sağlar. Örnekleyici, izlemelerinizi hizmetler arasında korumak için tasarlanmıştır ve eski Application Insights Yazılım Geliştirme Setleri (SDK' lar) ile birlikte çalışabilir. Daha fazla bilgi için bkz . Örnekleme hakkında daha fazla bilgi edinin.
Not veya Dikkat
Ölçümler ve Günlükler, örnekleme nedeniyle etkilenmez.
Application Insights'ta beklenmeyen ücretler veya yüksek maliyetler görüyorsanız bu kılavuz yardımcı olabilir. Yüksek telemetri hacmi, veri alımı ani artışları ve yanlış yapılandırılmış örnekleme gibi yaygın nedenleri kapsar. Özellikle maliyet artışları, telemetri hacmi, örneklemenin çalışmaması, veri üst sınırı, yüksek veri alımı veya beklenmeyen faturalama ile ilgili sorunları gideriyorsanız kullanışlıdır. Başlamak için bkz. Application Insights'ta yüksek veri alımı sorunlarını giderme.
Örnekleyici, 0 ile 1 (dahil) arasında bir örnek oranı bekler. 0,1 oranı, izlemelerinizin yaklaşık %10'unun gönderildiği anlamına gelir.
// Create a new ASP.NET Core web application builder.
var builder = WebApplication.CreateBuilder(args);
// Add the OpenTelemetry telemetry service to the application.
// This service will collect and send telemetry data to Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
// Set the sampling ratio to 10%. This means that 10% of all traces will be sampled and sent to Azure Monitor.
options.SamplingRatio = 0.1F;
});
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
Örnekleyici, 0 ile 1 (dahil) arasında bir örnek oranı bekler. 0,1 oranı, izlemelerinizin yaklaşık %10'unun gönderildiği anlamına gelir.
// Create a new OpenTelemetry tracer provider.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAzureMonitorTraceExporter(options =>
{
// Set the sampling ratio to 10%. This means that 10% of all traces will be sampled and sent to Azure Monitor.
options.SamplingRatio = 0.1F;
})
.Build();
3.4.0'dan itibaren hız sınırlı örnekleme kullanılabilir ve artık varsayılandır. Örnekleme hakkında daha fazla bilgi için bkz . Java örneklemesi.
Örnekleyici, 0 ile 1 (dahil) arasında bir örnek oranı bekler. 0,1 oranı, izlemelerinizin yaklaşık %10'unun gönderildiği anlamına gelir.
// Import the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions class from the @azure/monitor-opentelemetry package.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
// Create a new AzureMonitorOpenTelemetryOptions object and set the samplingRatio property to 0.1.
const options: AzureMonitorOpenTelemetryOptions = {
samplingRatio: 0.1
};
// Enable Azure Monitor integration using the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions object.
useAzureMonitor(options);
İşlev, Application Insights SDK'larıyla configure_azure_monitor()
uyumluluk ve telemetrinizi örneklemek için ApplicationInsightsSampler'ı otomatik olarak kullanır. Ortam OTEL_TRACES_SAMPLER_ARG
değişkeni, 0 ile 1 arasında geçerli bir aralıkla örnekleme hızını belirtmek için kullanılabilir; burada 0 %0, 1 ise %100 olur.
Örneğin, 0,1 değeri izlemelerinizin %10'unun gönderildiği anlamına gelir.
export OTEL_TRACES_SAMPLER_ARG=0.1
İpucu
Sabit oran/yüzde örnekleme kullanırken ve örnekleme hızının ne olarak ayarlanacağından emin değilseniz% 5'te başlayın. (0,05 örnekleme oranı) Hatalar ve performans bölmelerinde gösterilen işlemlerin doğruluğuna göre hızı ayarlayın. Daha yüksek bir oran genellikle daha yüksek doğrulukla sonuçlanır. Ancak, HERHANGI bir örnekleme doğruluğu etkiler, bu nedenle örneklemeden etkilenmeyen OpenTelemetry ölçümlerinde uyarı göndermenizi öneririz.
Canlı ölçümler
Canlı ölçümler , uygulama etkinliği ve performansıyla ilgili içgörüler için gerçek zamanlı bir analiz panosu sağlar.
Varsayılan olarak bu özellik etkindir.
Kullanıcılar, Distro'yu yapılandırırken Canlı Ölçümleri devre dışı bırakabilir.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options => {
// Disable the Live Metrics feature.
options.EnableLiveMetrics = false;
});
Bu özellik Azure İzleyici .NET Exporter'da kullanılamaz.
Not veya Dikkat
Canlı ölçümleri içermeyen konsol ve çalışan hizmeti uygulamaları için Azure İzleyici OpenTelemetry Exporter'ı öneririz.
Canlı Ölçümler bugün GraalVM yerel uygulamaları için kullanılamıyor.
Kullanıcılar, enableLiveMetrics
özelliğini kullanarak Dağıtım yapılandırılırken Canlı Ölçümleri etkinleştirebilir veya devre dışı bırakabilir.
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString:
process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"] || "<your connection string>",
},
enableLiveMetrics: false
};
useAzureMonitor(options);
Canlı ölçümleri etkinleştirmek için Python için OpenTelemetry Distro azure izleyicisini aşağıdaki gibi kullanabilirsiniz:
...
configure_azure_monitor(
enable_live_metrics=True
)
...
Azure'a daha güvenli bir bağlantı için Microsoft Entra kimlik doğrulamasını etkinleştirmek isteyebilirsiniz ve bu da yetkisiz telemetrinin aboneliğinize alınmasını önler.
Daha fazla bilgi için desteklenen her dil için bağlantılı ayrılmış Microsoft Entra kimlik doğrulama sayfamıza bakın.
GraalVM Yerel uygulamalarında Microsoft Entra Id kimlik doğrulaması kullanılamaz.
Çevrimdışı Depolama ve Otomatik Yeniden Denemeler
Azure Monitor OpenTelemetry tabanlı teklifler, bir uygulama Application Insights bağlantısı kesildiğinde telemetriyi önbelleğe alır ve göndermeyi 48 saate kadar yeniden dener. Veri işleme önerileri için bkz. Özel verileri dışarı aktarma ve silme. Yüksek yüke sahip uygulamalar bazen telemetri verilerini iki nedenden dolayı bırakır: izin verilen süreyi aşma veya dosya boyutu üst sınırını aşma. Gerektiğinde, ürün son olaylara eski olaylara göre öncelik verir.
Distro paketi, çevrimdışı depolama için varsayılan olarak aşağıdaki konumlardan birini kullanan AzureMonitorExporter'ı içerir (öncelik sırasına göre listelenir):
- Windows
- %LOCALAPPDATA%\Microsoft\AzureMonitor
- %TEMP%\Microsoft\AzureMonitor
- Windows Olmayan
- %TMPDIR%/Microsoft/AzureMonitor
- /var/tmp/Microsoft/AzureMonitor
- /tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız AzureMonitorOptions.StorageDirectory
gerekir.
// Create a new ASP.NET Core web application builder.
var builder = WebApplication.CreateBuilder(args);
// Add the OpenTelemetry telemetry service to the application.
// This service will collect and send telemetry data to Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
{
// Set the Azure Monitor storage directory to "C:\\SomeDirectory".
// This is the directory where the OpenTelemetry SDK will store any telemetry data that cannot be sent to Azure Monitor immediately.
options.StorageDirectory = "C:\\SomeDirectory";
});
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
Bu özelliği devre dışı bırakmak için ayarını yapmalısınız AzureMonitorOptions.DisableOfflineStorage = true
.
Varsayılan olarak, AzureMonitorExporter çevrimdışı depolama için aşağıdaki konumlardan birini kullanır (öncelik sırasına göre listelenir):
- Windows
- %LOCALAPPDATA%\Microsoft\AzureMonitor
- %TEMP%\Microsoft\AzureMonitor
- Windows Olmayan
- %TMPDIR%/Microsoft/AzureMonitor
- /var/tmp/Microsoft/AzureMonitor
- /tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız AzureMonitorExporterOptions.StorageDirectory
gerekir.
// Create a new OpenTelemetry tracer provider and set the storage directory.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAzureMonitorTraceExporter(options =>
{
// Set the Azure Monitor storage directory to "C:\\SomeDirectory".
// This is the directory where the OpenTelemetry SDK will store any trace data that cannot be sent to Azure Monitor immediately.
options.StorageDirectory = "C:\\SomeDirectory";
})
.Build();
// Create a new OpenTelemetry meter provider and set the storage directory.
// It is important to keep the MetricsProvider instance active throughout the process lifetime.
var metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddAzureMonitorMetricExporter(options =>
{
// Set the Azure Monitor storage directory to "C:\\SomeDirectory".
// This is the directory where the OpenTelemetry SDK will store any metric data that cannot be sent to Azure Monitor immediately.
options.StorageDirectory = "C:\\SomeDirectory";
})
.Build();
// Create a new logger factory and add the OpenTelemetry logger provider with the storage directory.
// It is important to keep the LoggerFactory instance active throughout the process lifetime.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(logging =>
{
logging.AddAzureMonitorLogExporter(options =>
{
// Set the Azure Monitor storage directory to "C:\\SomeDirectory".
// This is the directory where the OpenTelemetry SDK will store any log data that cannot be sent to Azure Monitor immediately.
options.StorageDirectory = "C:\\SomeDirectory";
});
});
});
Bu özelliği devre dışı bırakmak için ayarını yapmalısınız AzureMonitorExporterOptions.DisableOfflineStorage = true
.
Aracı Azure İzleyici'ye telemetri gönderemezse, telemetri dosyalarını diskte depolar. Dosyalar, telemetry
klasörüne, java.io.tmpdir
tarafından belirtilen sistem özelliği dizininin altına kaydedilir. Her dosya adı bir zaman damgasıyla başlar ve uzantıyla .trn
biter. Bu çevrimdışı depolama mekanizması, geçici ağ kesintileri veya alma hataları sırasında telemetrinin korunmasına yardımcı olur.
Aracı varsayılan olarak 50 MB'a kadar telemetri verilerini depolar ve depolama sınırının yapılandırılmasına izin verir. Depolanan telemetri gönderme girişimleri düzenli aralıklarla yapılır. 48 saatten eski telemetri dosyaları silinir ve depolama sınırına ulaşıldığında en eski olaylar atılır.
Kullanılabilir yapılandırmaların tam listesi için bkz . Yapılandırma seçenekleri.
Aracı Azure İzleyici'ye telemetri gönderemezse, telemetri dosyalarını diskte depolar. Dosyalar, telemetry
klasörüne, java.io.tmpdir
tarafından belirtilen sistem özelliği dizininin altına kaydedilir. Her dosya adı bir zaman damgasıyla başlar ve uzantıyla .trn
biter. Bu çevrimdışı depolama mekanizması, geçici ağ kesintileri veya alma hataları sırasında telemetrinin korunmasına yardımcı olur.
Varsayılan olarak, ajan 50 MB'a kadar telemetri verilerini depolar. Depolanan telemetri gönderme girişimleri düzenli aralıklarla yapılır. 48 saatten eski telemetri dosyaları silinir ve depolama sınırına ulaşıldığında en eski olaylar atılır.
Varsayılan olarak, AzureMonitorExporter çevrimdışı depolama için aşağıdaki konumlardan birini kullanır.
- Windows
- %TEMP%\Microsoft\AzureMonitor
- Windows Olmayan
- %TMPDIR%/Microsoft/AzureMonitor
- /var/tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız storageDirectory
gerekir.
Örneğin:
// Import the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions class from the @azure/monitor-opentelemetry package.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
// Create a new AzureMonitorOpenTelemetryOptions object and set the azureMonitorExporterOptions property to an object with the following properties:
//
// * connectionString: The connection string for your Azure Monitor Application Insights resource.
// * storageDirectory: The directory where the Azure Monitor OpenTelemetry exporter will store telemetry data when it is offline.
// * disableOfflineStorage: A boolean value that specifies whether to disable offline storage.
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: "<Your Connection String>",
storageDirectory: "C:\\SomeDirectory",
disableOfflineStorage: false
}
};
// Enable Azure Monitor integration using the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions object.
useAzureMonitor(options);
Bu özelliği devre dışı bırakmak için ayarını yapmalısınız disableOfflineStorage = true
.
Varsayılan olarak, Azure Monitor aktarıcıları aşağıdaki yolu kullanır.
<tempfile.gettempdir()>/Microsoft/AzureMonitor/opentelemetry-python-<your-instrumentation-key>
Varsayılan dizini geçersiz kılmak için istediğiniz dizine ayarlamanız storage_directory
gerekir.
Örneğin:
...
# Configure OpenTelemetry to use Azure Monitor with the specified connection string and storage directory.
# Replace `your-connection-string` with the connection string to your Azure Monitor Application Insights resource.
# Replace `C:\\SomeDirectory` with the directory where you want to store the telemetry data before it is sent to Azure Monitor.
configure_azure_monitor(
connection_string="your-connection-string",
storage_directory="C:\\SomeDirectory",
)
...
Bu özelliği devre dışı bırakmak için disable_offline_storage
'i True
olarak ayarlamanız gerekir. Varsayılan olarak ayarlanır False
.
Örneğin:
...
# Configure OpenTelemetry to use Azure Monitor with the specified connection string and disable offline storage.
# Replace `your-connection-string` with the connection string to your Azure Monitor Application Insights resource.
configure_azure_monitor(
connection_string="your-connection-string",
disable_offline_storage=True,
)
...
OTLP İhracatçısını Etkinleştirme
Telemetrinizi iki konuma göndermek için Azure İzleyici İhracatı ile birlikte OpenTelemetry Protokolü (OTLP) Vericisi'ni aynı anda etkinleştirmek isteyebilirsiniz.
Not veya Dikkat
OTLP İhracatçısı yalnızca kolaylık sağlamak için gösterilir. OTLP Exporter'ını veya onun ardındaki herhangi bir bileşeni ya da üçüncü taraf deneyimlerini resmi olarak desteklemiyoruz.
Projenize OpenTelemetry.Exporter.OpenTelemetryProtocol paketini yükleyin.
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Aşağıdaki kod parçacığını ekleyin. Bu örnekte, OTLP alıcısı çalışan bir OpenTelemetry Toplayıcınız olduğu varsayılır. Ayrıntılar için GitHub örneğine bakın.
// Create a new ASP.NET Core web application builder.
var builder = WebApplication.CreateBuilder(args);
// Add the OpenTelemetry telemetry service to the application.
// This service will collect and send telemetry data to Azure Monitor.
builder.Services.AddOpenTelemetry().UseAzureMonitor();
// Add the OpenTelemetry OTLP exporter to the application.
// This exporter will send telemetry data to an OTLP receiver, such as Prometheus
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddOtlpExporter());
builder.Services.AddOpenTelemetry().WithMetrics(builder => builder.AddOtlpExporter());
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
Projenize OpenTelemetry.Exporter.OpenTelemetryProtocol paketini yükleyin.
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Aşağıdaki kod parçacığını ekleyin. Bu örnekte, OTLP alıcısı çalışan bir OpenTelemetry Toplayıcınız olduğu varsayılır. Ayrıntılar için GitHub örneğine bakın.
// Create a new OpenTelemetry tracer provider and add the Azure Monitor trace exporter and the OTLP trace exporter.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAzureMonitorTraceExporter()
.AddOtlpExporter()
.Build();
// Create a new OpenTelemetry meter provider and add the Azure Monitor metric exporter and the OTLP metric exporter.
// It is important to keep the MetricsProvider instance active throughout the process lifetime.
var metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddAzureMonitorMetricExporter()
.AddOtlpExporter()
.Build();
Application Insights Java Aracısı OTLP'yi desteklemez.
Desteklenen yapılandırmalar hakkında daha fazla bilgi için Java ek belgelerine bakın.
Telemetri verilerinizi iki konuma göndermek için OpenTelemetry Protokolü (OTLP) İhracatçısını Azure İzleyici İhracatçısı ile birlikte etkinleştiremezsiniz.
Projenize OpenTelemetry Collector trace Exporter ve diğer OpenTelemetry paketlerini yükleyin.
npm install @opentelemetry/api
npm install @opentelemetry/exporter-trace-otlp-http
npm install @opentelemetry/sdk-trace-base
npm install @opentelemetry/sdk-trace-node
Aşağıdaki kod parçacığını ekleyin. Bu örnekte, OTLP alıcısı çalışan bir OpenTelemetry Toplayıcınız olduğu varsayılır. Ayrıntılar için GitHub örneğine bakın.
// Import the useAzureMonitor function, the AzureMonitorOpenTelemetryOptions class, the trace module, the ProxyTracerProvider class, the BatchSpanProcessor class, the NodeTracerProvider class, and the OTLPTraceExporter class from the @azure/monitor-opentelemetry, @opentelemetry/api, @opentelemetry/sdk-trace-base, @opentelemetry/sdk-trace-node, and @opentelemetry/exporter-trace-otlp-http packages, respectively.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
// Create a new OTLPTraceExporter object.
const otlpExporter = new OTLPTraceExporter();
// Enable Azure Monitor integration.
const options: AzureMonitorOpenTelemetryOptions = {
// Add the SpanEnrichingProcessor
spanProcessors: [new BatchSpanProcessor(otlpExporter)]
}
useAzureMonitor(options);
opentelemetry-exporter-otlp paketini yükleyin.
Aşağıdaki kod parçacığını ekleyin. Bu örnekte, OTLP alıcısı çalışan bir OpenTelemetry Toplayıcınız olduğu varsayılır. Ayrıntılar için bu README bölümüne bakın.
# Import the `configure_azure_monitor()`, `trace`, `OTLPSpanExporter`, and `BatchSpanProcessor` classes from the appropriate packages.
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor
# Configure OpenTelemetry to use Azure Monitor with the specified connection string.
# Replace `<your-connection-string>` with the connection string to your Azure Monitor Application Insights resource.
configure_azure_monitor(
connection_string="<your-connection-string>",
)
# Get the tracer for the current module.
tracer = trace.get_tracer(__name__)
# Create an OTLP span exporter that sends spans to the specified endpoint.
# Replace `http://localhost:4317` with the endpoint of your OTLP collector.
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317")
# Create a batch span processor that uses the OTLP span exporter.
span_processor = BatchSpanProcessor(otlp_exporter)
# Add the batch span processor to the tracer provider.
trace.get_tracer_provider().add_span_processor(span_processor)
# Start a new span with the name "test".
with tracer.start_as_current_span("test"):
print("Hello world!")
OpenTelemetry yapılandırmaları
Aşağıdaki OpenTelemetry yapılandırmalarına, Azure Monitor OpenTelemetry Dağıtımı kullanılırken ortam değişkenleri aracılığıyla erişilebilir.
Ortam değişkeni |
Açıklama |
APPLICATIONINSIGHTS_CONNECTION_STRING |
Bunu Application Insights kaynağınız için bağlantı dizesi olarak ayarlayın. |
APPLICATIONINSIGHTS_STATSBEAT_DISABLED |
Dahili ölçüm toplamayı devre dışı bırakmak için true olarak ayarlayın. |
OTEL_RESOURCE_ATTRIBUTES |
Kaynak öznitelikleri olarak kullanılacak anahtar-değer çiftleri. Kaynak öznitelikleri hakkında daha fazla bilgi için bkz . Kaynak SDK belirtimi. |
OTEL_SERVICE_NAME |
Kaynak özniteliğinin service.name değerini ayarlar. Eğer service.name OTEL_RESOURCE_ATTRIBUTES içinde sağlanmışsa, o zaman OTEL_SERVICE_NAME öncelik kazanır. |
Ortam değişkeni |
Açıklama |
APPLICATIONINSIGHTS_CONNECTION_STRING |
Bunu Application Insights kaynağınız için bağlantı dizesi olarak ayarlayın. |
APPLICATIONINSIGHTS_STATSBEAT_DISABLED |
Dahili ölçüm toplamayı devre dışı bırakmak için true olarak ayarlayın. |
OTEL_RESOURCE_ATTRIBUTES |
Kaynak öznitelikleri olarak kullanılacak anahtar-değer çiftleri. Kaynak öznitelikleri hakkında daha fazla bilgi için bkz . Kaynak SDK belirtimi. |
OTEL_SERVICE_NAME |
Kaynak özniteliğinin service.name değerini ayarlar. Eğer service.name OTEL_RESOURCE_ATTRIBUTES içinde sağlanmışsa, o zaman OTEL_SERVICE_NAME öncelik kazanır. |
Java hakkında daha fazla bilgi için Java ek belgelerine bakın.
Ortam değişkeni |
Açıklama |
APPLICATIONINSIGHTS_CONNECTION_STRING |
Bunu Application Insights kaynağınız için bağlantı dizesi olarak ayarlayın. |
Spring Boot yerel uygulamaları için OpenTelemetry Java SDK yapılandırmaları kullanılabilir.
Quarkus yerel uygulamaları için Quarkus OpenTelemetry belgelerini gözden geçirin.
OpenTelemetry SDK yapılandırması hakkında daha fazla bilgi için OpenTelemetry belgelerine bakın.
URL Sorgu Dizelerini Düzenle
URL sorgu dizelerini gizlemek için sorgu dizesi toplamasını kapatın. Sas belirteci kullanarak Azure depolamayı çağırırsanız bu ayarı öneririz.
Azure.Monitor.OpenTelemetry.AspNetCore dağıtım paketini kullanırken hem ASP.NET Core hem de HttpClient Enstrümentasyon kitaplıkları dahildir.
Dağıtım paketimiz Sorgu Dizesi Redaction'ını varsayılan olarak devre dışı bırakır.
Bu davranışı değiştirmek için ortam değişkenini true
veya false
olarak ayarlamanız gerekir.
- ASP.NET Core Enstrümantasyon:
OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_DISABLE_URL_QUERY_REDACTION
Sorgu Dizesi Düzenleme varsayılan olarak devre dışı bırakılmıştır. Etkinleştirmek için bu ortam değişkenini olarak false
ayarlayın.
- HTTP İstemci Enstrümantasyonu:
OTEL_DOTNET_EXPERIMENTAL_HTTPCLIENT_DISABLE_URL_QUERY_REDACTION
Sorgu Dizesi Sansürleme varsayılan olarak devre dışıdır. Etkinleştirmek için bu ortam değişkenini olarak false
ayarlayın.
Azure.Monitor.OpenTelemetry.Exporter kullanırken, OpenTelemetry yapılandırmanıza ASP.NET Core veya HttpClient Instrumentation kitaplıklarını el ile eklemeniz gerekir.
Bu Araçlar kitaplıklarında QueryString Redaction varsayılan olarak etkinleştirilmiştir.
Bu davranışı değiştirmek için ortam değişkenini true
veya false
olarak ayarlamanız gerekir.
- ASP.NET Core Enstrümantasyon:
OTEL_DOTNET_EXPERIMENTAL_ASPNETCORE_DISABLE_URL_QUERY_REDACTION
Sorgu Dizesi Kırpılması varsayılan olarak etkindir. Devre dışı bırakmak için bu ortam değişkenini olarak true
ayarlayın.
- Http İstemci İzleme:
OTEL_DOTNET_EXPERIMENTAL_HTTPCLIENT_DISABLE_URL_QUERY_REDACTION
Sorgu Dizesi Düzenlemesi varsayılan olarak etkindir. Devre dışı bırakmak için bu ortam değişkenini olarak true
ayarlayın.
Yapılandırma dosyasına aşağıdakileri applicationinsights.json
ekleyin:
{
"preview": {
"processors": [
{
"type": "attribute",
"actions": [
{
"key": "url.query",
"pattern": "^.*$",
"replace": "REDACTED",
"action": "mask"
}
]
},
{
"type": "attribute",
"actions": [
{
"key": "url.full",
"pattern": "[?].*$",
"replace": "?REDACTED",
"action": "mask"
}
]
}
]
}
}
Yeniden düzenlemeyi desteklemek için OpenTelemetry topluluğunda etkin bir şekilde çalışıyoruz.
Azure İzleyici OpenTelemetry dağıtım paketini kullanırken, dağıtım yapılandırmasına bir span işlemcisi oluşturup uygulayarak sorgu dizeleri yeniden uygulanabilir.
import { useAzureMonitor, AzureMonitorOpenTelemetryOptions } from "@azure/monitor-opentelemetry";
import { Context } from "@opentelemetry/api";
import { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
import { SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_TARGET, SEMATTRS_HTTP_URL } from "@opentelemetry/semantic-conventions";
class RedactQueryStringProcessor implements SpanProcessor {
forceFlush(): Promise<void> {
return Promise.resolve();
}
onStart(span: Span, parentContext: Context): void {
return;
}
shutdown(): Promise<void> {
return Promise.resolve();
}
onEnd(span: ReadableSpan) {
const httpRouteIndex: number = String(span.attributes[SEMATTRS_HTTP_ROUTE]).indexOf('?');
const httpUrlIndex: number = String(span.attributes[SEMATTRS_HTTP_URL]).indexOf('?');
const httpTargetIndex: number = String(span.attributes[SEMATTRS_HTTP_TARGET]).indexOf('?');
if (httpRouteIndex !== -1) {
span.attributes[SEMATTRS_HTTP_ROUTE] = String(span.attributes[SEMATTRS_HTTP_ROUTE]).substring(0, httpRouteIndex);
}
if (httpUrlIndex !== -1) {
span.attributes[SEMATTRS_HTTP_URL] = String(span.attributes[SEMATTRS_HTTP_URL]).substring(0, httpUrlIndex);
}
if (httpTargetIndex !== -1) {
span.attributes[SEMATTRS_HTTP_TARGET] = String(span.attributes[SEMATTRS_HTTP_TARGET]).substring(0, httpTargetIndex);
}
}
}
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: <YOUR_CONNECTION_STRING>,
},
spanProcessors: [new RedactQueryStringProcessor()]
};
useAzureMonitor(options);
Yeniden düzenlemeyi desteklemek için OpenTelemetry topluluğunda etkin bir şekilde çalışıyoruz.
Metrik dışa aktarma aralığı
Ortam değişkenini kullanarak OTEL_METRIC_EXPORT_INTERVAL
ölçüm dışarı aktarma aralığını yapılandırabilirsiniz.
OTEL_METRIC_EXPORT_INTERVAL=60000
Varsayılan değer milisaniyedir 60000
(60 saniye). Bu ayar, OpenTelemetry SDK'sının ölçümleri dışarı aktarma sıklıklarını denetler.
İpucu
Azure İzleyici Ölçümleri ve Azure İzleyici Çalışma Alanı özel ölçümleri sabit 60 saniyelik aralıklarla alır. Daha sık gönderilen ölçümler her 60 saniyede bir arabelleğe alınıp işlenir. Log Analytics, ölçümleri gönderildikleri aralıkta kaydeder ve bu da maliyetleri daha kısa aralıklarla artırabilir ve daha uzun aralıklarla görünürlüğü geciktirebilir.
Referans için, aşağıdaki OpenTelemetry belirtimlerine bakın: