استخدم إحدى الطرق الثلاث التالية لتكوين سلسلة الاتصال:
أضف UseAzureMonitor() إلى بدء تشغيل التطبيق الخاص بك، في فصلك program.cs الدراسي.
// 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();
إذا قمت بتعيين سلسلة الاتصال في أكثر من مكان واحد، فإننا نلتزم بالأسبقية التالية:
رمز
متغير بيئة
ملف التكوين
استخدم إحدى الطريقتين التاليتين لتكوين سلسلة الاتصال:
أضف مصدر Azure Monitor إلى كل إشارة OpenTelemetry في بدء تشغيل التطبيق.
// 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);
استخدم إحدى الطريقتين التاليتين لتكوين سلسلة الاتصال:
# 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>",
)
تعيين اسم دور مجموعة النظراء ومثيل دور مجموعة النظراء
بالنسبة للغات المدعومة، يكتشف Azure Monitor OpenTelemetry Distro تلقائيا سياق المورد ويوفر القيم الافتراضية لاسم دور السحابة وخصائص مثيل دور السحابة للمكون الخاص بك. ومع ذلك، قد ترغب في تجاوز القيم الافتراضية إلى شيء منطقي لفريقك. تظهر قيمة اسم دور السحابة على خريطة التطبيق كاسم أسفل عقدة.
قم بتعيين اسم دور السحابة ومثيل دور السحابة عبر سمات المورد . يستخدم اسم دور مجموعة النظراء السمات service.namespace وservice.name، على الرغم من أنه يقع مرة أخرى إلى service.name إذا لم يتم تعيين service.namespace. يستخدم مثيل دور مجموعة النظراء service.instance.id قيمة السمة. للحصول على معلومات حول السمات القياسية للموارد، راجع اصطلاحات القياس الدلالي OpenTelemetry.
// 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();
قم بتعيين اسم دور السحابة ومثيل دور السحابة عبر سمات المورد . يستخدم اسم دور مجموعة النظراء السمات service.namespace وservice.name، على الرغم من أنه يقع مرة أخرى إلى service.name إذا لم يتم تعيين service.namespace. يستخدم مثيل دور مجموعة النظراء service.instance.id قيمة السمة. للحصول على معلومات حول السمات القياسية للموارد، راجع اصطلاحات القياس الدلالي OpenTelemetry.
// 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();
});
});
قم بتعيين اسم دور السحابة ومثيل دور السحابة عبر سمات المورد . يستخدم اسم دور مجموعة النظراء السمات service.namespace وservice.name، على الرغم من أنه يقع مرة أخرى إلى service.name إذا لم يتم تعيين service.namespace. يستخدم مثيل دور مجموعة النظراء service.instance.id قيمة السمة. للحصول على معلومات حول السمات القياسية للموارد، راجع اصطلاحات القياس الدلالي OpenTelemetry.
// 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);
قم بتعيين اسم دور السحابة ومثيل دور السحابة عبر سمات المورد . يستخدم اسم دور مجموعة النظراء السمات service.namespace وservice.name، على الرغم من أنه يقع مرة أخرى إلى service.name إذا لم يتم تعيين service.namespace. يستخدم مثيل دور مجموعة النظراء service.instance.id قيمة السمة. للحصول على معلومات حول السمات القياسية للموارد، راجع اصطلاحات القياس الدلالي OpenTelemetry.
تعيين سمات الموارد باستخدام OTEL_RESOURCE_ATTRIBUTES و/أو OTEL_SERVICE_NAME متغيرات البيئة. OTEL_RESOURCE_ATTRIBUTES يأخذ سلسلة من أزواج قيم المفاتيح المفصولة بفواصل. على سبيل المثال، لتعيين اسم دور السحابة إلى my-namespace.my-helloworld-service وتعيين مثيل دور السحابة إلى my-instance، يمكنك تعيين OTEL_RESOURCE_ATTRIBUTES وعلى OTEL_SERVICE_NAME هذا النحو:
إذا لم تقم بتعيين سمة service.namespace المورد، يمكنك بدلا من ذلك تعيين اسم دور السحابة مع متغير البيئة OTEL_SERVICE_NAME فقط أو سمة service.name المورد. على سبيل المثال، لتعيين اسم دور السحابة إلى my-helloworld-service وتعيين مثيل دور السحابة إلى my-instance، يمكنك تعيين OTEL_RESOURCE_ATTRIBUTES وعلى OTEL_SERVICE_NAME هذا النحو:
قد ترغب في تمكين أخذ العينات لتقليل حجم استيعاب البيانات، ما يقلل من التكلفة. يوفر Azure Monitor أداة عينة مخصصة ذات معدل ثابت تملأ الأحداث بنسبة أخذ العينات، والتي يحولها Application Insights إلى ItemCount. يضمن أداة أخذ العينات ذات المعدل الثابت تجارب دقيقة وعدد الأحداث. تم تصميم أداة أخذ العينات للحفاظ على آثارك عبر الخدمات، وهي قابلة للتشغيل المتداخل مع Application Insights SDKs القديمة. لمزيد من المعلومات، راجع معرفة المزيد حول أخذ العينات.
يتوقع العينة معدل عينة يتراوح بين 0 و1 ضمنا. معدل 0.1 يعني أن حوالي 10٪ من آثارك يتم إرسالها.
// 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();
يتوقع العينة معدل عينة يتراوح بين 0 و1 ضمنا. معدل 0.1 يعني أن حوالي 10٪ من آثارك يتم إرسالها.
// 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، يتوفر أخذ العينات محدودة المعدل وهو الآن الافتراضي. لمزيد من المعلومات حول أخذ العينات، راجع أخذ عينات Java.
يتوقع العينة معدل عينة يتراوح بين 0 و1 ضمنا. معدل 0.1 يعني أن حوالي 10٪ من آثارك يتم إرسالها.
// 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);
configure_azure_monitor() تستخدم الدالة تلقائيا ApplicationInsightsSampler للتوافق مع Application Insights SDKs ولعينة بيانات تتبع الاستخدام الخاصة بك. OTEL_TRACES_SAMPLER_ARG يمكن استخدام متغير البيئة لتحديد معدل أخذ العينات، مع نطاق صالح من 0 إلى 1، حيث 0 هو 0٪ و1 هو 100٪.
على سبيل المثال، تعني قيمة 0.1 أن 10٪ من آثارك يتم إرسالها.
export OTEL_TRACES_SAMPLER_ARG=0.1
تلميح
عند استخدام أخذ العينات بمعدل ثابت/نسبة مئوية ولست متأكدا مما يجب تعيين معدل أخذ العينات عليه، ابدأ من 5٪ (أي نسبة أخذ العينات 0.05) وضبط المعدل بناء على دقة العمليات الموضحة في شفرات الفشل والأداء. ينتج عن ارتفاع المعدل بشكل عام دقة أعلى. ومع ذلك، فإن أي أخذ عينات سيؤثر على الدقة لذلك نوصي بالتنبيه على مقاييس القياس المفتوح، والتي لا تتأثر بأخذ العينات.
تمكين مصادقة معرف Microsoft Entra (المعروف سابقا ب Azure AD)
قد ترغب في تمكين مصادقة Microsoft Entra لاتصال أكثر أمانا ب Azure، ما يمنع استيعاب بيانات تتبع الاستخدام غير المصرح بها في اشتراكك.
// 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.
نوصي DefaultAzureCredential بالتطوير المحلي.
نوصي بالهويات ManagedIdentityCredential المدارة المعينة من قبل النظام والمخصصة من قبل المستخدم.
بالنسبة إلى النظام المعين، استخدم المنشئ الافتراضي بدون معلمات.
بالنسبة إلى المعين من قبل المستخدم، قم بتوفير معرف العميل إلى الدالة الإنشائية.
// 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;
});
});
});
نحن ندعم فئات بيانات الاعتماد التي توفرها Azure Identity.
// 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(),
)
التخزين غير المتصل وإعادة المحاولة التلقائية
لتحسين الموثوقية والمرونة، تكتب العروض المستندة إلى Azure Monitor OpenTelemetry إلى التخزين غير المتصل/المحلي بشكل افتراضي عندما يفقد أحد التطبيقات اتصاله ب Application Insights. يقوم بحفظ بيانات تتبع الاستخدام للتطبيق على القرص ويحاول إرساله مرة أخرى بشكل دوري لمدة تصل إلى 48 ساعة. في التطبيقات عالية التحميل، يتم إسقاط بيانات تتبع الاستخدام أحيانا لسببين. أولا، عند تجاوز الوقت المسموح به، وثانيا، عند تجاوز الحد الأقصى لحجم الملف أو عندما لا يكون لدى SDK فرصة لمسح الملف. إذا كنا بحاجة إلى الاختيار، فإن المنتج يحفظ الأحداث الأحدث على الأحداث القديمة. معرفة المزيد
تتضمن حزمة Distro AzureMonitorExporter، الذي يستخدم بشكل افتراضي أحد المواقع التالية للتخزين دون اتصال (مدرج بترتيب الأسبقية):
Windows
٪LOCALAPPDATA٪\Microsoft\AzureMonitor
٪TEMP٪\Microsoft\AzureMonitor
غير Windows
٪TMPDIR٪/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
/tmp/Microsoft/AzureMonitor
لتجاوز الدليل الافتراضي، يجب عليك تعيين AzureMonitorOptions.StorageDirectory.
// 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();
لتعطيل هذه الميزة، يجب تعيين AzureMonitorOptions.DisableOfflineStorage = true.
بشكل افتراضي، يستخدم AzureMonitorExporter أحد المواقع التالية للتخزين دون اتصال (مدرج بترتيب الأسبقية):
Windows
٪LOCALAPPDATA٪\Microsoft\AzureMonitor
٪TEMP٪\Microsoft\AzureMonitor
غير Windows
٪TMPDIR٪/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
/tmp/Microsoft/AzureMonitor
لتجاوز الدليل الافتراضي، يجب عليك تعيين AzureMonitorExporterOptions.StorageDirectory.
// 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";
});
});
});
لتعطيل هذه الميزة، يجب تعيين AzureMonitorExporterOptions.DisableOfflineStorage = true.
لا يتوفر تكوين التخزين دون اتصال وإعادة المحاولة التلقائية في Java.
للحصول على قائمة كاملة بالتكوينات المتوفرة، راجع خيارات التكوين.
بشكل افتراضي، يستخدم AzureMonitorExporter أحد المواقع التالية للتخزين دون اتصال.
Windows
٪TEMP٪\Microsoft\AzureMonitor
غير Windows
٪TMPDIR٪/Microsoft/AzureMonitor
/var/tmp/Microsoft/AzureMonitor
لتجاوز الدليل الافتراضي، يجب عليك تعيين storageDirectory.
على سبيل المثال:
// 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);
لتعطيل هذه الميزة، يجب تعيين disableOfflineStorage = true.
بشكل افتراضي، يستخدم مصدرو Azure Monitor المسار التالي:
لتجاوز الدليل الافتراضي، يجب تعيين storage_directory إلى الدليل الذي تريده.
على سبيل المثال:
...
# 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",
)
...
لتعطيل هذه الميزة، يجب تعيين disable_offline_storage إلى True. الإعدادات الافتراضية لـ False.
على سبيل المثال:
...
# 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
قد ترغب في تمكين مصدر بروتوكول القياس المفتوح (OTLP) جنبا إلى جنب مع مصدر Azure Monitor لإرسال بيانات تتبع الاستخدام إلى موقعين.
إشعار
يتم عرض مصدر OTLP للراحة فقط. نحن لا ندعم رسميًا المصدر OTLP أو أي مكونات أو تجارب طرف ثالث في المصب منه.
أضف جزء التعليمة البرمجية المكررة التالي. يفترض هذا المثال أن لديك جامع OpenTelemetry مع جهاز استقبال OTLP قيد التشغيل. للحصول على التفاصيل، راجع المثال على GitHub.
// 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();
أضف جزء التعليمة البرمجية المكررة التالي. يفترض هذا المثال أن لديك جامع OpenTelemetry مع جهاز استقبال OTLP قيد التشغيل. للحصول على التفاصيل، راجع المثال على GitHub.
// 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();
أضف جزء التعليمة البرمجية المكررة التالي. يفترض هذا المثال أن لديك جامع OpenTelemetry مع جهاز استقبال OTLP قيد التشغيل. للحصول على التفاصيل، راجع المثال على GitHub.
// 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 مع جهاز استقبال OTLP قيد التشغيل. للحصول على التفاصيل، راجع README هذا.
# 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
يمكن الوصول إلى تكوينات OpenTelemetry التالية من خلال متغيرات البيئة أثناء استخدام Azure Monitor OpenTelemetry Distros.
لمزيد من المعلومات حول تكوين OpenTelemetry SDK، راجع وثائق OpenTelemetry.
لمزيد من المعلومات حول تكوين OpenTelemetry SDK، راجع وثائق OpenTelemetry واستخدام Distro لمراقبة Azure.
الأسئلة الشائعة
يقدم هذا القسم إجابات للأسئلة الشائعة.
ما هو OpenTelemetry؟
إنه معيار مفتوح المصدر جديد لقابلية الملاحظة. تعرف على المزيد في OpenTelemetry.
لماذا تستثمر Microsoft Azure Monitor في OpenTelemetry؟
Microsoft هي من بين أكبر المساهمين في القياس المفتوح.
تتمثل اقتراحات القيم الرئيسية لـ OpenTelemetry في أنها محايدة من قبل المورد وتوفر واجهات برمجة تطبيقات/SDK ثابتة عبر اللغات.
مع مرور الوقت، نعتقد أن OpenTelemetry سيمكن عملاء Azure Monitor من مراقبة التطبيقات المكتوبة بلغات تتجاوز لغاتنا المدعومة. كما أنه يوسع أنواع البيانات التي يمكنك جمعها من خلال مجموعة غنية من مكتبات الأجهزة. علاوة على ذلك، تميل مجموعات تطوير البرامج الخاصة ب OpenTelemetry إلى أن تكون أكثر أداء على نطاق واسع من أسلافها، وهي Application Insights SDKs.
يمكنك التفكير في الأمر على أنه برنامج تضمين رفيع يجمع معا جميع مكونات OpenTelemetry للحصول على تجربة من الدرجة الأولى على Azure. يسمى هذا التضمين أيضا التوزيع في OpenTelemetry.
لماذا يجب استخدام "Azure Monitor OpenTelemetry Distro"؟
هناك العديد من المزايا لاستخدام Azure Monitor OpenTelemetry Distro على OpenTelemetry الأصلي من المجتمع:
تقليل جهد التمكين
مدعوم من قبل Microsoft
يجلب ميزات خاصة ب Azure مثل:
أخذ العينات المتوافق مع Application Insights SDKs الكلاسيكي
بروح OpenTelemetry، صممنا توزيعة لتكون مفتوحة وقابلة للتوسعة. على سبيل المثال، يمكنك إضافة:
مصدر بروتوكول القياس المفتوح (OTLP) وإرساله إلى وجهة ثانية في وقت واحد
مكتبات الأجهزة الأخرى غير المضمنة في توزيعة الأجهزة
نظرا لأن Distro يوفر توزيع OpenTelemetry، يدعم Distro أي شيء يدعمه OpenTelemetry. على سبيل المثال، يمكنك إضافة المزيد من معالجات بيانات تتبع الاستخدام أو المصدرين أو مكتبات الأجهزة، إذا كان OpenTelemetry يدعمها.
إشعار
يقوم Distro بتعيين العينة إلى عينة مخصصة ذات معدل ثابت ل Application Insights. يمكنك تغيير هذا إلى عينة مختلفة، ولكن القيام بذلك قد يعطل بعض القدرات المضمنة في Distro.
لمزيد من المعلومات حول أداة أخذ العينات المدعومة، راجع قسم تمكين أخذ العينات في تكوين القياس المفتوح ل Azure Monitor.
بالنسبة للغات التي لا تحتوي على مصدر OpenTelemetry مستقل معتمد، فإن Azure Monitor OpenTelemetry Distro هو الطريقة الوحيدة المدعومة حاليا لاستخدام OpenTelemetry مع Azure Monitor. بالنسبة للغات التي لديها مصدر OpenTelemetry مستقل معتمد، لديك خيار استخدام إما Azure Monitor OpenTelemetry Distro أو مصدر OpenTelemetry المستقل المناسب اعتمادا على سيناريو القياس عن بعد. لمزيد من المعلومات، راجع متى يجب استخدام مصدر Azure Monitor OpenTelemetry؟.
كيف يمكنني اختبار Azure Monitor OpenTelemetry Distro؟
يؤدي اعتماد OpenTelemetry الآن إلى منع الاضطرار إلى الترحيل في وقت لاحق.
متى يجب استخدام مصدر Azure Monitor OpenTelemetry؟
بالنسبة إلى ASP.NET Core وJava Node.js وPython، نوصي باستخدام Azure Monitor OpenTelemetry Distro. إنه سطر واحد من التعليمات البرمجية للبدء.
بالنسبة لجميع سيناريوهات .NET الأخرى، بما في ذلك ASP.NET الكلاسيكية وتطبيقات وحدة التحكم وما إلى ذلك، نوصي باستخدام مصدر .NET Azure Monitor OpenTelemetry: Azure.Monitor.OpenTelemetry.Exporter.
بالنسبة لسيناريوهات بيانات تتبع الاستخدام Python الأكثر تعقيدا التي تتطلب تكوينا متقدما، نوصي باستخدام مصدر بيانات تتبع الاستخدام المفتوح ل Python Azure Monitor.
ما هي حالة الإصدار الحالية للميزات داخل Azure Monitor OpenTelemetry Distro؟
يقسم المخطط التالي دعم ميزة OpenTelemetry لكل لغة.
نعم، لكننا لا نوصي به ولا يدعمه Azure. تم تحسين OpenTelemetry JavaScript بشكل كبير Node.js. بدلا من ذلك، نوصي باستخدام Application Insights JavaScript SDK.
متى يمكننا توقع توفر OpenTelemetry SDK للاستخدام في مستعرضات الويب؟
لا يحتوي OpenTelemetry web SDK على مخطط زمني محدد للتوفر. من المحتمل أن نكون على بعد عدة سنوات من متصفح SDK الذي يعد بديلا قابلا للتطبيق Insights JavaScript SDK.
هل يمكنني اختبار OpenTelemetry في مستعرض ويب اليوم؟
تعد بيئة الاختبار المعزولة للويب OpenTelemetry نسخة المستودع المصممة لجعل OpenTelemetry تعمل في مستعرض. لا يمكن بعد إرسال بيانات تتبع الاستخدام إلى Application Insights. لا تحدد SDK أحداث العميل العامة.
هل يتم دعم تشغيل Application Insights جنبا إلى جنب مع وكلاء منافسين مثل AppDynamics وDataDog و NewRelic؟
لا. هذه الممارسة ليست شيئا نخطط لاختباره أو دعمه، على الرغم من أن Distros الخاصة بنا تسمح لك بالتصدير إلى نقطة نهاية OTLP جنبا إلى جنب مع Azure Monitor في وقت واحد.
هل يمكنني استخدام ميزات المعاينة في بيئات الإنتاج؟
يستخدم بعض العملاء OpenTelemetry Collector كبديل للعامل، على الرغم من أن Microsoft لا تدعم رسميا نهجا يستند إلى عامل لمراقبة التطبيق حتى الآن. في هذه الأثناء، ساهم مجتمع المصدر المفتوح بمصدر OpenTelemetry Collector Azure Monitor الذي يستخدمه بعض العملاء لإرسال البيانات إلى Azure Monitor Application Insights. هذا غير معتمد من قبل Microsoft.
ما الفرق بين OpenCensus وOpenTelemetry؟
OpenCensus هو مقدمة OpenTelemetry. ساعدت Microsoft في الجمع بين OpenTracing وOpenCensus لإنشاء OpenTelemetry، وهو معيار واحد للمراقبة للعالم. تستند Python SDK الحالية الموصى بها للإنتاج ل Azure Monitor إلى OpenCensus. تلتزم Microsoft بإجراء Azure Monitor استنادا إلى OpenTelemetry.