← Back to Pull requests

[Blocked] Add automatic process environment context propagation #5660

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 09, 2026 14:26 UTC
Author

[!WARNING]

Blocked by https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/4853

Motivation

Processes launched from CI jobs, test runners, and command-line tools can receive trace context through environment variables, but automatic instrumentation currently starts disconnected root activities and does not inject the active context into child processes. An application using ActivitySource.StartActivity("job") should continue the incoming context without manually extracting it or configuring method targets.

Related specification PR:

  • https://github.com/open-telemetry/opentelemetry-specification/pull/5421/
  • Changes

  • Extract the startup environment once through the configured propagators, with parent, link, and none modes. The default is parent.

  • Apply incoming parent context or links before sampling through DiagnosticSource 10.x's shared private activity factory, covering public ActivitySource.StartActivity and CreateActivity overloads. Preserve ambient and supplied parents, existing links, delayed starts, and normal activity lifetimes without creating a synthetic process span.

  • Register the activity factory hook only when extraction produces valid incoming trace context. Extend the typed CallTarget path to nine arguments, reuse read-only incoming links, and preserve deferred enumeration for application links.

  • Initialize incoming baggage once, preserving existing ambient values and following normal execution-context inheritance. Initialize default propagators when SDK setup is delegated to the application without creating a provider.

  • Inject active trace context and live baggage into direct child-process launches by default, using an independent environment copy that preserves the parent environment and reusable ProcessStartInfo. Forward incoming trace context in parent mode when there is no active span.

  • Configure both directions through environment variables or nested YAML process.context_extraction.mode and process.context_injection.enabled options. No-code method instrumentation remains optional.

  • Keep the configuration reference concise and document supported .NET APIs, source registration, propagator-dependent environment fields, precedence, and implementation boundaries in the process instrumentation guide. Update YAML examples and the changelog.
  • ActivitySource performance

    The added per-call ActivitySource hook overhead is absent when OTEL_DOTNET_AUTO_TRACES_PROCESS_INSTRUMENTATION_CONTEXT_EXTRACTION_MODE=none or OTEL_DOTNET_AUTO_TRACES_PROCESS_INSTRUMENTATION_ENABLED=false is configured at startup. In both cases, the activity factory hook is excluded before bytecode rewriting; there is no injected callback or per-call enablement check. The hook is also omitted when extraction finds no valid incoming trace context. With extraction set to none, child-process injection remains independently configurable; disabling PROCESS disables both directions. General profiler, SDK, and other instrumentation costs can still remain. Native audits confirmed the disabled paths (the extraction mode was named off in the measured revision).

    Measured head: 536388a48532750a501e2bf94b36e7b946d69a82. Ubuntu 24.04.4 Linux x64/KVM, AMD EPYC 7571, CPU 3, concurrent workstation GC, runtime-default tiering. The VM is unreserved; frequency controls are unavailable.

    Measured targets: .NET 8.0.33, .NET 9.0.22: DiagnosticSource assembly 10.0.0.0, file 10.0.25.52411; .NET 10.0.14: DiagnosticSource assembly 10.0.0.0, file 10.0.1426.52326.

    Baseline: same profiler, PROCESS disabled, equivalent cached manual parent/link inputs, no exporters. Controls preserve parent selection, sampling decisions, and activity lifetimes. The primary listener uses fixed decisions; NoListeners uses the plain overload in every profile. Missing incoming trace context, disabled extraction, and disabled PROCESS leave the factory hook unregistered (native audits). Δ includes interception and context/link handling: automatic minus baseline after BenchmarkDotNet empty-loop subtraction; brackets show nominal paired 95% Student t intervals. Δ % = 100 × (automatic mean − baseline mean) / baseline mean, using unrounded aggregate means; percentages are point estimates. Allocation deltas are B/op, parent/link.

    | .NET 10 workload | Parent Δ ns/op [nominal 95% CI] | Parent Δ % | Link Δ ns/op [nominal 95% CI] | Link Δ % | +B/op parent/link |
    | --- | ---: | ---: | ---: | ---: | ---: |
    | Root | +101.0 [86.2, 115.7] | +26.8% | +81.9 [66.1, 97.7] | +15.3% | 0/0 |
    | RootEmptyLinks | +96.9 [84.0, 109.7] | +25.4% | +219.6 [196.3, 242.8] | +42.3% | 0/+128 |
    | RootExistingLink | +100.8 [87.8, 113.8] | +21.8% | +264.3 [241.3, 287.3] | +45.5% | 0/+160 |
    | RootAlreadyLinked | +100.5 [80.4, 120.6] | +21.8% | +233.9 [190.2, 277.5] | +43.3% | 0/+160 |
    | NoListeners | +86.8 [75.7, 97.9] | +632.1% | +77.3 [75.4, 79.2] | +580.7% | 0/0 |
    | Dropped | +79.5 [75.7, 83.3] | +195.3% | +68.3 [60.8, 75.8] | +125.6% | 0/0 |
    | DropReadingLinks | +78.6 [75.2, 82.0] | +123.1% | +238.0 [221.2, 254.9] | +309.2% | 0/+160 |
    | AmbientParent | +72.9 [65.4, 80.4] | +17.8% | +77.6 [72.6, 82.5] | +19.2% | 0/0 |
    | SuppliedContext | +91.0 [74.2, 107.9] | +24.5% | +102.0 [95.9, 108.0] | +28.3% | 0/0 |
    | SuppliedParentId | +45.1 [30.9, 59.3] | +8.2% | +68.0 [40.7, 95.2] | +12.5% | 0/0 |
    | SuppliedEmptyParentId | +36.6 [11.4, 61.8] | +7.6% | +33.2 [8.1, 58.2] | +6.9% | 0/0 |
    | CreateOnly | +88.6 [85.5, 91.7] | +98.9% | +72.1 [62.9, 81.3] | +36.3% | 0/0 |
    | CreateThenStart | +112.6 [73.8, 151.4] | +30.1% | +86.9 [79.6, 94.3] | +16.5% | 0/0 |
    | PropagationOnly | +105.0 [94.2, 115.7] | +28.0% | +86.3 [45.8, 126.9] | +16.3% | 0/0 |

    Sampled Root absolute baseline → automatic: parent 376.9 → 477.8 ns/op; link 534.0 → 615.9 ns/op. NoListeners absolute baseline → automatic: parent 13.7 → 100.5 ns/op; link 13.3 → 90.6 ns/op. Empty-loop subtraction matters here; raw Actual values remain available. The no-listener estimate includes a legacy four-block cohort without captured source/PDB binding; the repeat cannot strengthen that legacy proof.

    In link mode, non-null caller collections add deferred append/de-duplication work: RootEmptyLinks +128 B/op; RootExistingLink +160 B/op; RootAlreadyLinked +160 B/op. Null inputs reuse the singleton; the manual control caches the complete equivalent collection.

    A separate successful sampler reads links before Activity copies them: Root 556.7 → 647.7 ns/op (Δ +91.0 [72.0, 110.0] ns/op; +16.4%; 0 B/op); RootExistingLink 635.2 → 977.3 ns/op (Δ +342.2 [324.3, 360.0] ns/op; +53.9%; +160 B/op).

    Secondary Root cases use matched controls; costs depend on workload and runtime/tiering configuration. The SDK uses an application-owned ParentBased(AlwaysOn) provider without processors/exporters. The full report retains the .NET 8/9 six-workload subsets and remaining SDK/tiering cases.

    | Secondary Root case | Parent Δ ns/op [nominal 95% CI] | Parent Δ % | Link Δ ns/op [nominal 95% CI] | Link Δ % |
    | --- | ---: | ---: | ---: | ---: |
    | .NET 8 | +97.9 [72.0, 123.7] | +20.1% | +72.7 [43.3, 102.1] | +10.5% |
    | .NET 9 | +79.7 [49.0, 110.3] | +17.5% | +63.7 [8.1, 119.2] | +9.8% |
    | .NET 10 application SDK, ParentBased(AlwaysOn) | +89.0 [48.4, 129.6] | +19.1% | +88.1 [74.5, 101.6] | +14.5% |
    | .NET 10 tiering disabled | +120.9 [103.3, 138.6] | +21.0% | +129.4 [114.1, 144.7] | +15.9% |

    Four fresh processes per profile/cohort; 20 iterations/process, all retained (DontRemove); 10 seconds warming the actual method plus 40 BenchmarkDotNet warmups. The frozen plan pools eight blocks for .NET 10 Root, NoListeners, Dropped, AmbientParent, and SuppliedContext; other comparisons use four. Cohorts remain separate in the artifact. Repeats followed observed between-process variance; the plan was then frozen with no further precision-based stopping. These pointwise intervals use process blocks, are exploratory and nominal, and have no sequential-selection or multiplicity adjustment.

    Scope is warmed, single-threaded Linux factory calls, excluding startup, full requests, exporters, child-process creation, and concurrent throughput. Windows, .NET Framework, and ARM were not measured.

    Results · Methodology · Sources · Raw data and audits

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: pellared Review duration: 7722m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #5660"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%