Skip to content

Add compoment min level logging - #1788

Open
cnderrauber wants to merge 2 commits into
mainfrom
component_min_level
Open

Add compoment min level logging#1788
cnderrauber wants to merge 2 commits into
mainfrom
component_min_level

Conversation

@cnderrauber

Copy link
Copy Markdown
Contributor

To Support per project component logging level

To Support per project component logging level
@cnderrauber
cnderrauber requested review from a team and paulwe September 9, 2026 06:15
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fdfcb40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@boks1971 boks1971 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component log levels already work

@cnderrauber

cnderrauber commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

component log levels already work

@boks1971 Does it already have project-level component logging? I have not found the relevant config.

Comment thread logger/logger.go Outdated
Comment on lines +357 to +363
// Note this reports the logger's component min leveler but not its min
// level: see ZapLogger.WithMinLevel. levelEnablers is shared by every
// logger built from this config, so a min leveler's opinion, which is
// particular to one logger, must not be cached in it.
if override := l.zl.componentMinLevel(component); override != nil {
return zaputil.OrLevelEnabler{l.zl.sc.ComponentLevel(component), l.zl.tap, override}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be cached

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache both min level and component min level enablers in fdfcb40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot serialize every WithValues call on a global mutex..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a short circuit to return the OrLevelEnabler directly when ComponentMinLeveler is empty, so the mutex is hit only when the project component level is set in the config. I think in most cases the project component level is empty and behavior keeps unchange, except we turn it on for pion shortly.
Also asked claude about using xsync.Map and it said a mutex is better here..

Technically yes — it's a drop-in, same LoadOrCompute shape as zapConfig. But I'd keep the mutex+map, because the allocation profile is what separates the two cases:

two xsync.Map: 6048 B/op, 10 allocs/op
enablerCache{} (lazy): 24 B/op, 1 alloc/op
enablerCache + 1 entry: 360 B/op, 3 allocs/op

zapConfig's two maps are allocated once per process and read by every logger for the lifetime of the binary — 6 KB amortizes to nothing, and lock-free reads are worth it under fleet-wide contention. This cache is allocated per project logger, and in cloud that means per participant, per relay downtrack, and per HTTP request: pkg/node/middleware.go:236 builds one inside the per-request auth middleware, as does settings.go:96. For a debug-enabled project that's a cache per request, and almost none of those requests ever resolve a pion component — with the lazy maps they pay 24 bytes and never allocate a map at all.

Comment thread logger/logger.go Outdated
})
} else {
enab := zaputil.OrLevelEnabler{l.minLevel, l.sc.ComponentLevel(l.component)}
enab := zaputil.NewOrLevelEnabler(l.minLevel, l.sc.ComponentLevel(l.component), componentMinLevel)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allocates for every derived logger

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an equivalent of zaputil.OrLevelEnabler{} that doesn't allocate more.

Comment thread logger/logger.go Outdated
@boks1971

boks1971 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

component log levels already work

@boks1971 Does it already have project-level component logging? I have not found the relevant config.

Yeah, it is there. @paulwe did that.

But, it is not working for pion logger. Does this address that?

@boks1971

boks1971 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

component log levels already work

@boks1971 Does it already have project-level component logging? I have not found the relevant config.

Yeah, it is there. @paulwe did that.

But, it is not working for pion logger. Does this address that?

Actually, let me retrace. I might be conflating things. Sorry.

@cnderrauber

Copy link
Copy Markdown
Contributor Author

component log levels already work

@boks1971 Does it already have project-level component logging? I have not found the relevant config.

Yeah, it is there. @paulwe did that.

But, it is not working for pion logger. Does this address that?

yeah, for tracing project pion logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants