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

Skip to content

[Logs 1] Add Sentry Log feature to Java SDK #4372

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

Merged
merged 5 commits into from
May 13, 2025
Merged

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented May 6, 2025

📜 Description

Add API for capturing logs.

💡 Motivation and Context

Partial implementation for #4350

💚 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

sentry.sdk.name: The name of the SDK that sent the log
sentry.sdk.version: The version of the SDK that sent the log
[BACKEND SDKS ONLY] server.address: The address of the server that sent the log. Equivalent to server_name we attach to errors and transactions.

Copy link
Contributor

github-actions bot commented May 6, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 3f20c35

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.

Left some comments, otherwise LGTM as a first implementation

@adinauer
Copy link
Member Author

adinauer commented May 7, 2025

Thanks @lcian I changed the code in #4374 in order to reduce merge conflicts.

Copy link
Contributor

@buenaflor buenaflor left a comment

Choose a reason for hiding this comment

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

doing a drive by review since we also implement logs for Dart :)

Comment on lines +13 to +22
public final class SentryLogEvent implements JsonUnknown, JsonSerializable {

private @NotNull SentryId traceId;
private @NotNull Double timestamp;

private @NotNull String body;

private @Nullable SentryLevel level;
private @Nullable Map<String, SentryLogEventAttributeValue> attributes;
private @Nullable Map<String, Object> unknown;
Copy link
Contributor

@buenaflor buenaflor May 7, 2025

Choose a reason for hiding this comment

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

I think the optional severity_number is missing which later on is inferred by the SDK if not set, e.g

https://github.com/getsentry/sentry-javascript/blob/caa13167c5d6e35dd2a5dbc08b86f0f0f40681eb/packages/core/src/logs/constants.ts#L8

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean for other SDKs using the Java SDK? That should land in unknown if Java SDK doesn't have it directly.

I can add it in a follow up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also the severity number field that is optional. If it is not set (by the user) then the SDK will use the default values like in the link above

See here

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in #4391 but it cannot be passed in via API yet.

Copy link
Collaborator

@lbloder lbloder left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Left some comments to be addressed in later prs

@adinauer adinauer changed the title Add Sentry Log feature to Java SDK [Logs 1] Add Sentry Log feature to Java SDK May 12, 2025
Copy link
Contributor

github-actions bot commented May 12, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 401.04 ms 451.06 ms 50.02 ms
Size 1.58 MiB 2.08 MiB 508.27 KiB

Previous results on branch: feat/java-log-feature

Startup times

Revision Plain With Sentry Diff
04e25fb 469.47 ms 528.80 ms 59.33 ms

App size

Revision Plain With Sentry Diff
04e25fb 1.58 MiB 2.08 MiB 508.27 KiB

- `options.getLogs().setEnabled(true)` in `Sentry.init` / `SentryAndroid.init`
- `logs.enabled=true` in `sentry.properties`
- `sentry.logs.enabled=true` in `application.properties`
- `sentry.logs.enabled: true` in `application.yml`
Copy link
Member

Choose a reason for hiding this comment

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

manifest or no manifest? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah we should add it to manifest as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in #4395

Copy link
Member

@stefanosiano stefanosiano left a comment

Choose a reason for hiding this comment

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

nice!

@adinauer adinauer merged commit b01f8f5 into main May 13, 2025
33 of 34 checks passed
@adinauer adinauer deleted the feat/java-log-feature branch May 13, 2025 11:22
public final class SentryLogEvent implements JsonUnknown, JsonSerializable {

private @NotNull SentryId traceId;
private @NotNull Double timestamp;
Copy link
Member

Choose a reason for hiding this comment

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

could've been a primitive since it's required?

private @NotNull SentryId traceId;
private @NotNull Double timestamp;

private @NotNull String body;
Copy link
Member

Choose a reason for hiding this comment

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

haven't seen it in the docs, but maybe you know - do we need to do any truncation here? E.g. if there's a requirement that relay will drop logs with body longer than XXX or something

Copy link
Member Author

Choose a reason for hiding this comment

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

The same limit that applies to error envelopes also applies here. Not truncation needed / wanted. We probably want to implement a weight based approach in the future to only send a lower batch size in some cases.

Copy link
Member Author

@adinauer adinauer May 13, 2025

Choose a reason for hiding this comment

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

And the limit applies to the whole batch, since it's a single envelope.

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.

6 participants