Class: Contrast::Agent::Telemetry::StartupMetricsEvent

Inherits:
MetricEvent show all
Defined in:
lib/contrast/agent/telemetry/startup_metrics_event.rb

Overview

This class will hold the Startup Metrics Telemetry Event The class will include initialization of the agent version, language version os type, arch and version application framework and version and server framework It will be initialized and send in Middleware#agent_startup_routine

Constant Summary collapse

APP_AND_SERVER_DATA =
::Contrast::APP_CONTEXT.app_and_server_information.cs__freeze
SAAS_DEFAULT =

Multi-tenant Production Environments

{ addr: 'app.contrastsecurity.com', type: 'SAAS_DEFAULT' }.cs__freeze
SAAS_CS =
{ addr: /cs[[:digit:]]+\.contrastsecurity\.com/, type: 'SAAS_DEFAULT' }.cs__freeze
SAAS_JP =
{ addr: 'app.contrastsecurity.jp', type: 'SAAS_DEFAULT' }.cs__freeze
SAAS_CE =
{ addr: 'ce.contrastsecurity.com', type: 'SAAS_CE' }.cs__freeze
SAAS_DEMO =

Multi-tenant Demo Environments

{ addr: 'apptwo.contrastsecurity.com', type: 'SAAS_DEMO' }.cs__freeze
SAAS_POV =
{ addr: 'eval.contrastsecurity.com', type: 'SAAS_POV' }.cs__freeze
SAAS_RESEARCH =

Multi-tenant Testing Environment

{ addr: 'security-research.contrastsecurity.com', type: 'SAAS_RESEARCH' }.cs__freeze
SAAS_ALPHA =
{ addr: 'alpha.contrastsecurity.com', type: 'SAAS_ALPHA' }.cs__freeze
SAAS_STAGING =
{ addr: 'teamserver-staging.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
SAAS_STAGING_TOKYO =
{ addr: 'teamserver-staging.contsec.jp', type: 'SAAS_TESTING' }.cs__freeze
SAAS_TESTING =
{ addr: 'teamserver-darpa.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
SAAS_OPS_TESTING =
{ addr: 'teamserver-ops.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
SAAS_CUSTOM =

Fallback for Single-tenant Production Environments

{ addr: 'contrastsecurity.com', type: 'SAAS_CUSTOM' }.cs__freeze
SAAS_CUSTOM_JP =
{ addr: 'contrastsecurity.jp', type: 'SAAS_CUSTOM' }.cs__freeze
SINGLE_MAP_TENANTS =
[
  SAAS_DEFAULT, SAAS_JP, SAAS_CE, SAAS_DEMO, SAAS_POV, SAAS_RESEARCH, SAAS_ALPHA,
  SAAS_STAGING, SAAS_STAGING_TOKYO, SAAS_TESTING, SAAS_OPS_TESTING
].cs__freeze
REGEXP_MAP_TENANTS =
[SAAS_CS].cs__freeze
FALLBACK_TENANTS =
[SAAS_CUSTOM, SAAS_CUSTOM_JP].cs__freeze
EOP =

Fallback for Custom, most likely self-hosted, Environments

'EOP'
REJECTED_VALUES =
[nil, 'NEEDS_TO_BE_SET', Contrast::Utils::ObjectShare::EMPTY_STRING].cs__freeze

Instance Attribute Summary

Attributes inherited from MetricEvent

#fields

Attributes inherited from Event

#tags

Instance Method Summary collapse

Methods inherited from MetricEvent

#empty?, #sys_info, #to_controlled_hash

Methods included from Utils::OS

get_system_information, mac?, windows?

Methods included from Components::Scope::InstanceMethods

#contrast_enter_method_scopes!, #contrast_exit_method_scopes!, #with_app_scope, #with_contrast_scope, #with_deserialization_scope, #with_split_scope

Methods inherited from Event

#to_controlled_hash

Constructor Details

#initializeStartupMetricsEvent

Returns a new instance of StartupMetricsEvent.



47
48
49
50
51
52
53
54
# File 'lib/contrast/agent/telemetry/startup_metrics_event.rb', line 47

def initialize
  super
  @settings = []
  add_config_keys(::Contrast::CONFIG.config, 'root')
  @settings << ENV.keys.select { |v| v.start_with?('CONTRAST') }
  @settings.flatten
  add_tags
end

Instance Method Details

#add_config_keys(config, nested_key) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/contrast/agent/telemetry/startup_metrics_event.rb', line 69

def add_config_keys config, nested_key
  config.to_contrast_hash.reject! { |_k, v| REJECTED_VALUES.include?(v) }

  config.to_contrast_hash.each do |k, v|
    unless v.cs__class <= Contrast::Config::BaseConfiguration
      @settings << "#{ nested_key }.#{ k }"
      next
    end

    add_config_keys(v, "#{ nested_key }.#{ k }")
  end
end

#add_tagsObject



60
61
62
63
64
65
66
67
# File 'lib/contrast/agent/telemetry/startup_metrics_event.rb', line 60

def add_tags
  add_system_tags
  @tags['app_framework_and_version'] = APP_AND_SERVER_DATA[:application_info].to_s
  @tags['server_framework_and_version'] = APP_AND_SERVER_DATA[:server_info].to_s
  @tags['ASSESS'] = Contrast::ASSESS.enabled?.to_s
  @tags['PROTECT'] = Contrast::PROTECT.enabled?.to_s
  @tags['settings'] = @settings.join(',')
end

#pathObject



56
57
58
# File 'lib/contrast/agent/telemetry/startup_metrics_event.rb', line 56

def path
  '/startup'
end