Class: Instana::Exporter::Otlp::RailsConverter

Inherits:
BaseConverter show all
Defined in:
lib/instana/exporter/otlp/rails_converter.rb

Overview

Converter for Rails-related spans (ActionController, ActionView, ActionMailer) to OTLP format

Constant Summary collapse

ACTIONMAILER_SPAN =
'mail.actionmailer'

Instance Method Summary collapse

Methods inherited from BaseConverter

#convert, #initialize

Constructor Details

This class inherits a constructor from Instana::Exporter::Otlp::BaseConverter

Instance Method Details

#convert_attributesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/instana/exporter/otlp/rails_converter.rb', line 52

def convert_attributes
  attributes = {}
  span_type  = span[:n].to_s

  if span_type == 'actioncontroller' # rubocop:disable Style/CaseLikeIf
    convert_action_controller_attributes(attributes)
  elsif span_type == 'actionview'
    convert_action_view_attributes(attributes)
  elsif span_type == 'render'
    convert_render_attributes(attributes)
  elsif span_type == ACTIONMAILER_SPAN
    convert_action_mailer_attributes(attributes)
  end

  attributes
end

#span_nameString

Build OTel-compliant span name for Rails spans

Formulas per SPAN_NAME_PATTERNS.txt Sections 5 & 7:

actioncontroller  → "{Controller}#{action}"    e.g. "UsersController#index"
actionview        → "{view_name}"              e.g. "users/index"
render            → "{type} {name}"            e.g. "template users/index"
mail.actionmailer → "{Class}#{method}"         e.g. "UserMailer#welcome_email"

Returns:

  • (String)

    The span name



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/instana/exporter/otlp/rails_converter.rb', line 24

def span_name
  case span[:n].to_s
  when 'actioncontroller'
    d = span_data_for(:actioncontroller)
    ctrl   = d[:controller].to_s.strip
    action = d[:action].to_s.strip
    parts  = [ctrl, action].reject(&:empty?)
    parts.empty? ? 'actioncontroller' : parts.join('#')
  when 'actionview'
    d = span_data_for(:actionview)
    d[:name].to_s.strip.then { |n| n.empty? ? 'actionview' : n }
  when 'render'
    d = span_data_for(:render)
    type = d[:type].to_s.strip
    name = d[:name].to_s.strip
    parts = [type, name].reject(&:empty?)
    parts.empty? ? 'render' : parts.join(' ')
  when ACTIONMAILER_SPAN
    d = span_data_for(:actionmailer)
    klass  = d[:class].to_s.strip
    method = d[:method].to_s.strip
    parts  = [klass, method].reject(&:empty?)
    parts.empty? ? ACTIONMAILER_SPAN : parts.join('#')
  else
    super
  end
end