Class: Instana::Exporter::Otlp::BaseConverter Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/exporter/otlp/base_converter.rb

Overview

This class is abstract.

Subclasses should override #convert_attributes to provide type-specific attribute conversion logic.

Base class for all OTLP span converters

Provides common interface and shared functionality for converting Instana spans to OpenTelemetry Protocol (OTLP) compatible span data objects.

Examples:

Creating a custom converter

class MyConverter < BaseConverter
  def convert_attributes
    attributes = {}
    add_attribute(attributes, 'custom.field', span[:data][:custom][:field])
    attributes
  end
end

Defined Under Namespace

Classes: Event, InstrumentationScope, ResourceAdapter, SpanData, SpanDataWithEvents, Status

Instance Method Summary collapse

Constructor Details

#initialize(span, resource = nil) ⇒ BaseConverter

Returns a new instance of BaseConverter.

Parameters:

  • span (Instana::Trace::Span)

    The span to convert

  • resource (Object, nil) (defaults to: nil)

    Optional resource information (defaults to global resource)



142
143
144
145
# File 'lib/instana/exporter/otlp/base_converter.rb', line 142

def initialize(span, resource = nil)
  @span = span
  @resource = resource || Resource.instance
end

Instance Method Details

#convertSpanData, SpanDataWithEvents

Convert the Instana span to OTLP-compatible span data

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/instana/exporter/otlp/base_converter.rb', line 150

def convert
  # Resolve error info once — reused by both status and events
  error_count = span[:ec].to_i
  error_msg   = error_count.positive? ? extract_error_message : nil
  stacktrace  = error_count.positive? ? convert_stack_trace   : nil

  span_data = SpanData.new(
    name: span_name,
    trace_id: format_trace_id(span[:t]),
    span_id: format_span_id(span[:s]),
    parent_span_id: format_parent_span_id,
    resource: resource_adapter,
    instrumentation_scope: instrumentation_scope,
    kind: convert_span_kind,
    start_timestamp: convert_to_unix_nano(span[:ts]),
    end_timestamp: calculate_end_timestamp,
    attributes: convert_attributes,
    status: build_status(error_count, error_msg)
  )

  events = build_error_events(error_count, error_msg, stacktrace)
  return SpanDataWithEvents.new(span_data, events) unless events.empty?

  span_data
end