Skip to content

String templating for structured logs #3002

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 14 commits into from
Jun 25, 2025
Merged

String templating for structured logs #3002

merged 14 commits into from
Jun 25, 2025

Conversation

denrase
Copy link
Collaborator

@denrase denrase commented Jun 23, 2025

📜 Description

// A simple template string

Sentry.logger.fmt.warn(
  "Hey %s, how was your vacation in %s? %s days, was it?", 
  ["John", "France", 7],
);

// The same if using the `standard` API in Dart

Sentry.logger.warn(
  "Hey John, how was your vacation in France? 7 days, was it?",
  attributes: {
    'sentry.message.template': SentryLogAttribute.string(
      'Hey %s, how was your vacation in %s? %s days, was it?',
    ),
    'sentry.message.parameter.0': SentryLogAttribute.string('John'),
    'sentry.message.parameter.1': SentryLogAttribute.string('France'),
    'sentry.message.parameter.2': SentryLogAttribute.int(7),
  },
);

💡 Motivation and Context

Closes #2938

💚 How did you test it?

📝 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

I'd need some feedback if the API is the way to go. Here are several alternatives:

  • Sentry.logger.fmt.warn("Foo %s", ["bar"]) How its now.
  • SentryLogger.warnFormatted("Foo %s", ["bar"])
  • SentryLogger.warn(SentryFormattedString("Foo %s", ["bar"])

Copy link
Contributor

github-actions bot commented Jun 23, 2025

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

Generated by 🚫 dangerJS against f0d7b87

Copy link

codecov bot commented Jun 23, 2025

Codecov Report

Attention: Patch coverage is 95.08197% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.71%. Comparing base (81da2d7) to head (f0d7b87).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dart/lib/src/sentry_logger_formatter.dart 93.75% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3002      +/-   ##
==========================================
+ Coverage   87.68%   87.71%   +0.02%     
==========================================
  Files         284      286       +2     
  Lines        9267     9328      +61     
==========================================
+ Hits         8126     8182      +56     
- Misses       1141     1146       +5     

☔ 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.

Copy link
Contributor

github-actions bot commented Jun 23, 2025

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 437.62 ms 505.52 ms 67.90 ms
Size 6.54 MiB 7.53 MiB 1016.34 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c73ab67 353.82 ms 408.71 ms 54.90 ms
e66e71e 296.84 ms 345.43 ms 48.59 ms
1c926c2 424.57 ms 493.89 ms 69.32 ms
a817b8f 383.02 ms 445.17 ms 62.15 ms
8a10ab7 436.20 ms 509.43 ms 73.23 ms
ef31c7f 311.39 ms 359.33 ms 47.94 ms
2966d88 365.71 ms 422.50 ms 56.79 ms
134c9f8 301.40 ms 352.65 ms 51.26 ms
9fe67d5 373.80 ms 444.24 ms 70.45 ms
ee0ca56 355.35 ms 421.13 ms 65.78 ms

App size

Revision Plain With Sentry Diff
c73ab67 6.15 MiB 7.13 MiB 999.97 KiB
e66e71e 6.06 MiB 7.09 MiB 1.03 MiB
1c926c2 6.46 MiB 7.48 MiB 1.03 MiB
a817b8f 6.16 MiB 7.14 MiB 1003.22 KiB
8a10ab7 6.27 MiB 7.20 MiB 958.60 KiB
ef31c7f 6.06 MiB 7.09 MiB 1.03 MiB
2966d88 6.33 MiB 7.27 MiB 954.11 KiB
134c9f8 5.94 MiB 6.95 MiB 1.01 MiB
9fe67d5 6.33 MiB 7.29 MiB 987.27 KiB
ee0ca56 6.33 MiB 7.30 MiB 992.52 KiB

Previous results on branch: feat/logs-templating

Startup times

Revision Plain With Sentry Diff
b25f7b1 489.30 ms 556.44 ms 67.14 ms
e027314 487.91 ms 536.74 ms 48.83 ms
65e2736 503.46 ms 520.82 ms 17.36 ms
f6b686c 463.16 ms 489.04 ms 25.88 ms
3217850 511.16 ms 552.23 ms 41.07 ms
893e0ae 517.41 ms 656.36 ms 138.94 ms

App size

Revision Plain With Sentry Diff
b25f7b1 6.54 MiB 7.53 MiB 1017.18 KiB
e027314 6.54 MiB 7.53 MiB 1017.18 KiB
65e2736 6.54 MiB 7.53 MiB 1017.21 KiB
f6b686c 6.54 MiB 7.53 MiB 1017.18 KiB
3217850 6.54 MiB 7.53 MiB 1017.21 KiB
893e0ae 6.54 MiB 7.53 MiB 1017.18 KiB

Copy link
Contributor

github-actions bot commented Jun 23, 2025

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1235.76 ms 1260.37 ms 24.61 ms
Size 7.85 MiB 9.45 MiB 1.59 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
9ed26e6 1263.84 ms 1281.04 ms 17.20 ms
1d47eb7 1212.57 ms 1222.00 ms 9.43 ms
d883d62 1221.39 ms 1230.18 ms 8.80 ms
117d988 1200.83 ms 1223.24 ms 22.41 ms
6f3717a 1259.84 ms 1280.90 ms 21.06 ms
6e9c5a2 1245.59 ms 1260.24 ms 14.65 ms
bd69c1b 1258.09 ms 1282.46 ms 24.37 ms
d189e01 1219.94 ms 1228.20 ms 8.27 ms
fbf42af 1253.76 ms 1269.51 ms 15.76 ms
4829ad3 1260.14 ms 1264.41 ms 4.27 ms

App size

Revision Plain With Sentry Diff
9ed26e6 8.42 MiB 9.89 MiB 1.46 MiB
1d47eb7 8.29 MiB 9.39 MiB 1.09 MiB
d883d62 8.29 MiB 9.36 MiB 1.07 MiB
117d988 8.32 MiB 9.38 MiB 1.05 MiB
6f3717a 8.33 MiB 9.62 MiB 1.29 MiB
6e9c5a2 8.34 MiB 9.66 MiB 1.31 MiB
bd69c1b 8.43 MiB 9.98 MiB 1.55 MiB
d189e01 8.29 MiB 9.38 MiB 1.09 MiB
fbf42af 8.16 MiB 9.17 MiB 1.01 MiB
4829ad3 8.32 MiB 9.38 MiB 1.05 MiB

Previous results on branch: feat/logs-templating

Startup times

Revision Plain With Sentry Diff
e027314 1234.81 ms 1265.90 ms 31.09 ms
b25f7b1 1259.63 ms 1277.52 ms 17.90 ms
f6b686c 1259.16 ms 1269.63 ms 10.47 ms
3217850 1265.24 ms 1273.76 ms 8.51 ms
893e0ae 1254.76 ms 1265.90 ms 11.14 ms
65e2736 1263.53 ms 1287.79 ms 24.26 ms

App size

Revision Plain With Sentry Diff
e027314 7.85 MiB 9.45 MiB 1.59 MiB
b25f7b1 7.85 MiB 9.45 MiB 1.59 MiB
f6b686c 7.85 MiB 9.45 MiB 1.59 MiB
3217850 7.85 MiB 9.45 MiB 1.59 MiB
893e0ae 7.85 MiB 9.45 MiB 1.59 MiB
65e2736 7.85 MiB 9.45 MiB 1.59 MiB

@denrase denrase changed the title Add templating for logs String templating for structured logs Jun 23, 2025
@denrase denrase marked this pull request as ready for review June 24, 2025 07:43
@denrase denrase requested a review from stefanosiano as a code owner June 24, 2025 07:43
@denrase denrase requested a review from buenaflor June 24, 2025 07:43
@denrase denrase requested a review from buenaflor June 24, 2025 13:39
@denrase denrase requested a review from buenaflor June 25, 2025 06:53
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.

lgtm!

@denrase denrase merged commit 6ea1f55 into main Jun 25, 2025
158 checks passed
@denrase denrase deleted the feat/logs-templating branch June 25, 2025 10:37
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.

String templating for structured logs
2 participants