lib/opentelemetry/sdk/resources/resource.rb in opentelemetry-sdk-0.12.1 vs lib/opentelemetry/sdk/resources/resource.rb in opentelemetry-sdk-0.13.0
- old
+ new
@@ -28,10 +28,14 @@
end.freeze
new(frozen_attributes)
end
+ def default
+ @default ||= telemetry_sdk.merge(process).merge(create(Constants::SERVICE_RESOURCE[:name] => 'unknown_service'))
+ end
+
def telemetry_sdk
resource_attributes = {
Constants::TELEMETRY_SDK_RESOURCE[:name] => 'opentelemetry',
Constants::TELEMETRY_SDK_RESOURCE[:language] => 'ruby',
Constants::TELEMETRY_SDK_RESOURCE[:version] => OpenTelemetry::SDK::VERSION
@@ -46,10 +50,22 @@
end
resource_attributes.delete_if { |_key, value| value.nil? || value.empty? }
create(resource_attributes)
end
+
+ def process
+ resource_attributes = {
+ Constants::PROCESS_RESOURCE[:pid] => Process.pid,
+ Constants::PROCESS_RESOURCE[:command] => $PROGRAM_NAME,
+ Constants::PROCESS_RUNTIME_RESOURCE[:name] => RUBY_ENGINE,
+ Constants::PROCESS_RUNTIME_RESOURCE[:version] => RUBY_VERSION,
+ Constants::PROCESS_RUNTIME_RESOURCE[:description] => RUBY_DESCRIPTION
+ }
+
+ create(resource_attributes)
+ end
end
# @api private
# The constructor is private and only for use internally by the class.
# Users should use the {create} factory method to obtain a {Resource}
@@ -77,14 +93,10 @@
# @return [Resource] A new resource formed by merging the current resource
# with other
def merge(other)
return self unless other.is_a?(Resource)
- merged_attributes = attributes.merge(other.attributes) do |_, old_v, new_v|
- old_v.empty? ? new_v : old_v
- end
-
- self.class.send(:new, merged_attributes.freeze)
+ self.class.send(:new, attributes.merge(other.attributes).freeze)
end
protected
attr_reader :attributes