Skip to content

Logs: Integrate in Sentry Client #2920

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 27 commits into
base: feat/logs
Choose a base branch
from
Open

Logs: Integrate in Sentry Client #2920

wants to merge 27 commits into from

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented May 7, 2025

📜 Description

  • Adds captureLog to SentryClient
  • Adds enableLogs to SentryOptions
  • Adds BeforeSendLogCallback to SentryOptions

💡 Motivation and Context

Relates to #2915
Relates to #2919
Closes #2922

💚 How did you test it?

Unit tests

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

Hub & New Loggers

Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.73%. Comparing base (09f8959) to head (87d52e6).

Files with missing lines Patch % Lines
dart/lib/src/protocol/sentry_log.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           feat/logs    #2920      +/-   ##
=============================================
+ Coverage      87.68%   87.73%   +0.04%     
=============================================
  Files            275      275              
  Lines           9089     9114      +25     
=============================================
+ Hits            7970     7996      +26     
+ Misses          1119     1118       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -8,19 +8,19 @@ class SentryLogAttribute {
return SentryLogAttribute._(value, 'string');
}

factory SentryLogAttribute.boolean(bool value) {
factory SentryLogAttribute.bool(bool value) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this so the name is in line with the dart type.

return SentryLogAttribute._(value, 'boolean');
}

factory SentryLogAttribute.integer(int value) {
factory SentryLogAttribute.int(int value) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this so the name is in line with the dart type.

return SentryLogAttribute._(value, 'integer');
}

factory SentryLogAttribute.double(double value) {
return SentryLogAttribute._(value, 'double');
}

// In the future the SDK will also support string[], boolean[], integer[], double[] values.
// In the future the SDK will also support string[], bool[], int[], double[] values.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this so the name is in line with the dart type.

@denrase denrase changed the title Logs: Integrate in Sentry Client & Hub Logs: Integrate in Sentry Client May 8, 2025
required this.level,
required this.body,
required this.attributes,
this.severityNumber,
});
}) : traceId = traceId ?? SentryId.empty();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The traceId is always set in the client, no point in having it be required in the constr.

@@ -485,6 +485,75 @@ class SentryClient {
);
}

@internal
Future<void> captureLog(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Matched attributes and traceId application as close as i could to the Python implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can also leave parameterize strings out for now

_options.sdk,
);

// TODO: Make sure the Android SDK understands the log envelope type.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a reminder, this was an issue when we introduced feedback. The Native Android SDK would just ignore the envelope because it did not know about the type.

@denrase denrase marked this pull request as ready for review May 8, 2025 08:37
Comment on lines +497 to +502
log.attributes['sentry.sdk.name'] = SentryLogAttribute.string(
_options.sdk.name,
);
log.attributes['sentry.sdk.version'] = SentryLogAttribute.string(
_options.sdk.version,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

do you know if these keys will be used multiple times? if yes we can consider putting them in a constants files or something.

we have a constants.dart in the dart package

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.

2 participants