Method: Logtail::Contexts::Release.from_env

Defined in:
lib/logtail/contexts/release.rb

.from_envObject

Builds a release context based on environment variables. Simply add the RELEASE_COMMIT, RELEASE_CREATED_AT, or the RELEASE_VERSION env vars to get this context automatially. All are optional, but at least one must be present.

If you’re on Heroku, simply enable dyno metadata to get this automatically: devcenter.heroku.com/articles/dyno-metadata



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/logtail/contexts/release.rb', line 17

def from_env
  commit_hash = ENV['RELEASE_COMMIT'] || ENV['HEROKU_SLUG_COMMIT']
  created_at = ENV['RELEASE_CREATED_AT'] || ENV['HEROKU_RELEASE_CREATED_AT']
  version = ENV['RELEASE_VERSION'] || ENV['HEROKU_RELEASE_VERSION']

  if commit_hash || created_at || version
    Logtail::Config.instance.debug { "Release env vars detected, adding to context" }
    new(commit_hash: commit_hash, created_at: created_at, version: version)
  else
    Logtail::Config.instance.debug { "Release env vars _not_ detected" }
    nil
  end
end