Class: OpenTelemetry::SDK::Resources::Resource
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Resources::Resource
- Defined in:
- lib/opentelemetry/sdk/resources/resource.rb
Overview
Resource represents a resource, which captures identifying information about the entities for which telemetry (metrics or traces) is reported.
Class Method Summary collapse
-
.create(labels = {}) ⇒ Resource
Returns a newly created Resource with the specified labels.
- .telemetry_sdk ⇒ Object
Instance Method Summary collapse
-
#initialize(frozen_labels) ⇒ Resource
constructor
private
The constructor is private and only for use internally by the class.
-
#label_enumerator ⇒ Enumerator
Returns an enumerator for labels of this Resource.
- #merge(other) ⇒ Resource
Constructor Details
#initialize(frozen_labels) ⇒ 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 OpenTelemetry::SDK::Resources::Resource instance.
50 51 52 |
# File 'lib/opentelemetry/sdk/resources/resource.rb', line 50 def initialize(frozen_labels) @labels = frozen_labels end |
Class Method Details
.create(labels = {}) ⇒ Resource
Returns a newly created OpenTelemetry::SDK::Resources::Resource with the specified labels
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opentelemetry/sdk/resources/resource.rb', line 22 def create(labels = {}) frozen_labels = labels.each_with_object({}) do |(k, v), memo| raise ArgumentError, 'label keys must be strings' unless k.is_a?(String) raise ArgumentError, 'label values must be strings, integers, floats, or booleans' unless Internal.valid_value?(v) memo[-k] = v.freeze end.freeze new(frozen_labels) end |
.telemetry_sdk ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/opentelemetry/sdk/resources/resource.rb', line 33 def telemetry_sdk create( Constants::TELEMETRY_SDK_RESOURCE[:name] => 'opentelemetry', Constants::TELEMETRY_SDK_RESOURCE[:language] => 'ruby', Constants::TELEMETRY_SDK_RESOURCE[:version] => "semver:#{OpenTelemetry::SDK::VERSION}" ) end |
Instance Method Details
#label_enumerator ⇒ Enumerator
Returns an enumerator for labels of this OpenTelemetry::SDK::Resources::Resource
57 58 59 |
# File 'lib/opentelemetry/sdk/resources/resource.rb', line 57 def label_enumerator @label_enumerator ||= labels.to_enum end |
#merge(other) ⇒ Resource
Returns a new, merged OpenTelemetry::SDK::Resources::Resource by merging the current OpenTelemetry::SDK::Resources::Resource with the other OpenTelemetry::SDK::Resources::Resource. In case of a collision, the current OpenTelemetry::SDK::Resources::Resource takes precedence
68 69 70 71 72 73 74 75 76 |
# File 'lib/opentelemetry/sdk/resources/resource.rb', line 68 def merge(other) return self unless other.is_a?(Resource) merged_labels = labels.merge(other.labels) do |_, old_v, new_v| old_v.empty? ? new_v : old_v end self.class.send(:new, merged_labels.freeze) end |