Class: Instana::Exporter::Otlp::HttpConverter

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

Overview

Converter for HTTP spans to OTLP format Handles conversion of HTTP-related spans with specific attributes

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

#build_status(error_count, error_msg) ⇒ Status

Build OTel-compliant span status, treating EXIT spans with 4xx as ERROR

Parameters:

  • error_count (Integer)

    Span error count

  • error_msg (String, nil)

    Pre-extracted error message

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/instana/exporter/otlp/http_converter.rb', line 43

def build_status(error_count, error_msg)
  return super unless error_count.zero?

  http_data = span[:data]&.[](:http) || {}
  status_code = http_data[:status].to_i

  if convert_span_kind == :client && status_code >= 400 && status_code < 500
    Status.new(OpenTelemetry::Trace::Status::ERROR, '')
  else
    super
  end
end

#convert_attributesHash

Extract HTTP-specific attributes as plain key/value pairs

Returns:

  • (Hash)

    HTTP attributes



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/instana/exporter/otlp/http_converter.rb', line 19

def convert_attributes
  attributes = {}
  http_data = span[:data]&.[](:http) || {}

  add_attribute(attributes, OpenTelemetry::SemConv::HTTP::HTTP_REQUEST_METHOD, http_data[:method])
  add_attribute(attributes, OpenTelemetry::SemConv::URL::URL_FULL, http_data[:url])
  add_attribute(attributes, OpenTelemetry::SemConv::URL::URL_PATH, http_data[:path])
  add_attribute(attributes, OpenTelemetry::SemConv::URL::URL_QUERY, http_data[:params])
  add_attribute(attributes, OpenTelemetry::SemConv::SERVER::SERVER_ADDRESS, extract_host(http_data[:host]))
  add_attribute(attributes, OpenTelemetry::SemConv::SERVER::SERVER_PORT, extract_port(http_data[:host], http_data[:url]))
  add_attribute(attributes, OpenTelemetry::SemConv::URL::URL_SCHEME, extract_scheme(http_data[:url]))
  add_attribute(attributes, OpenTelemetry::SemConv::HTTP::HTTP_RESPONSE_STATUS_CODE, http_data[:status])
  add_attribute(attributes, OpenTelemetry::SemConv::USER_AGENT::USER_AGENT_ORIGINAL, http_data.dig(:header, 'user-agent'))

  add_protocol_attributes(attributes, http_data[:protocol])

  attributes
end

#span_nameString

Build OTel-compliant span name for HTTP spans

Convention (stable): "METHOD" or "METHOD Instana::Exporter::Otlp::HttpConverter.urlurl.template/path" Falls back to "HTTP" when no method is present.

Returns:

  • (String)

    The span name



62
63
64
65
66
67
68
69
# File 'lib/instana/exporter/otlp/http_converter.rb', line 62

def span_name
  http_data = span[:data]&.[](:http) || {}
  method = http_data[:method].to_s.upcase
  method = 'HTTP' if method.empty?

  path = http_data[:path].to_s.strip
  path.empty? ? method : "#{method} #{path}"
end