refactor: extract ApplicationVersion version from sentry
This commit is contained in:
parent
21507cf524
commit
0581c67d6c
3 changed files with 21 additions and 14 deletions
|
@ -339,7 +339,7 @@ class ApplicationController < ActionController::Base
|
||||||
environment: sentry[:environment],
|
environment: sentry[:environment],
|
||||||
browser: { modern: BrowserSupport.supported?(browser) },
|
browser: { modern: BrowserSupport.supported?(browser) },
|
||||||
user: sentry_user,
|
user: sentry_user,
|
||||||
release: SentryRelease.current
|
release: ApplicationVersion.current
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
19
config/initializers/application_version.rb
Normal file
19
config/initializers/application_version.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ApplicationVersion
|
||||||
|
@@current = nil
|
||||||
|
|
||||||
|
# Detect the current release version, which helps Sentry identifying the current release
|
||||||
|
# or can be used as cache key when for some contents susceptible to change between releases.
|
||||||
|
#
|
||||||
|
# The deploy process can write a "version" file at root
|
||||||
|
# containing a string identifying the release, like the sha256 commit used by its release.
|
||||||
|
# It defaults to a random string if the file is not found (so each restart will behave like a new version)
|
||||||
|
def self.current
|
||||||
|
@@current ||= begin
|
||||||
|
version = Rails.root.join('version')
|
||||||
|
version.readable? ? version.read.strip : SecureRandom.hex
|
||||||
|
end
|
||||||
|
@@current.presence
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,15 +1,3 @@
|
||||||
class SentryRelease
|
|
||||||
@@current = nil
|
|
||||||
|
|
||||||
def self.current
|
|
||||||
@@current ||= begin
|
|
||||||
version = Rails.root.join('version')
|
|
||||||
version.readable? ? version.read.strip : ''
|
|
||||||
end
|
|
||||||
@@current.presence
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Sentry.init do |config|
|
Sentry.init do |config|
|
||||||
secrets = Rails.application.secrets.sentry
|
secrets = Rails.application.secrets.sentry
|
||||||
|
|
||||||
|
@ -19,7 +7,7 @@ Sentry.init do |config|
|
||||||
|
|
||||||
config.dsn = secrets[:enabled] ? secrets[:rails_client_key] : nil
|
config.dsn = secrets[:enabled] ? secrets[:rails_client_key] : nil
|
||||||
config.send_default_pii = false
|
config.send_default_pii = false
|
||||||
config.release = SentryRelease.current
|
config.release = ApplicationVersion.current
|
||||||
config.environment = secrets[:environment] || Rails.env
|
config.environment = secrets[:environment] || Rails.env
|
||||||
config.enabled_environments = ['production', secrets[:environment].presence].compact
|
config.enabled_environments = ['production', secrets[:environment].presence].compact
|
||||||
config.breadcrumbs_logger = [:active_support_logger]
|
config.breadcrumbs_logger = [:active_support_logger]
|
||||||
|
|
Loading…
Add table
Reference in a new issue