Module: NewRelic::Agent::OpenTelemetry::Segments::Server

Included in:
Trace::Tracer
Defined in:
lib/new_relic/agent/opentelemetry/segments/server.rb

Instance Method Summary collapse

Instance Method Details

#create_server_transaction_name(original_name, tracer_name, attributes) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/new_relic/agent/opentelemetry/segments/server.rb', line 10

def create_server_transaction_name(original_name, tracer_name, attributes)
  attributes ||= NewRelic::EMPTY_HASH
  method = attributes['http.request.method'] || attributes['http.method']
  path = attributes['url.path'] || attributes['http.target']

  if method && path
    # TransactionNamer.name_for is used in ControllerInstrumentation
    # This will produce a name that looks something like:
    # "Controller/OpenTelemetry::Instrumentation::Rack/GET /path"
    # "method /path" is roughly what the semantic conventions have for
    # a server span name in the stable conventions, but the old
    # conventions prefix with HTTP; so we create the string
    # ourselves until only the stable conventions are used
    Instrumentation::ControllerInstrumentation::TransactionNamer.name_for(nil, nil, :web, {class_name: tracer_name, name: "#{method} #{path}"})
  else
    original_name
  end
end

#update_request_attributes(nr_item, attributes) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/new_relic/agent/opentelemetry/segments/server.rb', line 29

def update_request_attributes(nr_item, attributes)
  return unless nr_item.is_a?(Transaction)

  request_attributes = nr_item.instance_variable_get(:@request_attributes)

  return unless request_attributes.is_a?(NewRelic::Agent::Transaction::RequestAttributes)

  attributes ||= NewRelic::EMPTY_HASH
  host = attributes['server.address'] || attributes['http.host']
  method = attributes['http.request.method'] || attributes['http.method']
  path = attributes['url.path'] || attributes['http.target']
  user_agent = attributes['user_agent.original'] || attributes['http.user_agent']

  request_attributes.instance_variable_set(:@host, host) if host
  request_attributes.instance_variable_set(:@request_method, method) if method
  request_attributes.instance_variable_set(:@request_path, path) if path
  request_attributes.instance_variable_set(:@user_agent, user_agent) if user_agent
end