Skip to content

Conversation

@becomeStar
Copy link
Contributor

@becomeStar becomeStar commented Dec 24, 2025

Introduce an optional Predicate targetAttributeFilter to control how grpc.target is recorded in OpenTelemetry client metrics.

When a filter is provided, targets rejected by the predicate are normalized to "other" to reduce grpc.target metric cardinality, while accepted targets are recorded as-is. If no filter is set, existing behavior is preserved.

This change adds a new Builder API on GrpcOpenTelemetry to allow applications to configure the filter. Tests verify both the Builder wiring and the target normalization behavior.

This is an optional API; annotation (e.g., experimental) can be added per maintainer guidance.

Refs #12322
Related: gRFC A109 – Target Attribute Filter for OpenTelemetry Metrics
grpc/proposal#528

Introduce an optional Predicate<String> targetAttributeFilter in the
OpenTelemetryMetricsModule to control how grpc.target is recorded in
metrics. Also add support in GrpcOpenTelemetry.Builder to allow users
to configure this filter when building the module.
@becomeStar
Copy link
Contributor Author

Thanks for looping me in. I'll keep an eye on the Android desugaring discussion.

In the meantime, I've updated the PR and gRFC A109 with a null-safety check for the filtering logic to make it more robust.

If it turns out that using Java 8's Predicate causes compatibility concerns, I'm happy to adjust the interface accordingly (e.g., using a small custom functional interface), based on what the maintainers think is best.

Replace Predicate with a package-private TargetFilter interface in
fields to ensure compatibility with Android API levels < 24. This
prevents potential runtime issues for Android users who do not use
the filtering feature.

Mark the API as experimental and link the tracking issue.
@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 5, 2026
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 5, 2026
@ejona86
Copy link
Member

ejona86 commented Jan 5, 2026

/gcbrun

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 6, 2026
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Oh, I meant to improve when sending my last comment.

@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 6, 2026
@ejona86
Copy link
Member

ejona86 commented Jan 6, 2026

/gcbrun

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants