Module: Datadog::Runtime::Container
- Defined in:
- lib/ddtrace/runtime/container.rb
Overview
For container environments
Defined Under Namespace
Classes: Descriptor
Constant Summary collapse
- UUID_PATTERN =
'[0-9a-f]{8}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{12}'.freeze
- CONTAINER_PATTERN =
'[0-9a-f]{64}'.freeze
- POD_REGEX =
/(pod)?(#{UUID_PATTERN})(?:.slice)?$/
- CONTAINER_REGEX =
/(#{UUID_PATTERN}|#{CONTAINER_PATTERN})(?:.scope)?$/
Class Method Summary collapse
Class Method Details
.container_id ⇒ Object
26 27 28 |
# File 'lib/ddtrace/runtime/container.rb', line 26 def container_id descriptor.container_id end |
.descriptor ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ddtrace/runtime/container.rb', line 34 def descriptor @descriptor ||= begin Descriptor.new.tap do |descriptor| begin Cgroup.descriptors.each do |cgroup_descriptor| # Parse container data from cgroup descriptor path = cgroup_descriptor.path next if path.nil? # Split path into parts parts = path.split('/') parts.shift # Remove leading empty part next if parts.length < 2 # Read info from path platform = parts[0] container_id = parts[-1][CONTAINER_REGEX] task_uid = parts[-2][POD_REGEX] # If container ID wasn't found, ignore. # Path might describe a non-container environment. next if container_id.nil? descriptor.platform = platform descriptor.container_id = container_id descriptor.task_uid = task_uid break end rescue StandardError => e Datadog::Tracer.log.error( "Error while parsing container info. Cause: #{e.} Location: #{e.backtrace.first}" ) end end end end |
.platform ⇒ Object
22 23 24 |
# File 'lib/ddtrace/runtime/container.rb', line 22 def platform descriptor.platform end |
.task_uid ⇒ Object
30 31 32 |
# File 'lib/ddtrace/runtime/container.rb', line 30 def task_uid descriptor.task_uid end |