Module: OpenTelemetry::Instrumentation::HTTPX::HttpHelper Private

Defined in:
lib/opentelemetry/instrumentation/httpx/http_helper.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utility module for normalizing HTTP methods according to OpenTelemetry semantic conventions

Defined Under Namespace

Classes: SpanCreationAttributes

Class Method Summary collapse

Class Method Details

.span_attrs_for_dup(method) ⇒ SpanCreationAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares span data using both old and stable semantic conventions

Parameters:

  • method (String, Symbol)

    The HTTP method

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/opentelemetry/instrumentation/httpx/http_helper.rb', line 107

def self.span_attrs_for_dup(method)
  client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
  url_template = client_context_attrs['url.template']
  normalized = METHOD_CACHE[method]
  attributes = client_context_attrs.dup

  # Determine base span name and method value
  if normalized
    base_name = normalized
    method_value = normalized
    original = nil
  else
    base_name = 'HTTP'
    method_value = '_OTHER'
    original = method.to_s
  end

  span_name = url_template ? "#{base_name} #{url_template}" : base_name
  attributes['http.method'] ||= method_value
  attributes['http.request.method'] ||= method_value
  attributes['http.request.method_original'] ||= original if original

  SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
end

.span_attrs_for_old(method) ⇒ SpanCreationAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares span data using old semantic conventions

Parameters:

  • method (String, Symbol)

    The HTTP method

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/opentelemetry/instrumentation/httpx/http_helper.rb', line 58

def self.span_attrs_for_old(method)
  client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
  normalized = METHOD_CACHE[method]
  attributes = client_context_attrs.dup

  # Determine base span name and method value
  if normalized
    span_name = OLD_SPAN_NAMES_BY_METHOD[normalized]
    method_value = normalized
  else
    span_name = 'HTTP'
    method_value = '_OTHER'
  end

  attributes['http.method'] ||= method_value

  SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
end

.span_attrs_for_stable(method) ⇒ SpanCreationAttributes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares span data using stable semantic conventions

Parameters:

  • method (String, Symbol)

    The HTTP method

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/opentelemetry/instrumentation/httpx/http_helper.rb', line 80

def self.span_attrs_for_stable(method)
  client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
  url_template = client_context_attrs['url.template']
  normalized = METHOD_CACHE[method]
  attributes = client_context_attrs.dup

  # Determine base span name and method value
  if normalized
    base_name = normalized
    method_value = normalized
    original = nil
  else
    base_name = 'HTTP'
    method_value = '_OTHER'
    original = method.to_s
  end

  span_name = url_template ? "#{base_name} #{url_template}" : base_name
  attributes['http.request.method'] ||= method_value
  attributes['http.request.method_original'] ||= original if original

  SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
end