Skip to content

feat: Add Hint support to beforeSendLog and pass LogRecord from sentry_logging#3549

Draft
denrase wants to merge 7 commits intomainfrom
experiment/sentry-log-logrecord-hint
Draft

feat: Add Hint support to beforeSendLog and pass LogRecord from sentry_logging#3549
denrase wants to merge 7 commits intomainfrom
experiment/sentry-log-logrecord-hint

Conversation

@denrase
Copy link
Copy Markdown
Collaborator

@denrase denrase commented Mar 10, 2026

📜 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?

  • Added 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

This is a breaking change and should be part of a major version.

…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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

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

Generated by 🚫 dangerJS against f4ab192

@denrase
Copy link
Copy Markdown
Collaborator Author

denrase commented Mar 10, 2026

@buenaflor AFAIK, only python SDK offers a hint in the before send log method.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 380.39 ms 379.26 ms -1.13 ms
Size 14.31 MiB 15.49 MiB 1.19 MiB

Baseline results on branch: main

Startup times

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1264.11 ms 1247.00 ms -17.11 ms
Size 5.73 MiB 6.17 MiB 455.48 KiB

Baseline results on branch: main

Startup times

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

'sentry.origin': SentryAttribute.string(origin),
};

final hint = Hint.withMap({TypeCheckHint.record: record});
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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

sentry bot commented Mar 27, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
sentry_flutter_example io.sentry.flutter.sample 9.16.0 (1) Release Install Build

@denrase denrase marked this pull request as ready for review March 27, 2026 13:27
@buenaflor buenaflor marked this pull request as draft March 30, 2026 10:42
@buenaflor
Copy link
Copy Markdown
Contributor

Converting this back to draft until we get an idea on the usage of beforeSend(log)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants