Sha256: 3a68df93252b9abab3ec8f8dddcadda788ae4722a00e7f489ec78f0dd6d9d814

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'elastic_apm/context/request'
require 'elastic_apm/context/request/socket'
require 'elastic_apm/context/request/url'
require 'elastic_apm/context/response'
require 'elastic_apm/context/user'

module ElasticAPM
  # @api private
  class Context
    def initialize(custom: {}, labels: {}, user: nil, service: nil)
      @custom = custom
      @labels = labels
      @user = user || User.new
      @service = service
    end

    Service = Struct.new(:framework)
    Framework = Struct.new(:name, :version)

    attr_accessor :request
    attr_accessor :response
    attr_accessor :user
    attr_reader :custom
    attr_reader :labels
    attr_reader :service

    # rubocop:disable Metrics/CyclomaticComplexity
    def empty?
      return false if labels.any?
      return false if custom.any?
      return false if user.any?
      return false if service
      return false if request || response

      true
    end
    # rubocop:enable Metrics/CyclomaticComplexity

    def set_service(framework_name: nil, framework_version: nil)
      @service = Service.new(
        Framework.new(framework_name, framework_version)
      )
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
elastic-apm-3.6.0 lib/elastic_apm/context.rb
elastic-apm-3.5.0 lib/elastic_apm/context.rb
elastic-apm-3.4.0 lib/elastic_apm/context.rb
elastic-apm-3.3.0 lib/elastic_apm/context.rb
elastic-apm-3.2.0 lib/elastic_apm/context.rb
elastic-apm-3.1.0 lib/elastic_apm/context.rb