29 Sep 2023 04:36 PM
I'm trying to work on adding some additional metadata to our Dynatrace distributed traces in our .NET 6 applications. Specifically, I'm trying to accomplish this using the System.Diagnostics.Activity and ActivitySource types natively within the .NET framework. The spans are mostly picked up by the OneAgent that we already use but there are two primary issues I'm seeing.
The following code is adapted from my team's application to provide an example of what we're doing:
private readonly ActivitySource _trace; // initialized in constructor
public async Task DoWork(IEnumerable<int> items)
{
using var doWorkActivity = _trace.StartActivity("DoWork root"); // this shows up in Dynatrace
using var childActivity = _trace.StartActivity("DoWork child"); // this also shows up in Dynatrace, but not as a child of doWork
await Parallel.ForEachAsync(items, async (item, cancellationToken) =>
{
using var parallelActivity = _trace.StartActivity("DoWork parallel method"); // not in Dynatrace at all
await Task.Run(() =>
{
using var taskActivity = _trace.StartActivity("DoWork Task.Run"); // Not in dynatrace at all
// business logic
});
});
}
12 Dec 2023 08:37 PM
Sorry no good answer from me, but just noting I've observed similar issues with Dynatrace not tracking child tasks in a Parallel.ForEachAsync within the context of the parent trace. In my case, we were just using Dynatrace "Custom Services" defined via their UI, not OpenTelemetry (via System.Diagnostics), and we had to add additional "Custom Service" entry points for the child tasks to get any visibility. They however show as independent traces within the Dynatrace UI.