Class: Instana::Exporter::Otlp::HttpConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- Instana::Exporter::Otlp::HttpConverter
- 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
-
#build_status(error_count, error_msg) ⇒ Status
Build OTel-compliant span status, treating EXIT spans with 4xx as ERROR.
-
#convert_attributes ⇒ Hash
Extract HTTP-specific attributes as plain key/value pairs.
-
#span_name ⇒ String
Build OTel-compliant span name for HTTP spans.
Methods inherited from BaseConverter
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
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_attributes ⇒ Hash
Extract HTTP-specific attributes as plain key/value pairs
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_name ⇒ String
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.
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 |