Class: Appsignal::CustomMarker

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/custom_marker.rb

Overview

Custom markers are used on AppSignal.com to indicate events in an application, to give additional context on graph timelines.

This helper class will send a request to the AppSignal public endpoint to create a Custom marker for the application on AppSignal.com.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(marker_data) ⇒ CustomMarker

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 CustomMarker.



36
37
38
# File 'lib/appsignal/custom_marker.rb', line 36

def initialize(marker_data)
  @marker_data = marker_data
end

Class Method Details

.report(icon: nil, message: nil, created_at: nil) ⇒ Boolean

Parameters:

  • icon (String) (defaults to: nil)

    icon to use for the marker, like an emoji.

  • message (String) (defaults to: nil)

    name of the user that is creating the marker.

  • created_at (Time/String) (defaults to: nil)

    A Ruby time object or a valid ISO8601 timestamp.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appsignal/custom_marker.rb', line 21

def self.report(
  icon: nil,
  message: nil,
  created_at: nil
)
  new(
    {
      :icon => icon,
      :message => message,
      :created_at => created_at.respond_to?(:iso8601) ? created_at.iso8601 : created_at
    }.compact
  ).transmit
end

Instance Method Details

#transmitObject

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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/appsignal/custom_marker.rb', line 41

def transmit
  unless Appsignal.config
    Appsignal.internal_logger.warn(
      "Did not transmit custom marker: no AppSignal config loaded"
    )
    return false
  end

  transmitter = Transmitter.new(
    "#{Appsignal.config[:logging_endpoint]}/markers",
    Appsignal.config
  )
  response = transmitter.transmit(@marker_data)

  if (200...300).include?(response.code.to_i)
    Appsignal.internal_logger.info("Transmitted custom marker")
    true
  else
    Appsignal.internal_logger.error(
      "Failed to transmit custom marker: #{response.code} status code"
    )
    false
  end
rescue => e
  Appsignal.internal_logger.error(
    "Failed to transmit custom marker: #{e.class}: #{e.message}\n" \
      "#{e.backtrace}"
  )
  false
end