Skip to content

Extend Logs API to allow passing in attributes #4402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adinauer
Copy link
Member

📜 Description

Extend Logs API to allow passing in attributes

💡 Motivation and Context

Filtering Logs in Sentry via custom attributes.

💚 How did you test it?

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Copy link
Contributor

github-actions bot commented May 14, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Extend Logs API to allow passing in `attributes` ([#4402](https://github.com/getsentry/sentry-java/pull/4402))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 5ca032d

Copy link
Contributor

github-actions bot commented May 14, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 429.70 ms 484.57 ms 54.87 ms
Size 1.58 MiB 2.08 MiB 510.52 KiB

Previous results on branch: feat/logs-attributes-in-api

Startup times

Revision Plain With Sentry Diff
878e381 402.20 ms 417.65 ms 15.45 ms

App size

Revision Plain With Sentry Diff
878e381 1.58 MiB 2.08 MiB 510.51 KiB

}

@SuppressWarnings("AnnotateFormatMethod")
private void captureLog(
final @Nullable Map<String, Object> attributes,
Copy link
Member

Choose a reason for hiding this comment

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

I don't like it too much that it's the first param but I guess it must be like this because of the varargs right?

Copy link
Member

Choose a reason for hiding this comment

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

I would like it more for this to be the last param but I don't think that's possible. Either way it's fine, I would expect most users to not go through this API

@lcian lcian force-pushed the feat/logs-attributes-in-api branch from 3a26d0a to 5ca032d Compare May 15, 2025 15:52
@lcian
Copy link
Member

lcian commented May 15, 2025

Sorry pushed on this branch by mistake, should be restored, please double check

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

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

Did some manual tests and everything works as intended except for serialization of arbitrary objects as attributes, opened a PR on top of this to fix that #4409

final @NotNull HashMap<String, SentryLogEventAttributeValue> attributes = new HashMap<>();

if (incomingAttributes != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a copy of the attributes (here or in the capture method) to avoid having a map that could be changed while we iterate on it?

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