Repository navigation
fix(android): match sampling regexes as substrings and skip invalid patterns - #836
Merged
Merged
Conversation
…atterns CustomSampler used Regex.matches (full-string match), unlike the other SDKs, which do substring matching. It also compiled patterns lazily during span/log processing, so an invalid pattern from the backend threw PatternSyntaxException out of the span processor / log processor. Use containsMatchIn so anchors are needed for full matches, and cache the compilation result per pattern, including failures, so an invalid pattern logs one warning and the rule never matches. Mirrors the Java plugin fix in #381. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-by: termag
abelonogov-ld
approved these changes
Oct 21, 2026
abelonogov-ld
left a comment
Contributor
There was a problem hiding this comment.
Cool! It is even compiled!
Merged
Vadman97
pushed a commit
that referenced
this pull request
Oct 21, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>launchdarkly-observability-android: 0.69.1</summary> ## [0.69.1](launchdarkly-observability-android-0.69.0...launchdarkly-observability-android-0.69.1) (2026-10-21) ### Bug Fixes * **android:** match sampling regexes as substrings and skip invalid patterns ([#836](#836)) ([76127ee](76127ee)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Release `launchdarkly-observability-android` 0.69.1** via Release Please: bumps the package version in `.release-please-manifest.json` and `gradle.properties`, and adds the **0.69.1** changelog entry. > > This patch release ships the bugfix from [#836](#836): Android custom sampling regex rules now use **substring** matching (aligned with other LaunchDarkly observability SDKs) and **invalid patterns are skipped** after a one-time warning instead of breaking sampling. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e7d81fc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes how the Android SDK handles sampling regex rules. It now matches the way the Go SDK does it and the way the Java plugin was fixed in #381, following Andrey's review comment there.
CustomSamplercalledRegex.matches, which only matches the whole string. Every other SDK checks whether the pattern appears anywhere in the value. It now callscontainsMatchIn, sohealthmatchesGET /health-check.^and$still work when a rule needs a full match.PatternSyntaxExceptionout ofEventSpanProcessor.onEnd/SamplingLogProcessor.onEmit. Nothing upstream catches it, including the OpenTelemetry SDK'sSdkSpan.end/SdkLogRecordBuilder.emit, so it reached the app'sspan.end()or log call. Now each pattern's compile result is cached, failures included. A bad pattern logs one warning through the SDK'sObserveLoggerand its rule never matches. Other rules in the same config still apply.ObservabilityServicepasses its logger toCustomSamplerthrough a new optionalloggerparameter (defaults to null, so the constructor stays source-compatible).Note: the cache is cleared on
setConfig, so a bad pattern is warned about once each time a config is loaded, not on every span or log.How did you test this change?
Regex Matching TeststoCustomSamplerTest:^,$and^...$anchors are still respected./gradlew :lib:testDebugUnitTestlocally insdk/@launchdarkly/observability-android(JDK 21, Android SDK platform 35): 544 tests, 0 failures, 2 skipped (already skipped before this change).matchesand no exception handling put back, 7 of the 9 new tests fail.🤖 Generated with Claude Code
Opened from termag
Note
Overview
Aligns Android sampling regex behavior with other LaunchDarkly observability SDKs and hardens error handling when remote rules are malformed.
CustomSamplernow usescontainsMatchIninstead ofRegex.matches, so patterns match when they appear anywhere in span names or log messages (e.g.healthmatchesGET /health-check);^/$still enforce full-string matches when needed. Invalid patterns are compiled through a cachedCompiledRegexpath: compile failures log one warning via optionalObserveLogger, never throw into span/log export, and that rule never matches while later rules in the same config still apply.ObservabilityServicepasses its logger intoCustomSampler. Unit tests add a Regex Matching suite for substring/anchor behavior, invalid-regex safety, and one-time warnings.Reviewed by Cursor Bugbot for commit 71a5b05. Bugbot is set up for automated code reviews on this repo. Configure here.