Class: Sbmt::KafkaProducer::Instrumentation::OpenTelemetryTracer

Inherits:
Object
  • Object
show all
Defined in:
lib/sbmt/kafka_producer/instrumentation/open_telemetry_tracer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.enabled=(value) ⇒ Object (writeonly)

Sets the attribute enabled

Parameters:

  • value

    the value to set the attribute enabled to.



12
13
14
# File 'lib/sbmt/kafka_producer/instrumentation/open_telemetry_tracer.rb', line 12

def enabled=(value)
  @enabled = value
end

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/sbmt/kafka_producer/instrumentation/open_telemetry_tracer.rb', line 8

def enabled?
  !!@enabled
end

Instance Method Details

#call(message) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sbmt/kafka_producer/instrumentation/open_telemetry_tracer.rb', line 19

def call(message)
  return message unless enabled?

  topic = message[:topic]
  attributes = {
    "messaging.system" => "kafka",
    "messaging.destination" => topic,
    "messaging.destination_kind" => "topic"
  }

  message_key = extract_message_key(message[:key])
  attributes["messaging.kafka.message_key"] = message_key if message_key

  message[:headers] ||= {}

  tracer.in_span("#{topic} publish", attributes: attributes, kind: :producer) do
    ::OpenTelemetry.propagation.inject(message[:headers])
  end

  message
end

#enabled?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/sbmt/kafka_producer/instrumentation/open_telemetry_tracer.rb', line 15

def enabled?
  self.class.enabled?
end