← Back to Pull requests

sdk/log: allow unused loggers to be garbage collected #9638

Open
unknown opened this pull request with 263 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 15:55 UTC
Author

Store loggers in the LoggerProvider cache in weak pointers, allowing them to be garbage collected after the caller stops using them. This leaves us with the empty map entries, which we sweep on cache misses, roughly every time the logger count doubles.

Added a test which puts loggers in its own weak pointers and checks if GC sweeps drop them.

The additional memory cost per logger is 16B. The CPU cost is roughly 142 ns per new logger and 8.7 ns per cache hit. The amortized sweep cost is an additional ~100 ns with a lot of logger churn. I needed to modify the existing benchmark to use fixed batches, so its output isn't dependent on particulars of Go's map implementation. See the raw benchstat output below:

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: 13th Gen Intel(R) Core(TM) i7-13700H
                           │    main     │                weak                 │
                           │   sec/op    │   sec/op     vs base                │
LoggerProviderLogger         308.6n ± 5%   584.3n ± 1%  +89.31% (p=0.000 n=12)
LoggerProviderCachedLogger   48.69n ± 3%   57.24n ± 5%  +17.56% (p=0.000 n=12)
geomean                      122.6n        182.9n       +49.18%

                           │     main     │                weak                 │
                           │     B/op     │    B/op     vs base                 │
LoggerProviderLogger         464.0 ± 0%     480.0 ± 0%  +3.45% (p=0.000 n=12)
LoggerProviderCachedLogger   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=12) 
geomean                                 ²               +1.71%                
¹ all samples are equal
² summaries must be >0 to compute geomean

                           │     main     │                 weak                  │
                           │  allocs/op   │ allocs/op   vs base                   │
LoggerProviderLogger         1.000 ± 0%     2.000 ± 0%  +100.00% (p=0.000 n=12)
LoggerProviderCachedLogger   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=12) 
geomean                                 ²                +41.42%            

Resolves #6352

Diff: 263 lines (+197 / -66) across 3 files Reviewer: pellared Review duration: 209m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.44) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.44 · 263 lines diff across 3 files
0.44
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
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.334
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #9638"
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: 44.3% (MEDIUM) · Higher = larger blast radius
44.3%
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: 23.6% · Safe to merge
23.6%