Azure / Azure/azure-functions-dotnet-worker
Tracing is broken when AspNetCore integration is used
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
### Description
I configure ASP.NET Core integration along with OTel in the following way
```csharp
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(s => s.AddOpenTelemetry()
.WithTracing(t => t
.AddSource("testme")
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation())
.UseFunctionsWorkerDefaults()
.UseOtlpExporter())
.Build();
```
and enable host telemetry with
```json
"telemetryMode": "openTelemetry"
```
In my function code I create another activity
```csharp
[Function("Function1")]
public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
using var act = test.StartActivity("THIS IS A TEST");
_logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
await response.WriteStringAsync("Welcome to Azure Functions!");
return response;
}
```
## What I get:

I.e.
- `GET` - incoming HTTP request to host
- `GET` - outgoing HTTP request from host to worker
- `TestFuncs GET api/Function1` - incoming request on worker tracked by ASP.NET Core and OTel instrumentation on the worker
- `THIS IS A TEST` generated within `Function1` execution. **It's a child of the incoming request to host** - this is the problem
## What I expect
- `GET` - incoming HTTP request to host
- `GET` - outgoing HTTP request from host to worker
- `TestFuncs GET api/Function1` - incoming request on worker tracked by ASP.NET Core and OTel instrumentation on the worker
- `THIS IS A TEST` generated within `Function1` execution. It's a child of the incoming request to worker
### Steps to reproduce
- Run aspire dashboard `docker run --rm -p 18888:18888 -p 4317:18889 -p 4318:18890 --name aspire-dashboard mcr.microsoft.com/dotnet/nightly/aspire-dashboard:latest`
- Run https://github.com/lmolkova/testfuncotel/tree/aspnetcoreint locally
Related to https://github.com/Azure/azure-functions-dotnet-worker/issues/2733
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.