Using ambient context
In complex applications, we usually have multiple layers of spans in each trace. These spans are emitted by different libraries that are not aware of each other. Still, they are correlated because of the ambient context propagated in the Activity.Current
property.
Let’s create two layers of activities – we’ll make processing more resilient by retrying failed operations and instrumenting tries and the logical DoWork
operation:
Worker.cs
public static async Task DoWork(int workItemId) { using var workActivity = Source.StartActivity(); workActivity?.AddTag("work_item.id", workItemId); await DoWithRetry(async tryCount => { using var tryActivity = Source.StartActivity("Try"); try { await DoWorkImpl(work.Id, tryCount); tryActivity...