Bu makale, Azure İzleyici OpenTelemetry dağıtımının yapılandırma ayarlarını kapsar.
Connection string
Application Analizler'daki bir bağlantı dizesi, telemetri verilerini göndermek için hedef konumu tanımlar ve izleme ve analiz için uygun kaynağa ulaşmasını sağlar.
bağlantı dizesi yapılandırmak için aşağıdaki üç yoldan birini kullanın:
Sınıfınızda uygulama başlangıcınıza program.cs ekleyinUseAzureMonitor().
// 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 => {
options.ConnectionString = "<Your Connection String>";
});
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
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:
Uygulama başlangıcında her OpenTelemetry sinyaline Azure İzleyici Verme Aracı'nı 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>";
});
// 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>";
});
// 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(options =>
{
options.AddAzureMonitorLogExporter(options =>
{
options.ConnectionString = "<Your Connection String>";
});
});
});
// 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:
# 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ı ve özniteliklerini kullanırservice.namespace, ancak ayarlı değilse service.namespace değerine geri dönerservice.name.service.name 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 OpenTelemetry tracer provider to add the resource attributes to all traces.
builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) =>
builder.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ı ve özniteliklerini kullanırservice.namespace, ancak ayarlı değilse service.namespace değerine geri dönerservice.name.service.name 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();
// 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();
// 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(options =>
{
// Set ResourceBuilder on the Logging config.
options.SetResourceBuilder(resourceBuilder);
options.AddAzureMonitorLogExporter();
});
});
Kaynak öznitelikleri aracılığıyla Bulut Rolü Adını ve Bulut Rolü Örneğini ayarlayın. Bulut Rolü Adı ve özniteliklerini kullanırservice.namespace, ancak ayarlı değilse service.namespace değerine geri dönerservice.name.service.name 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ı ve özniteliklerini kullanırservice.namespace, ancak ayarlı değilse service.namespace değerine geri dönerservice.name.service.name 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_SERVICE_NAME ortam değişkenlerini kullanarak OTEL_RESOURCE_ATTRIBUTES Kaynak özniteliklerini ayarlayın. OTEL_RESOURCE_ATTRIBUTES virgülle ayrılmış anahtar-değer çiftleri serisi alır. Örneğin, Bulut Rolü Adı'nı my-namespace.my-helloworld-service olarak ayarlamak ve Bulut Rolü Örneği'ni olarak ayarlamak için my-instanceşu şekilde ayarlayabilirsiniz OTEL_RESOURCE_ATTRIBUTESOTEL_SERVICE_NAME :
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 ayarlamak ve Bulut Rolü Örneği'ni olarak ayarlamak için my-instanceşu şekilde ayarlayabilirsiniz OTEL_RESOURCE_ATTRIBUTESOTEL_SERVICE_NAME :
Veri alımı hacminizi azaltmak ve maliyetlerinizi azaltmak için örneklemeyi etkinleştirmek isteyebilirsiniz. Azure İzleyici, olayları bir örnekleme oranıyla dolduran ve Application Analizler'ın 'a ItemCountdönüştürdüğü özel bir sabit oranlı örnekleyici sağlar. Sabit oranlı örnekleyici doğru deneyimler ve olay sayıları sağlar. Örnekleyici, hizmetler genelinde izlemelerinizi korumak için tasarlanmıştır ve eski Application Analizler SDK'larıyla birlikte çalışabilir. Daha fazla bilgi için bkz . Örnekleme hakkında daha fazla bilgi edinin.
Ö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(o =>
{
// Set the sampling ratio to 10%. This means that 10% of all traces will be sampled and sent to Azure Monitor.
o.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;
});
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, configure_azure_monitor() Application Analizler SDK'larıyla uyumluluk ve telemetrinizi örneklemek için Application Analizler Sampler'ı 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 örneklemesi kullanırken örnekleme hızının ne olarak ayarlanacağından emin değilsiniz, %5'te (örn. 0,05 örnekleme oranı) başlayın ve hataların ve performans dikey pencerelerinde 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.
Microsoft Entra Id (eski adıyla Azure AD) kimlik doğrulamasını etkinleştirme
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.
// 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 credential to the DefaultAzureCredential.
// This credential will use the Azure identity of the current user or
// the service principal that the application is running as to authenticate
// to Azure Monitor.
options.Credential = new DefaultAzureCredential();
});
// Build the ASP.NET Core web application.
var app = builder.Build();
// Start the ASP.NET Core web application.
app.Run();
Azure Identity tarafından sağlanan kimlik bilgisi sınıflarını destekliyoruz.
Yerel geliştirme için önerilir DefaultAzureCredential .
Sistem tarafından atanan ve kullanıcı tarafından atanan yönetilen kimlikler için önerilir ManagedIdentityCredential .
Sistem tarafından atanan için parametresiz varsayılan oluşturucuyu kullanın.
Kullanıcı tarafından atanan için oluşturucuya istemci kimliğini sağlayın.
Hizmet sorumluları için öneririz ClientSecretCredential .
Oluşturucuya kiracı kimliğini, istemci kimliğini ve istemci gizli dizisini sağlayın.
// Create a DefaultAzureCredential.
var credential = new DefaultAzureCredential();
// Create a new OpenTelemetry tracer provider and set the credential.
// It is important to keep the TracerProvider instance active throughout the process lifetime.
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddAzureMonitorTraceExporter(options =>
{
options.Credential = credential;
});
// Create a new OpenTelemetry meter provider and set the credential.
// It is important to keep the MetricsProvider instance active throughout the process lifetime.
var metricsProvider = Sdk.CreateMeterProviderBuilder()
.AddAzureMonitorMetricExporter(options =>
{
options.Credential = credential;
});
// Create a new logger factory and add the OpenTelemetry logger provider with the credential.
// It is important to keep the LoggerFactory instance active throughout the process lifetime.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddAzureMonitorLogExporter(options =>
{
options.Credential = credential;
});
});
});
Java hakkında daha fazla bilgi için Java ek belgelerine bakın.
Azure Identity tarafından sağlanan kimlik bilgisi sınıflarını destekliyoruz.
// Import the useAzureMonitor function, the AzureMonitorOpenTelemetryOptions class, and the ManagedIdentityCredential class from the @azure/monitor-opentelemetry and @azure/identity packages, respectively.
const { useAzureMonitor, AzureMonitorOpenTelemetryOptions } = require("@azure/monitor-opentelemetry");
const { ManagedIdentityCredential } = require("@azure/identity");
// Create a new ManagedIdentityCredential object.
const credential = new ManagedIdentityCredential();
// Create a new AzureMonitorOpenTelemetryOptions object and set the credential property to the credential object.
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
credential: credential
}
};
// Enable Azure Monitor integration using the useAzureMonitor function and the AzureMonitorOpenTelemetryOptions object.
useAzureMonitor(options);
# Import the `ManagedIdentityCredential` class from the `azure.identity` package.
from azure.identity import ManagedIdentityCredential
# 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 a managed identity credential.
# This will allow OpenTelemetry to authenticate to Azure Monitor without requiring you to provide a connection string.
configure_azure_monitor(
credential=ManagedIdentityCredential(),
)
Çevrimdışı Depolama ve Otomatik Yeniden Denemeler
Güvenilirliği ve dayanıklılığı artırmak için Azure İzleyici OpenTelemetry tabanlı teklifler, uygulama Application Analizler bağlantısını kaybettiğinde varsayılan olarak çevrimdışı/yerel depolamaya yazar. Uygulama telemetrisini diske kaydeder ve düzenli aralıklarla 48 saate kadar yeniden göndermeye çalışır. Yüksek yüke sahip uygulamalarda telemetri bazen iki nedenden dolayı bırakılır. İlk olarak, izin verilen süre aşıldığında ve ikincisi, en büyük dosya boyutu aşıldığında veya SDK'nın dosyayı temizleme fırsatı olmadığında. Seçim yapmamız gerekirse ürün, eski olaylara göre daha yeni olaylar kaydeder. Daha Fazla Bilgi
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 Dışı
%TMPDIR%/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
/tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız AzureMonitorOptions.StorageDirectorygerekir.
// 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 Dışı
%TMPDIR%/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
/tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız AzureMonitorExporterOptions.StorageDirectorygerekir.
// 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";
});
// 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";
});
// 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(options =>
{
options.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.
Çevrimdışı Depolama yapılandırma ve Otomatik Yeniden Denemeler Java'da kullanılamaz.
Varsayılan olarak, AzureMonitorExporter çevrimdışı depolama için aşağıdaki konumlardan birini kullanır.
Windows
%TEMP%\Microsoft\AzureMonitor
Windows Dışı
%TMPDIR%/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
Varsayılan dizini geçersiz kılmak için değerini ayarlamanız storageDirectorygerekir.
Ö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 İzleyici verenler aşağıdaki yolu kullanır:
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 olarak ayarlamanız disable_offline_storageTruegerekir. varsayılan değeridir 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 Vereni ile birlikte OpenTelemetry Protokolü (OTLP) Verme Aracı'nı etkinleştirmek isteyebilirsiniz.
Not
OTLP İhracatçısı yalnızca kolaylık sağlamak için gösterilir. OTLP İhracatçısını veya herhangi bir bileşeni ya da üçüncü taraf deneyimlerini resmi olarak desteklemiyoruz.
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();
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();
// 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();
Java hakkında daha fazla bilgi için Java ek belgelerine bakın.
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);
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 BENİOKU 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 İzleyici OpenTelemetry Dağıtımları kullanılırken ortam değişkenleri aracılığıyla erişilebilir.
Bu bölüm, sık sorulan soruların yanıtlarını sağlar.
OpenTelemetry nedir?
Gözlemlenebilirlik için yeni bir açık kaynak standardıdır. OpenTelemetry'de daha fazla bilgi edinin.
Microsoft Azure İzleyici neden OpenTelemetry'ye yatırım yapıyor?
Microsoft, OpenTelemetry'e en büyük katkıda bulunanlardandır.
OpenTelemetry'nin temel değer teklifleri, satıcıdan bağımsız olması ve diller arasında tutarlı API'ler/SDK'lar sağlamasıdır.
Zaman içinde OpenTelemetry'nin Azure İzleyici müşterilerinin desteklenen dillerimizin ötesindeki dillerde yazılmış uygulamaları gözlemleye olanak tanıyacağına inanıyoruz. Ayrıca zengin bir izleme kitaplıkları kümesi aracılığıyla toplayabileceğiniz veri türlerini de genişletir. Ayrıca OpenTelemetry SDK'ları, öncülleri olan Uygulama Analizler SDK'larından daha yüksek ölçekte performans gösterme eğilimindedir.
Bunu, Azure'da birinci sınıf bir deneyim için tüm OpenTelemetry bileşenlerini bir araya getiren ince bir sarmalayıcı olarak düşünebilirsiniz. Bu sarmalayıcı OpenTelemetry'de dağıtım olarak da adlandırılır.
Neden "Azure İzleyici OpenTelemetry Distro" kullanmalıyım?
Azure İzleyici OpenTelemetry Dağıtımı'nı topluluktan yerel OpenTelemetry üzerinden kullanmanın çeşitli avantajları vardır:
Etkinleştirme çabasını azaltır
Microsoft tarafından desteklenir
Aşağıdakiler gibi Azure'a özgü özellikleri getirir:
Klasik Uygulama Analizler SDK'ları ile uyumlu örnekleme
OpenTelemetry ruhuyla dağıtımı açık ve genişletilebilir olacak şekilde tasarladık. Örneğin şunları ekleyebilirsiniz:
OpenTelemetry Protokolü (OTLP) verme ve aynı anda ikinci bir hedefe gönderme
Dağıtıma dahil olmayan diğer izleme kitaplıkları
Distro bir OpenTelemetry dağıtımı sağladığından, Distro OpenTelemetry tarafından desteklenen her şeyi destekler. Örneğin, OpenTelemetry destekliyorsa daha fazla telemetri işlemcisi, dışarı aktarıcı veya izleme kitaplığı ekleyebilirsiniz.
Not
Distro, örnekleyiciyi Uygulama Analizler için özel, sabit oranlı bir örnekleyiciye ayarlar. Bunu farklı bir örnekleyiciyle değiştirebilirsiniz, ancak bunu yapmak Distro'nun dahil edilen özelliklerinden bazılarını devre dışı bırakabilir.
Desteklenen örnekleyici hakkında daha fazla bilgi için Azure İzleyici OpenTelemetry'yi Yapılandırma'nın Örneklemeyi Etkinleştirme bölümüne bakın.
Desteklenen tek başına OpenTelemetry vereni olmayan diller için Azure İzleyici OpenTelemetry Distro, OpenTelemetry'yi Azure İzleyici ile kullanmanın şu anda desteklenen tek yoludur. Desteklenen tek başına OpenTelemetry veren diller için, telemetri senaryonuza bağlı olarak Azure İzleyici OpenTelemetry Distro veya uygun tek başına OpenTelemetry verme işlemini kullanma seçeneğiniz vardır. Daha fazla bilgi için bkz. Azure İzleyici OpenTelemetry dışarı aktarmayı ne zaman kullanmalıyım?.
Azure İzleyici OpenTelemetry Dağıtımı'nı nasıl test ederim?
.NET, Java, JavaScript (Node.js) ve Python için etkinleştirme belgelerimize göz atın.
OpenTelemetry mi yoksa Uygulama Analizler SDK'sını mı kullanmalıyım?
Yalnızca Uygulama Analizler SDK'sında resmi destekle kullanılabilen bir özellik gerektirmediğiniz sürece OpenTelemetry Distro'sunu kullanmanızı öneririz.
OpenTelemetry'yi benimsemek artık daha sonraki bir tarihte geçiş yapılmasını engelliyor.
Azure İzleyici OpenTelemetry dışarı aktarmasını ne zaman kullanmalıyım?
ASP.NET Core, Java, Node.js ve Python için Azure İzleyici OpenTelemetry Distro kullanmanızı öneririz. Başlamak için bir kod satırıdır.
Klasik ASP.NET, konsol uygulamaları vb. gibi diğer tüm .NET senaryoları için .NET Azure İzleyici OpenTelemetry dışarı aktarmayı kullanmanızı öneririz: Azure.Monitor.OpenTelemetry.Exporter.
OpenTelemetry web tarayıcıları için kullanılabilir mi?
Evet, ancak bunu önermiyoruz ve Azure desteklemiyor. OpenTelemetry JavaScript, Node.js için yoğun olarak iyileştirilmiştir. Bunun yerine Application Analizler JavaScript SDK'sını kullanmanızı öneririz.
OpenTelemetry SDK'sının web tarayıcılarında ne zaman kullanılabilir olmasını bekleyebiliriz?
OpenTelemetry web SDK'sının belirlenmiş bir kullanılabilirlik zaman çizelgesi yoktur. Application Analizler JavaScript SDK'sına uygun bir alternatif olan tarayıcı SDK'sından birkaç yıl uzaktayız.
OpenTelemetry'yi bugün bir web tarayıcısında test edebilir miyim?
OpenTelemetry web korumalı alanı, OpenTelemetry'nin tarayıcıda çalışmasını sağlamak için tasarlanmış bir çataldır. Uygulama Analizler telemetri göndermek henüz mümkün değildir. SDK genel istemci olaylarını tanımlamaz.
Application Analizler'ı AppDynamics, DataDog ve NewRelic gibi rakip aracılarla birlikte çalıştırmak destekleniyor mu?
Hayır Bu uygulama test veya desteklemeyi planladığımız bir uygulama değildir, ancak Dağıtımlarımız Azure İzleyici ile aynı anda bir OTLP uç noktasına dışarı aktarmanıza olanak sağlar.
Üretim ortamlarında önizleme özelliklerini kullanabilir miyim?
Microsoft henüz uygulama izleme için aracı tabanlı bir yaklaşımı resmi olarak desteklemese de bazı müşteriler openTelemetry Collector'ı aracı alternatifi olarak kullanır. Bu arada açık kaynak topluluğu, bazı müşterilerin Azure İzleyici Uygulaması Analizler'ne veri göndermek için kullandığı bir OpenTelemetry Collector Azure İzleyici Exporter'a katkıda bulundu. Bu, Microsoft tarafından desteklenmez.
OpenCensus ile OpenTelemetry arasındaki fark nedir?
OpenCensus, OpenTelemetry'nin öncüsüdür. Microsoft, OpenTracing ve OpenCensus'un bir araya getirerek dünya için tek bir gözlemlenebilirlik standardı olan OpenTelemetry'yi oluşturmasına yardımcı oldu. Azure İzleyici için üretim tarafından önerilen geçerli Python SDK'sı OpenCensus'a dayanır. Microsoft, OpenTelemetry temelinde Azure İzleyici oluşturmayı taahhüt etmiştir.