Class: Instana::Exporter::Otlp::Resource
- Inherits:
-
Object
- Object
- Instana::Exporter::Otlp::Resource
- Defined in:
- lib/instana/exporter/otlp/resource.rb
Overview
Resource represents a resource, which captures identifying information about the entities for which telemetry (metrics or traces) is reported. This follows OpenTelemetry semantic conventions for resource attributes
Constant Summary collapse
- PROC_SELF_CGROUP =
'/proc/self/cgroup'- DOCKER_ENV_FILE =
'/.dockerenv'- PODMAN_CONTAINERENV =
'/run/.containerenv'- MACHINE_ID_PATHS =
Linux-only stable machine-id paths (systemd and D-Bus fallback). These files do not exist on macOS or Windows; host_id returns nil there.
%w[/etc/machine-id /var/lib/dbus/machine-id].freeze
- CLOUD_RESOURCE_ID =
cloud.resource_id is not yet in the installed semconv gem version
'cloud.resource_id'
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
Returns the attributes hash for this resource.
Class Method Summary collapse
-
.create(attributes = {}) ⇒ Resource
Returns a newly created Resource with the specified attributes.
-
.default ⇒ Resource
Returns the default resource with standard attributes.
-
.instance ⇒ Hash
Get the global resource instance (singleton pattern) This method provides backward compatibility with the previous API.
-
.process ⇒ Resource
Returns process resource attributes.
-
.reset! ⇒ Object
Reset the resource instance (useful for testing) This method provides backward compatibility with the previous API.
-
.telemetry_sdk ⇒ Resource
Returns telemetry SDK resource attributes.
Instance Method Summary collapse
-
#attribute_enumerator ⇒ Enumerator
Returns an enumerator for attributes of this Resource.
-
#initialize(frozen_attributes) ⇒ Resource
constructor
private
The constructor is private and only for use internally by the class.
- #merge(other) ⇒ Resource
Constructor Details
#initialize(frozen_attributes) ⇒ Resource
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The constructor is private and only for use internally by the class. Users should use the create factory method to obtain a Instana::Exporter::Otlp::Resource instance.
372 373 374 |
# File 'lib/instana/exporter/otlp/resource.rb', line 372 def initialize(frozen_attributes) @attributes = frozen_attributes end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns the attributes hash for this resource
399 400 401 |
# File 'lib/instana/exporter/otlp/resource.rb', line 399 def attributes @attributes end |
Class Method Details
.create(attributes = {}) ⇒ Resource
Returns a newly created Instana::Exporter::Otlp::Resource with the specified attributes
33 34 35 36 37 38 39 |
# File 'lib/instana/exporter/otlp/resource.rb', line 33 def create(attributes = {}) frozen_attributes = attributes.each_with_object({}) do |(k, v), memo| memo[k.freeze] = v.freeze end.freeze new(frozen_attributes) end |
.default ⇒ Resource
Returns the default resource with standard attributes
44 45 46 47 48 49 50 51 52 |
# File 'lib/instana/exporter/otlp/resource.rb', line 44 def default @default ||= create(OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => 'ruby-service') .merge(process) .merge(telemetry_sdk) .merge(service_name_from_env) .merge(optional_attributes) .merge(container_attributes) .merge(faas_attributes) end |
.instance ⇒ Hash
Get the global resource instance (singleton pattern) This method provides backward compatibility with the previous API
58 59 60 |
# File 'lib/instana/exporter/otlp/resource.rb', line 58 def instance @instance ||= default.attributes end |
.process ⇒ Resource
Returns process resource attributes
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/instana/exporter/otlp/resource.rb', line 83 def process create( OpenTelemetry::SemanticConventions::Resource::PROCESS_PID => Process.pid, OpenTelemetry::SemanticConventions::Resource::PROCESS_COMMAND => $PROGRAM_NAME, OpenTelemetry::SemanticConventions::Resource::PROCESS_EXECUTABLE_NAME => File.basename($PROGRAM_NAME), OpenTelemetry::SemanticConventions::Resource::PROCESS_RUNTIME_NAME => RUBY_ENGINE, OpenTelemetry::SemanticConventions::Resource::PROCESS_RUNTIME_VERSION => RUBY_VERSION, OpenTelemetry::SemanticConventions::Resource::PROCESS_RUNTIME_DESCRIPTION => RUBY_DESCRIPTION ) end |
.reset! ⇒ Object
Reset the resource instance (useful for testing) This method provides backward compatibility with the previous API
64 65 66 67 |
# File 'lib/instana/exporter/otlp/resource.rb', line 64 def reset! @instance = nil @default = nil end |
.telemetry_sdk ⇒ Resource
Returns telemetry SDK resource attributes
72 73 74 75 76 77 78 |
# File 'lib/instana/exporter/otlp/resource.rb', line 72 def telemetry_sdk create( OpenTelemetry::SemanticConventions::Resource::TELEMETRY_SDK_NAME => 'instana', OpenTelemetry::SemanticConventions::Resource::TELEMETRY_SDK_LANGUAGE => 'ruby', OpenTelemetry::SemanticConventions::Resource::TELEMETRY_SDK_VERSION => ::Instana::VERSION ) end |
Instance Method Details
#attribute_enumerator ⇒ Enumerator
Returns an enumerator for attributes of this Instana::Exporter::Otlp::Resource
379 380 381 |
# File 'lib/instana/exporter/otlp/resource.rb', line 379 def attribute_enumerator @attribute_enumerator ||= attributes.to_enum end |
#merge(other) ⇒ Resource
Returns a new, merged Instana::Exporter::Otlp::Resource by merging the current Instana::Exporter::Otlp::Resource with the other Instana::Exporter::Otlp::Resource. In case of a collision, the other Instana::Exporter::Otlp::Resource takes precedence
390 391 392 393 394 |
# File 'lib/instana/exporter/otlp/resource.rb', line 390 def merge(other) return self unless other.is_a?(Resource) self.class.send(:new, attributes.merge(other.send(:attributes)).freeze) end |