Skip to content

Conversation

@solnic
Copy link
Collaborator

@solnic solnic commented May 7, 2025

This replaces previous internal Sentry.logger with a public-facing logger that supports structured logging and sending log events to Sentry via Sentry.capture_log API.

Sample config

require "sentry-ruby"

# Initialize Sentry with experimental logging feature enabled
Sentry.init do |config|
  config.dsn = "https://..."
  config.environment = "development"
  config.debug = true
  config.max_log_events = 3

  # Set this to enable structured logging via Sentry.logger
  config.enable_logs = true
end

puts "Testing logging with attributes..."

Sentry.logger.info("User logged in", user_id: 123, action: "login", success: true)

puts "Testing different log levels..."

Sentry.logger.debug("Debug message")
Sentry.logger.info("Info message")
Sentry.logger.warn("Warning message")
Sentry.logger.error("Error message")
Sentry.logger.fatal("Fatal message")

puts "Testing with message templates..."

Sentry.logger.info("Hello %s!", ["World"], extra: "super useful info")

puts "Flushing..."

Sentry.get_current_client.flush

puts "Done!"

Sample results in the UI

Screenshot 2025-05-07 at 13 39 15

Log event with a message template

Positioned parameters

Screenshot 2025-05-08 at 15 37 06

Hash-based parameters

Screenshot 2025-05-09 at 15 21 16

Closes #2604

@solnic solnic linked an issue May 7, 2025 that may be closed by this pull request
@solnic solnic force-pushed the 2604-introduce-a-new-sentrylogger-interface branch 6 times, most recently from 3843c19 to d7546d2 Compare May 7, 2025 12:03
@solnic solnic marked this pull request as ready for review May 7, 2025 12:05
@solnic solnic force-pushed the 2604-introduce-a-new-sentrylogger-interface branch 2 times, most recently from 1468907 to f887ca7 Compare May 9, 2025 12:36
@solnic solnic marked this pull request as draft May 12, 2025 14:10
@solnic solnic force-pushed the 2604-introduce-a-new-sentrylogger-interface branch from 16980a7 to 13863bc Compare May 13, 2025 09:57
@solnic solnic force-pushed the 2604-introduce-a-new-sentrylogger-interface branch from 0692e1a to d879a8b Compare May 13, 2025 10:11
@solnic solnic marked this pull request as ready for review May 13, 2025 10:11
@solnic
Copy link
Collaborator Author

solnic commented May 13, 2025

@sl0thentr0py this is ready for review. Please ignore ruby-head failed builds.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

some minor comments

end
end

TOKEN_REGEXP = /%\{(\w+)\}/
Copy link
Member

Choose a reason for hiding this comment

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

we should have a clear note in docs that our templates are expected to be like

"This is a template with a %{var}"

and not what ruby people are used to

"This is a template with a #{var}"

@solnic solnic requested a review from sl0thentr0py May 13, 2025 13:11
Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

:shipit:

end
else
parameters.each_with_index do |param, index|
attributes["sentry.message.parameters.#{index}"] = param
Copy link
Member

@sl0thentr0py sl0thentr0py May 13, 2025

Choose a reason for hiding this comment

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

they just changed this to sentry.message.parameter
see getsentry/sentry-python#4387

Copy link
Member

Choose a reason for hiding this comment

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

something something hardest problem in computer science

@solnic solnic requested a review from sl0thentr0py May 13, 2025 14:12
@solnic solnic merged commit b9fc537 into master May 13, 2025
134 of 138 checks passed
@solnic solnic deleted the 2604-introduce-a-new-sentrylogger-interface branch May 13, 2025 14:21
@erickreutz
Copy link

Do you guys plan to support log drains? https://devcenter.heroku.com/articles/log-drains

Trying to understand how Sentry.logger is intended to be used? Along side something like Rails.logger or as a replacement?

@AbhiPrasad
Copy link
Member

Hey @erickreutz thanks for your interest!

Trying to understand how Sentry.logger is intended to be used? Along side something like Rails.logger or as a replacement?

We have docs for logging in Ruby here: https://docs.sentry.io/platforms/ruby/logs/. If you want more details about logs in Sentry, see our product docs: https://docs.sentry.io/product/explore/logs

We don't have Rails/ActiveSupport support just yet, this is being tracked by this GH issue: #2605. If there's something you'd like to see, please leave a reply!

Do you guys plan to support log drains? https://devcenter.heroku.com/articles/log-drains

Not at the current moment, we are prioritizing getting logging working via our SDKs (so that you can connect your logs and traces together automatically). We're tracking Heroku support in this GH issue: getsentry/sentry#91727. Please leave a comment about your use case, that will help us prioritize this!

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.

Introduce a new Sentry.logger interface

5 participants