Class: Fluent::Plugin::SentryOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_sentry.rb

Instance Method Summary collapse

Instance Method Details

#create_sentry_event_ingestion_urlObject



113
114
115
# File 'lib/fluent/plugin/out_sentry.rb', line 113

def create_sentry_event_ingestion_url
  "#{@ingest_url}/api/#{@project_id}/store/?sentry_key=#{@auth_token}&sentry_version=7"
end

#send_to_sentry(record, time) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fluent/plugin/out_sentry.rb', line 117

def send_to_sentry(record, time)
  event = SentryMessageFormat.new(
    record['timestamp'] || Time.at(time).to_i || Time.now.to_i,
    SecureRandom.hex(16),
    record['component_name'] || nil,
    record['environment'] || nil,
    record['commitId'] || nil,
    record['tags'] || nil,
    record['request'] || nil,
    record['exception'] || nil,
    record['platform'] || 'node',
    record['transaction'] || nil
  )

  url = create_sentry_event_ingestion_url
  request_payload = event.to_json

  log.debug 'Sending payload - ', request_payload, ' to - ', url
  Net::HTTP.post(URI(url), request_payload)
end

#write(chunk) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/fluent/plugin/out_sentry.rb', line 102

def write(chunk)
  chunk.each do |time, record|
    log.debug time, record
    begin
      send_to_sentry(record, time)
    rescue => e
      log.error 'Unable to send event to Sentry, Err class - ', e.class, ', error message - ', e.message
    end
  end
end