|
| 1 | +# LLM context telemetry: research and decisions |
| 2 | + |
| 3 | +## Contract |
| 4 | + |
| 5 | +Add two common properties to the optional Microsoft.Testing.Extensions.Telemetry |
| 6 | +usage collector: |
| 7 | + |
| 8 | +| Property | Value | |
| 9 | +| --- | --- | |
| 10 | +| `is llm` | Existing `LLMEnvironmentDetector` result as `true`/`false`; a heuristic, not proof of human/agent authorship. | |
| 11 | +| `CopilotAgentSessionId` | Normalized `COPILOT_AGENT_SESSION_ID`, or `not_present` when absent/empty. | |
| 12 | + |
| 13 | +Match the SDK's `CopilotAgentSessionId`: preserve canonical UUID versions 1-8 |
| 14 | +with RFC variant, plus the nil UUID, including original casing. Hash other |
| 15 | +values as lowercase SHA-256 of their original UTF-8 bytes, without trimming. |
| 16 | +A literal `not_present` input is hashed. A missing telemetry property means |
| 17 | +collection support is unknown. |
| 18 | + |
| 19 | +The signals are independent. Snapshot them before queueing each event, without |
| 20 | +mutating caller dictionaries or accepting overrides. Preserve existing opt-outs, |
| 21 | +session/reporter IDs, runtime restrictions, cancellation, and transport. |
| 22 | +No new public API or dependency; no changes to console defaults, OpenTelemetry, |
| 23 | +or JSON-RPC `ServerTelemetry` forwarding, which operates independently of usage |
| 24 | +telemetry opt-out. |
| 25 | + |
| 26 | +## Research and decision |
| 27 | + |
| 28 | +[dotnet/sdk#57106](https://github.com/dotnet/sdk/pull/57106) adds cross-product |
| 29 | +Copilot correlation. Its pinned |
| 30 | +[normalization implementation](https://github.com/dotnet/sdk/blob/a436089fa916892516a2d1d4ed964c96d07380fa/src/Cli/dotnet/Telemetry/TelemetryCommonProperties.cs) |
| 31 | +was checked against the referenced Copilot runtime source on 2026-11-18. |
| 32 | + |
| 33 | +Reuse TestFx's detector, previously used only for console defaults, and collect |
| 34 | +the fields in `AppInsightsProvider.LogEventAsync`. Construction-time capture was |
| 35 | +rejected because queued events could receive stale context. Keep normalization |
| 36 | +private: TestFx's existing hasher uppercases inputs and would break correlation; |
| 37 | +`Guid.TryParse` accepts UUID forms outside Copilot's contract. Collecting agent |
| 38 | +names/raw marker values or adding OpenTelemetry tags is outside scope. |
| 39 | + |
| 40 | +Use the SDK's exact correlation key to simplify cross-product queries. Keep |
| 41 | +`is llm` distinct from SDK's `llm`, which contains agent names rather than a boolean. |
| 42 | + |
| 43 | +## Test-value evidence |
| 44 | + |
| 45 | +SDK-key alignment validated on 2026-11-18, Debug, SDK `12.0.100-alpha.1.26562.108`. |
| 46 | +Base: `53b0b9bd9df4f856498e18dec978ca86c9753cfc`. |
| 47 | +Behavioral `src`/`test` patch SHA-256: |
| 48 | +`c6abdb455adf3e0e0634e1dfedb99d8397ff21d98d640e8a7408618de3a41fbf`. |
| 49 | +This document is excluded from that patch identity. |
| 50 | + |
| 51 | +| Contract | Tests | |
| 52 | +| --- | --- | |
| 53 | +| Detection and correlation | `LogEvent_ReportsLLMContext` (6 cases), `LogEvent_NormalizesCopilotSessionId` (17 cases: UUIDs, absence, casing, whitespace, malformed IDs, UTF-8). | |
| 54 | +| Queueing and ownership | `LogEvent_SnapshotsContextBeforeQueueingWithoutMutatingCallerProperties`: three distinguishable events, changing context, overrides, and dictionary reuse. | |
| 55 | +| Opt-outs | Packaged environment-variable and `TestApplicationOptions` tests with the real provider registered. | |
| 56 | +| Shipping boundary | `Telemetry_Context_IsIncludedInEveryUsageEvent`: four contexts per runtime; checks each event's fields, identity, and unchanged platform session ID. | |
| 57 | + |
| 58 | +| Selection | Passed / executed | Result | |
| 59 | +| --- | --- | --- | |
| 60 | +| Provider tests: .NET 10 / 11 / Framework 4.6.2 / 4.7.2 | 57 / 57, 57 / 57, 54 / 54, 54 / 54 | Exit 0 | |
| 61 | +| Packaged acceptance: .NET 10 / 11 / Framework 4.6.2 | 15 / 15 | Exit 0 | |
| 62 | + |
| 63 | +Current alignment: **222 unit and 15 acceptance cases passed**, no failures/skips. |
| 64 | +TRX/JUnit/CTRF counts were reconciled; method-level parallelization was preserved. |
| 65 | +The acceptance host runs on .NET 12. Its custom-framework children intentionally |
| 66 | +exit 8 (`ZeroTests`), exercising startup/shutdown telemetry rather than counting |
| 67 | +zero-test runs as regression tests. |
| 68 | + |
| 69 | +**Executed regression check:** the same 17 `LogEvent_NormalizesCopilotSessionId` |
| 70 | +cases ran in an isolated output copy with the preserved pre-rename provider. |
| 71 | +All 17 failed specifically because `CopilotAgentSessionId` was missing (exit 2). |
| 72 | +Replacing only that DLL with the rebuilt provider yielded 17 passes (exit 0); |
| 73 | +test assembly bytes were unchanged. Both runs also checked report counts. |
| 74 | +The initial feature's separate field-removal check detected 24 failures before |
| 75 | +key alignment; its earlier reports remain archived. |
| 76 | + |
| 77 | +Both changed `3.0.0-dev` packages packed successfully. All six executed consumer |
| 78 | +DLLs matched their NuGet payload hashes, using `netstandard2.0` assets on |
| 79 | +.NET Framework. Isolated restores and actual loaded assembly paths were checked. |
| 80 | +The packaged scenarios verified 24 usage events across 12 context-specific launches, |
| 81 | +including the SDK key's presence and the old space-separated key's absence. |
| 82 | + |
| 83 | +## Validation notes and remaining work |
| 84 | + |
| 85 | +CI exposed a Release-only failure: the namespace import for `RoslynString` was |
| 86 | +guarded by `#if DEBUG`. The import is now unconditional. Release packing passes |
| 87 | +for all three product TFMs, and 190 Release provider cases pass across .NET 10/11 |
| 88 | +and Framework 4.6.2/4.7.2 (49/49/46/46). This fixes compilation, not runtime behavior. |
| 89 | + |
| 90 | +Full commands, reports, patches, and DLL hashes remain in session artifacts under |
| 91 | +`sdk-key-alignment`: `validate.ps1`, `comparison-provenance.json`, and |
| 92 | +`consumer-provenance-complete\provenance.json`. Fixture-only packages were restored |
| 93 | +temporarily for acceptance and removed afterward; the isolated comparison output |
| 94 | +is also cleaned up. Final `.\eng\verify-nupkgs.ps1 -configuration Debug` passed. |
| 95 | + |
| 96 | +This is nonvisual metadata; backend ingestion/dashboard queries were not verified. |
| 97 | +Before release, update the |
| 98 | +[public telemetry documentation](https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-telemetry) |
| 99 | +and complete any required telemetry governance review. |
0 commit comments