Module: Contrast::Agent::Telemetry::Identifier
- Defined in:
- lib/contrast/agent/telemetry/identifier.rb
Overview
Gets info about the instrumented application required to build unique identifiers, used in the agent’s Telemetry.
Constant Summary collapse
- MAC_REGEXP =
/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.cs__freeze
- LINUX_OS_REG =
/hwaddr=.*?(([A-F0-9]{2}:){5}[A-F0-9]{2})/im.cs__freeze
- MAC_OS_PRIMARY =
'en0'.cs__freeze
- LINUX_PRIMARY =
'enp'.cs__freeze
Class Method Summary collapse
-
.app_name ⇒ Object
Sinatra and Grape both use similar approach to identify the app_name.
-
.application_id ⇒ String
Set and return a Sha256 hash representing this application, based on the mac identifier of this machine and the application name or a Secure UUID if one of them cannot be determined.
-
.instance_id ⇒ String
Set and return a Sha256 hash representing this agent run, based on the mac identifier of this machine or a Secure UUID if one cannot be determined.
-
.mac ⇒ String?
Returns the MAC address of the primary network interface, depending on the used OS.
Class Method Details
.app_name ⇒ Object
Sinatra and Grape both use similar approach to identify the app_name. Rails has a different way of doing it, but to unify this we’ll use this one. If app_name is changed/renamed during production it would still get the new folder’s name.
@ return [String] name of the application from the current working directory
26 27 28 |
# File 'lib/contrast/agent/telemetry/identifier.rb', line 26 def self.app_name @_app_name ||= File.basename(Dir.pwd) end |
.application_id ⇒ String
Set and return a Sha256 hash representing this application, based on the mac identifier of this machine and the application name or a Secure UUID if one of them cannot be determined.
45 46 47 48 49 50 51 52 53 |
# File 'lib/contrast/agent/telemetry/identifier.rb', line 45 def self.application_id @_application_id ||= begin id = nil mac = Contrast::Agent::Telemetry::Identifier.mac app_name = Contrast::Agent::Telemetry::Identifier.app_name id = mac + app_name if mac && app_name Digest::SHA2.new(256).hexdigest(id || "_#{ SecureRandom.uuid }") end end |
.instance_id ⇒ String
Set and return a Sha256 hash representing this agent run, based on the mac identifier of this machine or a Secure UUID if one cannot be determined.
59 60 61 62 |
# File 'lib/contrast/agent/telemetry/identifier.rb', line 59 def self.instance_id @_instance_id ||= Digest::SHA2.new(256).hexdigest(Contrast::Agent::Telemetry::Identifier.mac || "_#{ SecureRandom.uuid }") end |
.mac ⇒ String?
Returns the MAC address of the primary network interface, depending on the used OS. If the primary is unknown it finds the first available network interface and gets it’s MAC address instead.
the first available one, or nil if nothing found
36 37 38 39 |
# File 'lib/contrast/agent/telemetry/identifier.rb', line 36 def self.mac primary = Contrast::Utils::OS.mac? ? MAC_OS_PRIMARY : LINUX_PRIMARY @_mac = find_mac(primary) || find_mac end |