Class: Contrast::Components::AppContext::Interface
- Includes:
- ComponentBase, Interface
- 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 =
'/'
Instance Method Summary collapse
- #build_agent_startup_message ⇒ Object
- #build_app_startup_message ⇒ Object
- #client_id ⇒ Object
- #disabled_agent_rake_tasks ⇒ Object
-
#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.
-
#initialize ⇒ Interface
constructor
A new instance of Interface.
- #instrument_middleware_stack? ⇒ Boolean
- #name ⇒ Object
- #path ⇒ Object
- #pgid ⇒ Object
- #pid ⇒ Object
- #ppid ⇒ Object
- #server_name ⇒ Object
- #server_path ⇒ Object
- #server_type ⇒ Object
Methods included from Interface
Methods included from ComponentBase
Constructor Details
#initialize ⇒ Interface
Returns a new instance of Interface.
26 27 28 |
# File 'lib/contrast/components/app_context.rb', line 26 def initialize original_pid end |
Instance Method Details
#build_agent_startup_message ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/contrast/components/app_context.rb', line 93 def msg = Contrast::Api::Dtm::AgentStartup.new msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type msg.server_version = Contrast::Agent::VERSION msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment msg. = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server. msg. = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application. msg. = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory. msg. = Contrast::Utils::StringUtils.protobuf_format ASSESS. logger.info('Application context', server_name: msg.server_name, server_path: msg.server_path, server_type: msg.server_type, application_name: name, application_path: path, application_language: Contrast::Utils::ObjectShare::RUBY) msg end |
#build_app_startup_message ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/contrast/components/app_context.rb', line 79 def msg = Contrast::Api::Dtm::ApplicationCreate.new msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code msg. = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application. # Other fields have limits in TeamServer, the rest don't. msg.session_id = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_id, truncate: false msg. = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application., truncate: false msg end |
#client_id ⇒ Object
128 129 130 |
# File 'lib/contrast/components/app_context.rb', line 128 def client_id @_client_id ||= [name, pgid].join('-') end |
#disabled_agent_rake_tasks ⇒ Object
136 137 138 |
# File 'lib/contrast/components/app_context.rb', line 136 def disabled_agent_rake_tasks CONFIG.root.agent.ruby.disabled_agent_rake_tasks end |
#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.
146 147 148 149 150 |
# File 'lib/contrast/components/app_context.rb', line 146 def in_new_process? current_pid = Process.pid original_pid = pid current_pid != original_pid end |
#instrument_middleware_stack? ⇒ Boolean
132 133 134 |
# File 'lib/contrast/components/app_context.rb', line 132 def instrument_middleware_stack? !Contrast::Utils::JobServersRunning.job_servers_running? end |
#name ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/contrast/components/app_context.rb', line 38 def name @_name ||= begin tmp = CONFIG.root.application.name 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 |
#path ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/contrast/components/app_context.rb', line 49 def path @_path ||= begin tmp = CONFIG.root.application.path Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH) rescue StandardError DEFAULT_APP_PATH end end |
#pgid ⇒ Object
124 125 126 |
# File 'lib/contrast/components/app_context.rb', line 124 def pgid Process.getpgid(pid) end |
#pid ⇒ Object
116 117 118 |
# File 'lib/contrast/components/app_context.rb', line 116 def pid Process.pid end |
#ppid ⇒ Object
120 121 122 |
# File 'lib/contrast/components/app_context.rb', line 120 def ppid Process.ppid end |
#server_name ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/contrast/components/app_context.rb', line 58 def server_name @_server_name ||= begin tmp = CONFIG.root.server.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_path ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/contrast/components/app_context.rb', line 69 def server_path @_server_path ||= begin tmp = CONFIG.root.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_type ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/contrast/components/app_context.rb', line 30 def server_type @_server_type ||= begin tmp = CONFIG.root.server.type tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp) tmp end end |