class ElasticAPM::Transport::Serializers::ContextSerializer

@api private

Public Instance Methods

build(context) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 25
def build(context)
  return nil if context.nil? || context.empty?

  {
    custom: context.custom,
    tags: mixed_object(context.labels),
    request: build_request(context.request),
    response: build_response(context.response),
    user: build_user(context.user),
    service: build_service(context.service)
  }
end

Private Instance Methods

build_request(request) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 40
def build_request(request)
  return unless request

  {
    body: request.body,
    cookies: request.cookies,
    env: request.env,
    headers: request.headers,
    http_version: keyword_field(request.http_version),
    method: keyword_field(request.method),
    socket: build_socket(request.socket),
    url: build_url(request.url)
  }
end
build_response(response) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 55
def build_response(response)
  return unless response

  {
    status_code: response.status_code.to_i,
    headers: response.headers,
    headers_sent: response.headers_sent,
    finished: response.finished
  }
end
build_service(service) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 98
def build_service(service)
  return unless service

  {
    framework: {
      name: keyword_field(service.framework.name),
      version: keyword_field(service.framework.version)
    }
  }
end
build_socket(socket) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 76
def build_socket(socket)
  return unless socket

  {
    remote_addr: socket.remote_addr
  }
end
build_url(url) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 84
def build_url(url)
  return unless url

  {
    protocol: keyword_field(url.protocol),
    full: keyword_field(url.full),
    hostname: keyword_field(url.hostname),
    port: keyword_field(url.port),
    pathname: keyword_field(url.pathname),
    search: keyword_field(url.search),
    hash: keyword_field(url.hash)
  }
end
build_user(user) click to toggle source
# File lib/elastic_apm/transport/serializers/context_serializer.rb, line 66
def build_user(user)
  return if !user || user.empty?

  {
    id: keyword_field(user.id),
    email: keyword_field(user.email),
    username: keyword_field(user.username)
  }
end