feat: Add Hint support to beforeSendLog and pass LogRecord from sentry_logging#3549
Draft
feat: Add Hint support to beforeSendLog and pass LogRecord from sentry_logging#3549
beforeSendLog and pass LogRecord from sentry_logging#3549Conversation
…y_logging Adds an optional Hint parameter to BeforeSendLogCallback and threads it through the entire log capture pipeline. The LoggingIntegration now passes the full LogRecord as a hint, allowing users to access the original object in beforeSendLog and derive custom attributes from it — without needing Sentry-specific code at log call sites.
Contributor
|
Collaborator
Author
|
@buenaflor AFAIK, only python SDK offers a hint in the before send log method. |
Contributor
Android Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| cfca825 | 417.36 ms | 393.37 ms | -23.99 ms |
| 51520fc | 351.89 ms | 349.79 ms | -2.10 ms |
| 75284dc | 512.39 ms | 530.87 ms | 18.48 ms |
| a909995 | 383.55 ms | 370.78 ms | -12.77 ms |
| f761369 | 462.73 ms | 563.80 ms | 101.06 ms |
| 575ebaa | 478.00 ms | 585.76 ms | 107.76 ms |
| a5b28db | 383.85 ms | 387.65 ms | 3.80 ms |
| e5b87f8 | 371.22 ms | 377.22 ms | 6.00 ms |
| c8596a6 | 474.00 ms | 492.96 ms | 18.96 ms |
| 79f6b41 | 469.66 ms | 525.90 ms | 56.24 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| cfca825 | 14.09 MiB | 15.28 MiB | 1.19 MiB |
| 51520fc | 13.93 MiB | 15.18 MiB | 1.25 MiB |
| 75284dc | 13.93 MiB | 14.93 MiB | 1.00 MiB |
| a909995 | 14.09 MiB | 15.28 MiB | 1.19 MiB |
| f761369 | 6.54 MiB | 7.70 MiB | 1.16 MiB |
| 575ebaa | 6.54 MiB | 7.69 MiB | 1.15 MiB |
| a5b28db | 13.93 MiB | 15.18 MiB | 1.25 MiB |
| e5b87f8 | 13.93 MiB | 15.18 MiB | 1.25 MiB |
| c8596a6 | 6.54 MiB | 7.53 MiB | 1015.27 KiB |
| 79f6b41 | 6.54 MiB | 7.69 MiB | 1.15 MiB |
Previous results on branch: experiment/sentry-log-logrecord-hint
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b2d0acc | 363.70 ms | 375.81 ms | 12.11 ms |
| dc7f3f0 | 523.94 ms | 510.24 ms | -13.69 ms |
| ebad35e | 444.25 ms | 444.15 ms | -0.10 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b2d0acc | 14.31 MiB | 15.49 MiB | 1.19 MiB |
| dc7f3f0 | 14.31 MiB | 15.49 MiB | 1.19 MiB |
| ebad35e | 14.30 MiB | 15.49 MiB | 1.19 MiB |
Contributor
iOS Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 51520fc | 1253.87 ms | 1254.87 ms | 1.00 ms |
| 0e2b9b0 | 1248.69 ms | 1252.22 ms | 3.54 ms |
| c8596a6 | 1234.11 ms | 1241.19 ms | 7.08 ms |
| bfabaf2 | 1251.72 ms | 1253.38 ms | 1.67 ms |
| 29e8ebe | 1260.46 ms | 1262.60 ms | 2.14 ms |
| 1777727 | 1249.21 ms | 1258.40 ms | 9.18 ms |
| 6b69699 | 1254.80 ms | 1273.31 ms | 18.52 ms |
| e3f3ea1 | 1262.83 ms | 1264.83 ms | 1.99 ms |
| 827bf09 | 1261.86 ms | 1276.41 ms | 14.55 ms |
| 944b773 | 1252.82 ms | 1254.08 ms | 1.27 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 51520fc | 5.53 MiB | 5.96 MiB | 443.39 KiB |
| 0e2b9b0 | 5.73 MiB | 6.17 MiB | 453.79 KiB |
| c8596a6 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| bfabaf2 | 5.53 MiB | 6.01 MiB | 487.95 KiB |
| 29e8ebe | 5.53 MiB | 6.01 MiB | 488.12 KiB |
| 1777727 | 5.73 MiB | 6.17 MiB | 453.78 KiB |
| 6b69699 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| e3f3ea1 | 5.53 MiB | 5.96 MiB | 443.28 KiB |
| 827bf09 | 7.86 MiB | 9.44 MiB | 1.58 MiB |
| 944b773 | 5.53 MiB | 6.00 MiB | 479.98 KiB |
Previous results on branch: experiment/sentry-log-logrecord-hint
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b2d0acc | 1253.42 ms | 1258.98 ms | 5.56 ms |
| dc7f3f0 | 1242.31 ms | 1252.91 ms | 10.60 ms |
| ebad35e | 1267.47 ms | 1265.63 ms | -1.84 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b2d0acc | 5.73 MiB | 6.17 MiB | 455.45 KiB |
| dc7f3f0 | 5.73 MiB | 6.17 MiB | 455.48 KiB |
| ebad35e | 5.73 MiB | 6.17 MiB | 453.79 KiB |
buenaflor
reviewed
Mar 25, 2026
| 'sentry.origin': SentryAttribute.string(origin), | ||
| }; | ||
|
|
||
| final hint = Hint.withMap({TypeCheckHint.record: record}); |
Contributor
There was a problem hiding this comment.
We can consider making this more convenient and easy to discover for users.
something like hint.logging.record
logging -> refers to the logging integration / package
record -> give me the record associated with this log if there is one
/// Logging-specific hint data.
class LoggingHintData {
final Hint _hint;
LoggingHintData(this._hint);
/// The original [LogRecord] from the `logging` package, if this
/// log originated from [LoggingIntegration].
LogRecord? get record => _hint.get(TypeCheckHint.record) as LogRecord?;
}
extension SentryLoggingHint on Hint {
/// Access logging-specific hint data.
LoggingHintData get logging => LoggingHintData(this);
}But this is just suggestion, we don't have to do this but I think it would be nice to have.
Collaborator
Author
There was a problem hiding this comment.
Great idea, since this is in the logging package and the pattern is not used elsewhere, i added it directly to hint as an extension.
Sentry Build Distribution
|
Contributor
|
Converting this back to draft until we get an idea on the usage of beforeSend(log) |
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.
📜 Description
Adds an optional Hint parameter to BeforeSendLogCallback and threads it through the entire log capture pipeline. The LoggingIntegration now passes the full LogRecord as a hint, allowing users to access the original object in beforeSendLog and derive custom attributes from it — without needing Sentry-specific code at log call sites.
💡 Motivation and Context
For now this in only an exploration of a possible solution to #3527
💚 How did you test it?
📝 Checklist
sendDefaultPiiis enabled🔮 Next steps
This is a breaking change and should be part of a major version.