Module: ElasticAPM::Spies::SNSSpy::Ext Private

Defined in:
lib/elastic_apm/spies/sns.rb

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

Instance Method Summary collapse

Instance Method Details

#publish(params = {}, options = {}) ⇒ 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.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/elastic_apm/spies/sns.rb', line 78

def publish(params = {}, options = {})
  unless (transaction = ElasticAPM.current_transaction)
    return super(params, options)
  end

  topic = ElasticAPM::Spies::SNSSpy.get_topic(params)
  span_name = topic ? "SNS PUBLISH to #{topic}" : 'SNS PUBLISH'
  region = ElasticAPM::Spies::SNSSpy.arn_region(
    params[:topic_arn] || params[:target_arn]
  )
  context = ElasticAPM::Spies::SNSSpy.span_context(
    topic,
    region || config.region
  )

  ElasticAPM.with_span(
    span_name,
    TYPE,
    subtype: SUBTYPE,
    action: 'publish',
    context: context
  ) do |span|
    trace_context = span&.trace_context || transaction.trace_context
    trace_context.apply_headers do |key, value|
      params[:message_attributes] ||= {}
      params[:message_attributes][key] ||= {}
      params[:message_attributes][key][:string_value] = value
      params[:message_attributes][key][:data_type] = 'String'
    end

    ElasticAPM::Spies::SNSSpy.without_net_http do
      super(params, options)
    end
  end
end