Class: Contrast::Components::AppContext::Interface

Inherits:
Object
  • Object
show all
Includes:
Contrast::Components::AppContextExtend, ComponentBase, Contrast::Config::BaseConfiguration
Defined in:
lib/contrast/components/app_context.rb

Overview

A wrapper build around the Common Agent Configuration project to allow for access of the values contained in its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the Application, including the Client, Process, and Server information.

Constant Summary collapse

DEFAULT_APP_NAME =
'rails'
DEFAULT_APP_PATH =
'/'
DEFAULT_SERVER_NAME =
'localhost'
DEFAULT_SERVER_PATH =
'/'
CANON_NAME =
'application'
CONFIG_VALUES =
%w[name version language path group tags code metadata session_id session_metadata].cs__freeze

Constants included from Contrast::Config::BaseConfiguration

Contrast::Config::BaseConfiguration::AT_UNDERSCORE

Constants included from ComponentBase

ComponentBase::ENABLE

Constants included from Contrast::Config::Diagnostics::Tools

Contrast::Config::Diagnostics::Tools::CHECK

Constants included from Contrast::Config::Diagnostics::SingletonTools

Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK

Constants included from Contrast::Components::AppContextExtend

Contrast::Components::AppContextExtend::SUPPORTED_FRAMEWORKS, Contrast::Components::AppContextExtend::SUPPORTED_SERVERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Contrast::Config::BaseConfiguration

#to_contrast_hash

Methods included from ComponentBase

#false?, #file_exists?, #stringify_array, #true?, #valid_cert?

Methods included from Contrast::Config::Diagnostics::Tools

#add_effective_config_values, #add_single_effective_value

Methods included from Contrast::Config::Diagnostics::SingletonTools

#flatten_settings, #to_config_values, #update_config, #value_to_s

Methods included from Contrast::Components::AppContextExtend

#app_and_server_information, #disabled_agent_rake_tasks, #find_gem_information, #instrument_middleware_stack?, #pid, #ppid

Constructor Details

#initialize(hsh = {}) ⇒ Interface

Returns a new instance of Interface.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/contrast/components/app_context.rb', line 45

def initialize hsh = {}
  original_pid
  @config_values = CONFIG_VALUES
  @canon_name = CANON_NAME
  return unless hsh

  @_name = hsh[:name]
  @version = hsh[:version]
  @language = hsh[:language]
  @_path = hsh[:path]
  @group = hsh[:group]
  @tags = hsh[:tags]
  @code = hsh[:code]
  @metadata = hsh[:metadata]
  @_session_id = hsh[:session_id]
  @_session_metadata = hsh[:session_metadata]
end

Instance Attribute Details

#canon_nameString (readonly)

Returns:



41
42
43
# File 'lib/contrast/components/app_context.rb', line 41

def canon_name
  @canon_name
end

#codeString

Returns:



37
38
39
# File 'lib/contrast/components/app_context.rb', line 37

def code
  @code
end

#config_valuesArray (readonly)

Returns:

  • (Array)


43
44
45
# File 'lib/contrast/components/app_context.rb', line 43

def config_values
  @config_values
end

#groupString

Returns:



34
35
36
# File 'lib/contrast/components/app_context.rb', line 34

def group
  @group
end

#languageString

Returns:



32
33
34
# File 'lib/contrast/components/app_context.rb', line 32

def language
  @language
end

#metadataString

Returns:



39
40
41
# File 'lib/contrast/components/app_context.rb', line 39

def 
  @metadata
end

#tagsObject



145
146
147
# File 'lib/contrast/components/app_context.rb', line 145

def tags
  stringify_array(@tags)
end

#versionString

Returns:



30
31
32
# File 'lib/contrast/components/app_context.rb', line 30

def version
  @version
end

Instance Method Details

#in_new_process?Boolean

Determines if the Process we’re currently in matches that of the Process in which the App Context instance was created. If it doesn’t, that indicates the running context is in a new Process.

Returns:

  • (Boolean)

    if we’re in the original Process in which the App Context instance was initialized.



155
156
157
158
159
# File 'lib/contrast/components/app_context.rb', line 155

def in_new_process?
  current_pid = Process.pid
  original_pid = pid
  current_pid != original_pid
end

#nameObject



97
98
99
100
101
102
103
104
105
# File 'lib/contrast/components/app_context.rb', line 97

def name
  @_name ||= begin
    tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
    tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
    Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
  rescue StandardError
    DEFAULT_APP_NAME
  end
end

#name=(app_name) ⇒ String

Set application name

Parameters:

  • app_name (String)

    application name

Returns:



111
112
113
# File 'lib/contrast/components/app_context.rb', line 111

def name= app_name
  @_name = app_name
end

#pathObject



115
116
117
118
119
120
121
122
# File 'lib/contrast/components/app_context.rb', line 115

def path
  @_path ||= begin
    tmp = Contrast::Agent.framework_manager.application_root unless Contrast::Utils::StringUtils.present?(tmp)
    Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
  rescue StandardError
    DEFAULT_APP_PATH
  end
end

#server_nameObject



124
125
126
127
128
129
130
131
132
133
# File 'lib/contrast/components/app_context.rb', line 124

def server_name
  @_server_name ||= begin
    tmp = ::Contrast::CONFIG.server.name # rubocop:disable Security/Module/Name
    tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
    tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
    Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
  rescue StandardError
    DEFAULT_SERVER_NAME
  end
end

#server_pathObject



135
136
137
138
139
140
141
142
143
# File 'lib/contrast/components/app_context.rb', line 135

def server_path
  @_server_path ||= begin
    tmp = ::Contrast::CONFIG.server.path
    tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
    Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
  rescue StandardError
    DEFAULT_SERVER_PATH
  end
end

#server_typeObject



89
90
91
92
93
94
95
# File 'lib/contrast/components/app_context.rb', line 89

def server_type
  @_server_type ||= begin
    tmp = ::Contrast::CONFIG.server.type
    tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
    tmp
  end
end

#session_idString, Contrast::Utils::ObjectShare::EMPTY_STRING



64
65
66
# File 'lib/contrast/components/app_context.rb', line 64

def session_id
  @_session_id ||= Contrast::Utils::ObjectShare::EMPTY_STRING
end

#session_id=(id) ⇒ String

Set session_id

Parameters:

Returns:



72
73
74
# File 'lib/contrast/components/app_context.rb', line 72

def session_id= id
  @_session_id = id
end

#session_metadataString, Contrast::Utils::ObjectShare::EMPTY_STRING



77
78
79
# File 'lib/contrast/components/app_context.rb', line 77

def 
  @_session_metadata ||= Contrast::Utils::ObjectShare::EMPTY_STRING
end

#session_metadata=(meta) ⇒ String

Set session_metadata

Parameters:

Returns:



85
86
87
# File 'lib/contrast/components/app_context.rb', line 85

def session_metadata= meta
  @_session_metadata = meta
end

#to_effective_config(effective_config) ⇒ Object

Converts current configuration to effective config values class and appends them to EffectiveConfig class.

Parameters:



165
166
167
168
# File 'lib/contrast/components/app_context.rb', line 165

def to_effective_config effective_config
  super
  Contrast::CONFIG.server.to_effective_config(effective_config)
end