elastic-apm 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of elastic-apm might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/elastic_apm/instrumenter.rb +1 -0
- data/lib/elastic_apm/metadata/system_info.rb +7 -1
- data/lib/elastic_apm/metadata/system_info/container_info.rb +117 -0
- data/lib/elastic_apm/railtie.rb +2 -2
- data/lib/elastic_apm/transport/connection.rb +1 -1
- data/lib/elastic_apm/util/prefixed_logger.rb +2 -2
- data/lib/elastic_apm/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b8d2dcb34f97fa80f6dd200bbb5d6a02a0219d054a0f2ca0df5a186ff530c8a
|
4
|
+
data.tar.gz: 4ad68c7e8c7fcac5d82c7b621090091dd9816e90584115b0482523b7ca458942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1203dad667452f7080e67d7509f8046b327989c88da82e7019ecac3488c6a990d974e631a2ebd284c0e7b0896c8d533912bb8228bf728f7244c4a6da10edbd6
|
7
|
+
data.tar.gz: be5499f9a2bbb5803879d8fde02c8aa6b4b6c7585b150cb9f7baebd7d52b86df79db664aaa3b9e330458e2f29c60dc53b4f0a96ffeb999a8615215a7b8de2289
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## Changed (2019-01-31)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Read container info from Docker or Kupernetes ([#303](https://github.com/elastic/apm-agent-ruby/pull/303))
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- Fix logging exceptions when booting via Railtie ([#306](https://github.com/elastic/apm-agent-ruby/pull/306))
|
16
|
+
|
7
17
|
## 2.3.0 (2019-01-29)
|
8
18
|
|
9
19
|
### Added
|
@@ -10,9 +10,13 @@ module ElasticAPM
|
|
10
10
|
@hostname = @config.hostname || `hostname`.chomp
|
11
11
|
@architecture = gem_platform.cpu
|
12
12
|
@platform = gem_platform.os
|
13
|
+
|
14
|
+
container_info = ContainerInfo.read!
|
15
|
+
@container = container_info.container
|
16
|
+
@kupernetes = container_info.kupernetes
|
13
17
|
end
|
14
18
|
|
15
|
-
attr_reader :hostname, :architecture, :platform
|
19
|
+
attr_reader :hostname, :architecture, :platform, :container, :kupernetes
|
16
20
|
|
17
21
|
private
|
18
22
|
|
@@ -22,3 +26,5 @@ module ElasticAPM
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
29
|
+
|
30
|
+
require 'elastic_apm/metadata/system_info/container_info'
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElasticAPM
|
4
|
+
class Metadata
|
5
|
+
class SystemInfo
|
6
|
+
# @api private
|
7
|
+
class ContainerInfo
|
8
|
+
CGROUP_PATH = '/proc/pid/cgroup'
|
9
|
+
|
10
|
+
attr_accessor :container_id, :kupernetes_namespace,
|
11
|
+
:kupernetes_node_name, :kupernetes_pod_name, :kupernetes_pod_uid
|
12
|
+
|
13
|
+
def initialize(cgroup_path: CGROUP_PATH)
|
14
|
+
@cgroup_path = cgroup_path
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :cgroup_path
|
18
|
+
|
19
|
+
def read!
|
20
|
+
read_from_cgroup!
|
21
|
+
read_from_env!
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.read!
|
26
|
+
new.read!
|
27
|
+
end
|
28
|
+
|
29
|
+
def container
|
30
|
+
@container ||=
|
31
|
+
begin
|
32
|
+
return unless container_id
|
33
|
+
{ id: container_id }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def kupernetes
|
38
|
+
@kupernetes =
|
39
|
+
begin
|
40
|
+
kupernetes = {}
|
41
|
+
|
42
|
+
kupernetes[:namespace] = kupernetes_namespace
|
43
|
+
kupernetes[:node_name] = kupernetes_node_name
|
44
|
+
kupernetes[:pod_name] = kupernetes_pod_name
|
45
|
+
kupernetes[:pod_uid] = kupernetes_pod_uid
|
46
|
+
return nil if kupernetes.values.all?(&:nil?)
|
47
|
+
|
48
|
+
kupernetes
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def read_from_env!
|
55
|
+
self.kupernetes_namespace =
|
56
|
+
ENV.fetch('KUBERNETES_NAMESPACE', kupernetes_namespace)
|
57
|
+
self.kupernetes_node_name =
|
58
|
+
ENV.fetch('KUBERNETES_NODE_NAME', kupernetes_node_name)
|
59
|
+
self.kupernetes_pod_name =
|
60
|
+
ENV.fetch('KUBERNETES_POD_NAME', kupernetes_pod_name)
|
61
|
+
self.kupernetes_pod_uid =
|
62
|
+
ENV.fetch('KUBERNETES_POD_UID', kupernetes_pod_uid)
|
63
|
+
end
|
64
|
+
|
65
|
+
CONTAINER_ID_REGEX = /^[0-9A-Fa-f]{64}$/.freeze
|
66
|
+
KUBEPODS_REGEX = %r{(?:^/kubepods/[^/]+/pod([^/]+)$)|(?:^/kubepods\.slice/kubepods-[^/]+\.slice/kubepods-[^/]+-pod([^/]+)\.slice$)}.freeze # rubocop:disable Metrics/LineLength
|
67
|
+
SYSTEMD_SCOPE_SUFFIX = '.scope'
|
68
|
+
|
69
|
+
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
|
70
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
71
|
+
def read_from_cgroup!
|
72
|
+
return unless File.exist?(cgroup_path)
|
73
|
+
IO.readlines(cgroup_path).each do |line|
|
74
|
+
parts = line.strip.split(':')
|
75
|
+
next if parts.length != 3
|
76
|
+
|
77
|
+
cgroup_path = parts[2]
|
78
|
+
|
79
|
+
# Depending on the filesystem driver used for cgroup
|
80
|
+
# management, the paths in /proc/pid/cgroup will have
|
81
|
+
# one of the following formats in a Docker container:
|
82
|
+
#
|
83
|
+
# systemd: /system.slice/docker-<container-ID>.scope
|
84
|
+
# cgroupfs: /docker/<container-ID>
|
85
|
+
#
|
86
|
+
# In a Kubernetes pod, the cgroup path will look like:
|
87
|
+
#
|
88
|
+
# systemd:
|
89
|
+
# /kubepods.slice/kubepods-<QoS-class>.slice/kubepods-\
|
90
|
+
# <QoS-class>-pod<pod-UID>.slice/<container-iD>.scope
|
91
|
+
# cgroupfs:
|
92
|
+
# /kubepods/<QoS-class>/pod<pod-UID>/<container-iD>
|
93
|
+
directory, container_id = File.split(cgroup_path)
|
94
|
+
|
95
|
+
if container_id.end_with?(SYSTEMD_SCOPE_SUFFIX)
|
96
|
+
container_id = container_id[0...-SYSTEMD_SCOPE_SUFFIX.length]
|
97
|
+
if container_id.include?('-')
|
98
|
+
container_id = container_id.split('-', 2)[1]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if (kubepods_match = KUBEPODS_REGEX.match(directory))
|
103
|
+
pod_id = kubepods_match[1] || kubepods_match[2]
|
104
|
+
|
105
|
+
self.container_id = container_id
|
106
|
+
self.kupernetes_pod_uid = pod_id
|
107
|
+
elsif CONTAINER_ID_REGEX.match(container_id)
|
108
|
+
self.container_id = container_id
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
113
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/elastic_apm/railtie.rb
CHANGED
@@ -10,7 +10,7 @@ module ElasticAPM
|
|
10
10
|
Config::DEFAULTS.each { |option, value| config.elastic_apm[option] = value }
|
11
11
|
|
12
12
|
initializer 'elastic_apm.initialize' do |app|
|
13
|
-
config = app.config.elastic_apm.merge(app: app).tap do |c|
|
13
|
+
config = Config.new(app.config.elastic_apm.merge(app: app)).tap do |c|
|
14
14
|
# Prepend Rails.root to log_path if present
|
15
15
|
if c.log_path && !c.log_path.start_with?('/')
|
16
16
|
c.log_path = Rails.root.join(c.log_path)
|
@@ -27,7 +27,7 @@ module ElasticAPM
|
|
27
27
|
end
|
28
28
|
rescue StandardError => e
|
29
29
|
config.alert_logger.error format('Failed to start: %s', e.message)
|
30
|
-
config.alert_logger.debug e.backtrace.join("\n")
|
30
|
+
config.alert_logger.debug "Backtrace:\n" + e.backtrace.join("\n")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -119,7 +119,7 @@ module ElasticAPM
|
|
119
119
|
if resp&.status == 202
|
120
120
|
debug 'APM Server responded with status 202'
|
121
121
|
elsif resp
|
122
|
-
error "APM Server
|
122
|
+
error "APM Server responded with an error:\n%p", resp.body.to_s
|
123
123
|
end
|
124
124
|
|
125
125
|
resp
|
@@ -11,8 +11,8 @@ module ElasticAPM
|
|
11
11
|
|
12
12
|
attr_reader :prefix
|
13
13
|
|
14
|
-
def add(severity, message = nil, progname = nil)
|
15
|
-
super(severity, format('%s%s', prefix,
|
14
|
+
def add(severity, message = nil, progname = nil, &block)
|
15
|
+
super(severity, message, format('%s%s', prefix, progname), &block)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/elastic_apm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/elastic_apm/metadata/process_info.rb
|
105
105
|
- lib/elastic_apm/metadata/service_info.rb
|
106
106
|
- lib/elastic_apm/metadata/system_info.rb
|
107
|
+
- lib/elastic_apm/metadata/system_info/container_info.rb
|
107
108
|
- lib/elastic_apm/metrics.rb
|
108
109
|
- lib/elastic_apm/metrics/cpu_mem.rb
|
109
110
|
- lib/elastic_apm/metricset.rb
|