Skip to content

Commit 613d6bb

Browse files
committed
update investigation doc
1 parent 0e11757 commit 613d6bb

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/development/investigations/APMSVLS-58-Azure-Functions-span-parenting.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,22 @@ Added `aas.function.process` tag to distinguish host vs worker spans:
177177

178178
### Environment
179179

180+
**All Function Apps** (Resource Group: `lucas.pimentel`, Location: Canada Central):
181+
182+
| Name | Purpose |
183+
|------|---------|
184+
| lucasp-premium-linux-isolated-aspnet | **Primary test app** - Isolated .NET 8 with ASP.NET Core Integration |
185+
| lucasp-premium-linux-isolated | Isolated .NET 8 (no ASP.NET Core) |
186+
| lucasp-premium-linux-inproc | In-process .NET 6 |
187+
| lucasp-premium-windows-isolated-aspnet | Windows isolated with ASP.NET Core |
188+
| lucasp-premium-windows-isolated | Windows isolated (no ASP.NET Core) |
189+
| lucasp-premium-windows-inproc | Windows in-process |
190+
| lucasp-consumption-windows-isolated | Windows consumption plan |
191+
| lucasp-flex-consumption-isolated | Flex consumption plan |
192+
193+
**Primary Test App:**
194+
- **Name**: `lucasp-premium-linux-isolated-aspnet`
180195
- **Resource Group**: `lucas.pimentel`
181-
- **Primary Test App**: `lucasp-premium-linux-isolated` (isolated-dotnet8-aspnetcore)
182196
- **Source**: `D:\source\datadog\serverless-dev-apps\azure\functions\dotnet\isolated-dotnet8-aspnetcore`
183197

184198
### Steps
@@ -302,6 +316,44 @@ Since AsyncLocal context doesn't flow through Azure Functions middleware, use `H
302316
- Use `FunctionContext.Features` to store/retrieve scope
303317
- Custom middleware to bridge AsyncLocal → Features before context is lost
304318

319+
## Implementation Progress
320+
321+
### Phase 3: HttpContext.Items Bridge (In Progress)
322+
323+
**Status**: Code implemented, testing pending
324+
325+
**Changes Made** (Commit: d0e31854a):
326+
327+
1. **Store scope in HttpContext.Items**
328+
- File: `tracer/src/Datadog.Trace/PlatformHelpers/AspNetCoreHttpRequestHandler.cs:142`
329+
- Added: `httpContext.Items["__Datadog.Trace.AspNetCore.ActiveScope"] = scope;`
330+
- Stores the AspNetCore scope immediately after creation
331+
332+
2. **Add Items property to IFunctionContext**
333+
- File: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/Isolated/IFunctionContext.cs:22`
334+
- Added: `IDictionary<object, object>? Items { get; }`
335+
- Allows duck-typed access to FunctionContext.Items
336+
337+
3. **Retrieve scope from HttpContext.Items**
338+
- File: `tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Azure/Functions/AzureFunctionsCommon.cs:262-297`
339+
- Logic:
340+
1. Check if `tracer.InternalActiveScope == null` (AsyncLocal didn't flow)
341+
2. Try to get HttpContext from `context.Items["__AspNetCoreHttpContext__"]`
342+
3. Try to get scope from `httpContext.Items["__Datadog.Trace.AspNetCore.ActiveScope"]`
343+
4. Use scope as parent if found, otherwise fall back to header extraction
344+
- Only uses HttpContext.Items when AsyncLocal fails (maintains backward compatibility)
345+
346+
**Next Steps**:
347+
1. Deploy updated NuGet package to `lucasp-premium-linux-isolated-aspnet`
348+
2. Trigger HttpTest function
349+
3. Download and analyze traces to verify:
350+
- Worker's `azure_functions.invoke` is now child of `aspnet_core.request`
351+
- All spans in same trace
352+
- Correct parent_id relationships
353+
354+
**Pending**:
355+
- Step 3: Skip host span creation when HTTP proxying is detected (secondary priority)
356+
305357
## References
306358

307359
- [Azure Functions ASP.NET Core Integration](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=hostbuilder%2Cwindows#aspnet-core-integration)

0 commit comments

Comments
 (0)