Class: ElasticAPM::OpenTracing::Span Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_apm/opentracing.rb

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elastic_span, span_context) ⇒ Span

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.

Returns a new instance of Span.



27
28
29
30
# File 'lib/elastic_apm/opentracing.rb', line 27

def initialize(elastic_span, span_context)
  @elastic_span = elastic_span
  @span_context = span_context
end

Instance Attribute Details

#elastic_spanObject (readonly)

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.



32
33
34
# File 'lib/elastic_apm/opentracing.rb', line 32

def elastic_span
  @elastic_span
end

Instance Method Details

#contextObject

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.



38
39
40
# File 'lib/elastic_apm/opentracing.rb', line 38

def context
  @span_context
end

#finish(end_time: Time.now) ⇒ Object

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.

rubocop:enable Lint/UnusedMethodArgument



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/elastic_apm/opentracing.rb', line 85

def finish(end_time: Time.now)
  return unless (agent = ElasticAPM.agent)

  elastic_span.done clock_end: Util.micros(end_time)

  case elastic_span
  when ElasticAPM::Transaction
    agent.instrumenter.current_transaction = nil
  when ElasticAPM::Span
    agent.instrumenter.current_spans.delete(elastic_span)
  end

  agent.enqueue elastic_span
end

#get_baggage_item(_key) ⇒ Object

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.



67
68
69
70
71
72
73
# File 'lib/elastic_apm/opentracing.rb', line 67

def get_baggage_item(_key)
  ElasticAPM.agent.config.logger.warn(
    'Baggage is not supported by ElasticAPM'
  )

  nil
end

#log_kv(timestamp: nil, **fields) ⇒ Object

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.

rubocop:disable Lint/UnusedMethodArgument



76
77
78
79
80
81
82
# File 'lib/elastic_apm/opentracing.rb', line 76

def log_kv(timestamp: nil, **fields)
  if (exception = fields[:'error.object'])
    ElasticAPM.report exception
  elsif (message = fields[:message])
    ElasticAPM.report_message message
  end
end

#operation_name=(name) ⇒ Object

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.



34
35
36
# File 'lib/elastic_apm/opentracing.rb', line 34

def operation_name=(name)
  elastic_span.name = name
end

#set_baggage_item(_key, _value) ⇒ Object

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.



61
62
63
64
65
# File 'lib/elastic_apm/opentracing.rb', line 61

def set_baggage_item(_key, _value)
  ElasticAPM.agent.config.logger.warn(
    'Baggage is not supported by ElasticAPM'
  )
end

#set_tag(key, val) ⇒ Object

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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/elastic_apm/opentracing.rb', line 42

def set_tag(key, val)
  if elastic_span.is_a?(Transaction)
    case key.to_s
    when 'type'
      elastic_span.type = val
    when 'result'
      elastic_span.result = val
    when /user\.(\w+)/
      set_user_value($1, val)
    else
      elastic_span.context.labels[key] = val
    end
  else
    elastic_span.context.labels[key] = val
  end

  self
end