Class: NewRelic::Agent::OpenTelemetry::BaseTranslator
- Inherits:
-
Object
- Object
- NewRelic::Agent::OpenTelemetry::BaseTranslator
- Includes:
- AttributeMappings
- Defined in:
- lib/new_relic/agent/opentelemetry/translators/base_translator.rb
Direct Known Subclasses
DatastoreTranslator, GenericTranslator, HttpClientTranslator, HttpServerTranslator
Constant Summary
Constants included from AttributeMappings
AttributeMappings::DATASTORE_MAPPINGS, AttributeMappings::DEFAULT_DESTINATIONS, AttributeMappings::HTTP_CLIENT_MAPPINGS, AttributeMappings::HTTP_SERVER_MAPPINGS
Class Method Summary collapse
-
.add_specialized_attributes(result: {}, name: nil, attributes: {}, instrumentation_scope: nil) ⇒ Hash
Method defined by child classes that calls any extra, unique operations to craft attributes.
-
.mappings_hash ⇒ Object
This method should be redefined in child classes.
-
.translate(attributes: {}, name: nil, instrumentation_scope: nil) ⇒ Hash
The translate method iterates through the mappings_hash to assign the provided attributes into the correct categories.
Class Method Details
.add_specialized_attributes(result: {}, name: nil, attributes: {}, instrumentation_scope: nil) ⇒ Hash
Method defined by child classes that calls any extra, unique operations to craft attributes. Ex: parse_operation in DatastoreTranslator.
74 75 76 77 |
# File 'lib/new_relic/agent/opentelemetry/translators/base_translator.rb', line 74 def add_specialized_attributes(result: {}, name: nil, attributes: {}, instrumentation_scope: nil) # no-op {} end |
.mappings_hash ⇒ Object
This method should be redefined in child classes. The body of the method should be the mappings constant defined in the
AttributesMappings module for the attribute type being translated
17 18 19 20 |
# File 'lib/new_relic/agent/opentelemetry/translators/base_translator.rb', line 17 def mappings_hash # no-op NewRelic::EMPTY_HASH end |
.translate(attributes: {}, name: nil, instrumentation_scope: nil) ⇒ Hash
The translate method iterates through the mappings_hash to assign the provided attributes into the correct categories
transaction or segment.
31 32 33 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 |
# File 'lib/new_relic/agent/opentelemetry/translators/base_translator.rb', line 31 def translate(attributes: {}, name: nil, instrumentation_scope: nil) working_attrs = attributes.dup # shallow copy result = {intrinsic: {}, agent: {}, custom: {}, for_segment_api: {}, instance_variable: {}, translator: self} mappings_hash.each do |nr_key, mapping| value = extract_first_present(working_attrs, mapping[:otel_keys]) next unless value case mapping[:category] when :intrinsic result[:intrinsic][nr_key] = value when :agent result[:agent][nr_key] = {value: value, destinations: mapping[:destinations]} when :instance_variable result[:instance_variable][nr_key] = value end if mapping[:segment_field] result[:for_segment_api][mapping[:segment_field]] = value end end # Call any methods unique to the category being translated to create # specialized attributes. # This method will augment the working result hash, so it does not # need to be merged. add_specialized_attributes(result: result, name: name, attributes: attributes, instrumentation_scope: instrumentation_scope) # Assign any remaining attributes as custom attributes result[:custom] = working_attrs result end |