fix(otel v2): keep the destination merge immutable

The per-backend var merge seeded a plain dict and the gated exporter list a plain
list, both of which the LIT budget counts. Wrap the merge in MappingProxyType and
hand the exporters back as a tuple.
This commit is contained in:
Yucheng He 2026-09-03 17:17:38 -07:00
parent 1779fcf4a7
commit e9df4458c7
2 changed files with 22 additions and 14 deletions

View file

@ -19,7 +19,9 @@ def ensure_mappers(mapper_names: Iterable[str], *names: str) -> list[str]:
return result
def credential_gated_exporters(exporters: "Iterable[ExporterSpec]", owner: "ExporterOwner") -> "list[ExporterSpec]":
def credential_gated_exporters(
exporters: "Iterable[ExporterSpec]", owner: "ExporterOwner"
) -> "tuple[ExporterSpec, ...]":
"""``exporters`` with the operator's destination replaced by a header-gated one.
Used when a credential-mandatory backend is asked to build without the operator's
@ -29,10 +31,10 @@ def credential_gated_exporters(exporters: "Iterable[ExporterSpec]", owner: "Expo
span would be printed to stdout, and the gated spec keeps the owner so the
override filter still recognises which backend this provider speaks for.
"""
return [
return (
*(spec for spec in exporters if not _is_unconfigured_placeholder(spec)),
ExporterSpec(owner=owner, requires_headers=True),
]
)
def _is_unconfigured_placeholder(spec: "ExporterSpec") -> bool:

View file

@ -1028,19 +1028,25 @@ def resolve_tenant_otel_destinations(
if (callback := _get_validated_callback_metadata(item=item, source="otel-destination")) is not None
if callback.callback_type != "failure"
)
merged: Final = {
name: {
var: value
for callback in callbacks
if callback.callback_name == name
for var, value in callback.callback_vars.items()
}
for name in dict.fromkeys(callback.callback_name for callback in callbacks)
}
return tuple(
destination
for name, callback_vars in merged.items()
if (destination := destination_for(name, _tenant_otel_params(callback_vars))) is not None
for name in dict.fromkeys(callback.callback_name for callback in callbacks)
if (
destination := destination_for(
name,
_tenant_otel_params(
MappingProxyType(
{
var: value
for callback in callbacks
if callback.callback_name == name
for var, value in callback.callback_vars.items()
}
)
),
)
)
is not None
)