Documentation forSolarWinds Observability SaaS

Azure Functions Telemetry Collection

Azure Functions is a serverless solution that runs on top of managed infrastructure such as Azure App Service or Azure Container Apps. Functions has built-in OpenTelemetry capabilities that can be used to export telemetry to an OTLP-compatible backend, including SolarWinds Observability.

Telemetry Sources in Azure Functions

Azure Functions can generate telemetry from two distinct components: the Azure Functions host and the language worker. Understanding where telemetry originates is important when configuring OpenTelemetry, particularly when determining which telemetry should be collected, sampled, and exported.

The Azure Functions host is the runtime that manages the execution of Functions. It is responsible for activities such as receiving and dispatching trigger events, managing function invocations, and handling bindings and other runtime operations. Telemetry generated by the host provides visibility into the operation of the Functions runtime and the invocation lifecycle. This telemetry is separate from what is generated by the application code running in the worker.

The language worker is the process that runs the Function’s application code. Depending on the language and instrumentation configuration, the worker can generate OpenTelemetry traces, metrics, and logs from the application and the libraries it uses. For example, instrumentation in the worker can create spans that represent the execution of the function and calls to downstream services such as HTTP endpoints or other Azure resources.

This distinction is important for distributed tracing. A request may enter the Azure Functions host, be dispatched to the language worker, and then generate additional spans as the application executes. Correct propagation of trace context between these components allows telemetry from the host and worker to be associated with the same distributed trace. This makes it possible to follow a request across the Azure Functions runtime and the application code, as well as across downstream dependencies.

Because telemetry can originate from both components, enabling OpenTelemetry for an Azure Function typically means both configuring it at the host level, and setting up instrumentation at the worker level, which will be different per language.

Enable OpenTelemetry for the host

First, update the Function’s host.json file to add a "telemetryMode": "OpenTelemetry" element to the root collection. Example host.json file:

{
    "version": "2.0",
    "telemetryMode": "OpenTelemetry",
    ...
}

Then use the Function’s app settings to specify environment variables that configure the data export. There may be settings specific to a language worker, check the official Use OpenTelemetry with Azure Functions documentation making sure to select the appropriate language and the “OTLP Exporter” tab. For example, for a C# Function see the Enable OpenTelemetry in the Functions host and Configure application settings sections.

The required environment variable settings to export to SolarWinds are described below along with recommended and useful settings.

Required Configuration

Environment Variable Value Description
OTEL_EXPORTER_OTLP_ENDPOINT Determine based on your data center, for example, https://otel.collector.na-01.cloud.solarwinds.com:443 OTLP endpoint for SolarWinds collector. See SolarWinds Observability | Data centers and endpoint URIs for the specific OTLP endpoint for each data center.
OTEL_EXPORTER_OTLP_HEADERS authorization=Bearer%20<your-api-token> Bearer auth token header with your SolarWinds Observability API Token. The header value should be URL encoded.

Recommended/ Useful Configuration

Environment Variable Value Description
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE delta SolarWinds Observability APM charts and dashboards require delta temporality metrics, meaning that each reported data point represents only the change or difference in value measured since the last reporting interval.
OTEL_SERVICE_NAME <service-name-override> By default, the Azure Function app name will be used as the service name. This environment variable can set an override. See also the Default behavior section in the official Microsoft documentation.

Sampling

SolarWinds may drop traces during ingestion if the volume exceeds fair use as seen within the customer base.

Configuring a sampler for the OpenTelemetry instrumentation helps control the volume of traces that is collected and exported. Azure Functions can process a high volume of requests, and collecting traces for every request can generate a large amount of data.

A sampler allows you to trace a representative subset of requests while still providing useful visibility into application behavior and performance. The sampling probability can be adjusted based on the function's request volume and the level of observability required.

We recommend using the parentbased_traceidratio sampler with the probability set to 0.1 as a safe default. This limits collection to 10% of requests while honoring upstream sampling decisions, and can be tuned up or down by changing the OTEL_TRACES_SAMPLER_ARG environment variable.

Environment Variable Value Description
OTEL_TRACES_SAMPLER parentbased_traceidratio Respects upstream sampling decisions while enforcing configurable sampling limits.
OTEL_TRACES_SAMPLER_ARG 0.1

For the parentbased_traceidratio sampler, this value represents the sampling probability and must be a number in the [0..1] range (for example, 0.1 for 10%). It represents the proportion of requests received by the Azure Function that will be sampled for tracing.

Depending on the volume of requests processed by the Azure Function, this value can be decreased or increased.

Telemetry attributes for entity correlation

SolarWinds Observability uses attributes available on the Azure Functions telemetry for entity correlation, for example between the APM Service and the Cloud API Monitoring Azure entities. The key attributes for inference include cloud.provider, cloud.platform and cloud.resource_id.

Functions on the Flex Consumption hosting plan currently do not collect cloud.resource_id as noted in Flex Consumption: OTel semconv attribute cloud.resource_id is missing · Issue #11838 · Azure/azure-functions-host.

If your Function is on the Flex Consumption hosting plan, the OTEL_RESOURCE_ATTRIBUTES environment variable can be used in the Function’s app setting to manually set cloud.resource_id to the expected value.

Enable OpenTelemetry for the application (language worker)

In general, enabling requires adding OpenTelemetry dependencies for export and instrumentation to your application, updating the application code to set up the OTel SDK and initialize instrumentation, and (optionally) using the OTel API to manually collect logs, metrics and traces. Check the official Use OpenTelemetry with Azure Functions documentation making sure to select the appropriate language and the “OTLP Exporter” tab. For example, for a C# Function see the Enable OpenTelemetry in your app section.

.NET

See Enable OpenTelemetry in your app (C# | OTLP export) for the official documentation on how to update your application to output OpenTelemetry data.

The example below shows the updates needed to add instrumentation for basic HTTP client requests (such as System.Net.Http.HttpClient or System.Net.HttpWebRequest) using the OpenTelemetry.Instrumentation.Http package. If your application uses the Azure SDK the distributed tracing section of their Diagnostics page may also be helpful.

  1. Run these commands to install the required assemblies in your app:

    Windows Command Prompt :

    dotnet add package Microsoft.Azure.Functions.Worker.OpenTelemetry
    dotnet add package OpenTelemetry.Extensions.Hosting 
    dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol   
    dotnet add package OpenTelemetry.Instrumentation.Http
    
  2. In your Program.cs project file, add this using statement:

    C#:

    using Microsoft.Azure.Functions.Worker.Builder;
    using Microsoft.Azure.Functions.Worker.OpenTelemetry;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using OpenTelemetry;
    using OpenTelemetry.Trace;
  3. Configure OpenTelemetry based on whether your project startup uses IHostBuilder or IHostApplicationBuilder.

    IHostApplicationBuilder

    In Program.cs, add this line of code after ConfigureFunctionsWebApplication:

    builder.Services.AddOpenTelemetry()
        // The Functions worker defaults are specific to Azure Functions and
        // by default will set the service name to be the Azure Function Name
        .UseFunctionsWorkerDefaults()
        // Adds instrumentation for http client calls made by the Azure Function
        .WithTracing(traceBuilder => traceBuilder.AddHttpClientInstrumentation())
        .UseOtlpExporter();

    IHostBuilder

    In Program.cs, add this ConfigureServices call in your HostBuilder pipeline:

    .ConfigureServices(s =>
    {
        s.AddOpenTelemetry()
        // The functions worker defaults is specifically for Azure Functions and
        // by default will set the service name to be the Azure Function Name
        .UseFunctionsWorkerDefaults()
        // Adds instrumentation for http client calls made by the Azure Function
        .WithTracing(tracing => tracing.AddHttpClientInstrumentation());
        .UseOtlpExporter();
    })