Thanks to visit codestin.com
Credit goes to github.com

Skip to content

use key presence for stacktrace filter instead of value - #400

Merged
cleverchuk merged 2 commits into
mainfrom
cc/NH-126126
Dec 18, 2025
Merged

use key presence for stacktrace filter instead of value#400
cleverchuk merged 2 commits into
mainfrom
cc/NH-126126

Conversation

@cleverchuk

Copy link
Copy Markdown
Contributor

Context:

Span stacktrace filter now checks key presence instead of limiting to only string-key values. This type agnostic approach is consistent with current documentation.

Test Plan:

New unit test and regression.

Test services data

  1. e-1712644058766987264
  2. e-1712643928659124224
  3. e-1742334541200846848
  4. e-1777406072376840192

@cleverchuk
cleverchuk requested a review from a team as a code owner December 16, 2025 03:09
@cleverchuk
cleverchuk requested a review from Copilot December 16, 2025 03:09

Copilot AI 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.

Pull request overview

This PR changes the SpanStacktraceFilter to check for attribute key presence instead of checking for string-typed attribute values. This makes the filter type-agnostic and aligns with the documented behavior.

Key changes:

  • Modified filter logic to check if attribute keys exist regardless of their value types
  • Changed filterAttributes from static to instance field to support proper testing
  • Enhanced test coverage with multiple attribute types (string, long, string arrays, long arrays)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
SpanStacktraceFilter.java Refactored the test method to check for attribute key presence instead of string attribute values, and changed filterAttributes from static to instance field
SpanStacktraceFilterTest.java Replaced mock-based tests with comprehensive tests covering multiple attribute types and proper setup/teardown


public class SpanStacktraceFilter implements Predicate<ReadableSpan> {
private static final Set<String> filterAttributes = new HashSet<>();
private final Set<String> filterAttributes = new HashSet<>();

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

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

Changing filterAttributes from static to instance field may cause thread safety issues if SpanStacktraceFilter instances are shared across threads. Each call to test() modifies this field. Consider making this field static and using thread-safe operations, or document that instances should not be shared across threads.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +46
Set<String> attributes =
readableSpan.getAttributes().asMap().keySet().stream()
.map(AttributeKey::getKey)
.collect(Collectors.toSet());
attributes.retainAll(filterAttributes);
return !attributes.isEmpty();

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

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

This implementation creates a new Set and copies all attribute keys on every invocation. For spans with many attributes, this could be inefficient. Consider using a stream-based approach that short-circuits on the first match: filterAttributes.stream().anyMatch(attr -> readableSpan.getAttributes().asMap().keySet().stream().anyMatch(key -> key.getKey().equals(attr)))

Suggested change
Set<String> attributes =
readableSpan.getAttributes().asMap().keySet().stream()
.map(AttributeKey::getKey)
.collect(Collectors.toSet());
attributes.retainAll(filterAttributes);
return !attributes.isEmpty();
return filterAttributes.stream().anyMatch(
attr -> readableSpan.getAttributes().asMap().keySet().stream()
.anyMatch(key -> key.getKey().equals(attr))
);

Copilot uses AI. Check for mistakes.

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.

Any merit to this suggestion?

@cleverchuk cleverchuk Dec 17, 2025

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.

yeah. compute-wise superior and memory-wise inferior in worst case scenario. all round superior actually.

cheempz
cheempz previously approved these changes Dec 16, 2025

@cheempz cheempz 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.

LGTM pending question.

Comment on lines +41 to +46
Set<String> attributes =
readableSpan.getAttributes().asMap().keySet().stream()
.map(AttributeKey::getKey)
.collect(Collectors.toSet());
attributes.retainAll(filterAttributes);
return !attributes.isEmpty();

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.

Any merit to this suggestion?

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@cheempz cheempz 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.

Thanks for the revisit!

@cleverchuk
cleverchuk merged commit f9fd5e1 into main Dec 18, 2025
53 of 63 checks passed
@cleverchuk
cleverchuk deleted the cc/NH-126126 branch December 18, 2025 01:12
@cleverchuk

Copy link
Copy Markdown
Contributor Author

merged because lambda-release-test failing is not actual test failure. it's failure to write test results file.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants