Azure / Azure/azure-functions-dotnet-worker

Missing log correlation for non sampled requests When sampling is on

Open
#3,378 2 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions) potential-bug
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

### Description

.Net 8 Isolated worker Azure function (with service bus queue trigger/ timer trigger) setup with openteletmetry, exporting logs, traces & metrics via OTLP exporter, have missing trace.id in logs when sampling is on for non sampled requests.

### Steps to reproduce

- Microsoft.Azure.Functions.Worker 2.52.0
- Microsoft.Azure.Functions.Worker.sdk 2.0.7
- Microsoft.Azure.Functions.Worker.OpenTelemetry 1.2.0
- OpenTelemetry.Exporter.OpenTelemetryProtocol 1.15.0
- OpenTelemetry.Extensions.Hosting 1.15.0

I have setup telemetry as follows with all exporting to OtlpExporter (sources omitted for brevity)

`services.
AddOpenTelemetry().
UseFunctionaWorkerDefaults()
.WithTracing()
.WithMetric()
.WithLogging()`

Note: Had to register ("Azure.Messaging.*") tracing source for service bus queue propagation.

I am using the following to control traces,
OTEL_TRACES_SAMPLER
OTEL_TRACES_SAMPLER_ARG

When
OTEL_TRACES_SAMPLER = always_on
Then
Traces are generated
Logs are generated
Logs & Traces correlated

When
OTEL_TRACES_SAMPLER = always_off (any other supported value that samples request)
Then
Traces are not generated for non-sampled request (expected)
Logs are generated for all requests (expected)
**Logs are missing trace.id for non-sampled requests (not-expected)**

Contributor guide

No contributing guide indexed for this repository

Research direction

No source file is named. Start by reproducing the .NET 8 isolated worker setup with Microsoft.Azure.Functions.Worker, OpenTelemetry, OTLP export, and an always_off sampler; inspect how logging and tracing are configured through UseFunctionsWorkerDefaults and the OTEL_TRACES_SAMPLER settings. Done means logs for non-sampled requests retain the expected trace.id while traces remain unsampled.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.