Setting up a proper role name helps organize profiling sessions effectively. For example:
-
Azure App Service:
If you are running onAzure App Service, the role name will be set up for you automatically. It uses theWEBSITE_SITE_NAMEenvironment variable. -
Other Platforms:
If you are running the application on other platforms (e.g., a development machine, an on-prem Kubernetes cluster, AKS, etc.), you can set the value using OpenTelemetry Resource Semantic Conventions, specificallyservice.name. There are several ways to do this:-
Using environment variables:
# Only need to set one. OTEL_RESOURCE_ATTRIBUTES="service.name=simple-otel-profiler,other.settings=othervalue" OTEL_SERVICE_NAME="simple-otel-profiler" -
Using code (Azure Monitor OpenTelemetry distro):
If you are using
Azure.Monitor.OpenTelemetry.AspNetCore(Option A):builder.Services.AddOpenTelemetry().UseAzureMonitor(); builder.Services.ConfigureOpenTelemetryTracerProvider((_, b) => b.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name")) // Set service.name to `service-name` );
-
Using code (Application Insights 3.x):
If you are using
Microsoft.ApplicationInsights.AspNetCore3.x (Option B):builder.Services.AddApplicationInsightsTelemetry(); builder.Services.ConfigureOpenTelemetryTracerProvider((_, b) => b.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name")) // Set service.name to `service-name` );
For more details, refer to Adding Custom Resource.
-
-
Feedback:
If you think the value should be automatically populated for the platform the app's running on, please open an issue.
-
Role Name Detectors:
We have built several role name detectors. Each detector attempts to retrieve the role name from a specific source, and they are chained together. For example:// Retrieve value from OpenTelemetry resource semantic conventions (`service.name`). services.AddSingleton<IRoleNameDetector, OtelResourceRoleNameDetector>(); // Retrieve value from the `WEBSITE_SITE_NAME` environment variable. services.AddSingleton<IRoleNameDetector, EnvRoleNameDetector>(_ => new EnvRoleNameDetector("WEBSITE_SITE_NAME")); // Retrieve value from another environment variable. services.AddSingleton<IRoleNameDetector, EnvRoleNameDetector>(_ => new EnvRoleNameDetector("RoleName")); // Issue a warning if no value is provided. services.AddSingleton<IRoleNameDetector, UnknownRoleNameDetector>(); // Aggregate the detections. services.AddSingleton<IRoleNameSource, AggregatedRoleNameSource>();
See the source code here.
In the future, OpenTelemetry aims to provide values automatically for various environments, eliminating the need for manual configuration.
For example, in a Kubernetes cluster, the service name can be derived from well-known labels. Refer to the OpenTelemetry Semantics Non-normative specs for more details.
