Sha256: 57d4c850458eb7232dcd079a58148213fc880402e5bec61d2993a6ca818c83ce
Contents?: true
Size: 1.8 KB
Versions: 18
Compression:
Stored size: 1.8 KB
Contents
require "logtail/config" require "logtail/context" require "logtail/util" module Logtail module Contexts # @private class Release < Context class << self # 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: # https://devcenter.heroku.com/articles/dyno-metadata 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 end attr_reader :commit_hash, :created_at, :version def initialize(attributes) @commit_hash = attributes[:commit_hash] @created_at = attributes[:created_at] @version = attributes[:version] end # Builds a hash representation containing simple objects, suitable for serialization (JSON). def to_hash @to_hash ||= { release: Util::NonNilHashBuilder.build do |h| h.add(:commit_hash, commit_hash) h.add(:created_at, created_at) h.add(:version, version) end } end end end end
Version data entries
18 entries across 18 versions & 2 rubygems