Class: Bugstack::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/bugstack/event.rb

Overview

Represents an error event to be sent to BugStack.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, stack_trace: "", file: "", function: "", fingerprint: "", exception_type: "", request: nil, environment: nil, timestamp: nil, metadata: {}) ⇒ Event

Returns a new instance of Event.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bugstack/event.rb', line 12

def initialize(
  message:,
  stack_trace: "",
  file: "",
  function: "",
  fingerprint: "",
  exception_type: "",
  request: nil,
  environment: nil,
  timestamp: nil,
  metadata: {}
)
  @message = message
  @stack_trace = stack_trace
  @file = file
  @function = function
  @fingerprint = fingerprint
  @exception_type = exception_type
  @request = request
  @environment = environment || default_environment
  @timestamp = timestamp || Time.now.utc.iso8601
  @metadata =  || {}
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def environment
  @environment
end

#exception_typeObject

Returns the value of attribute exception_type.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def exception_type
  @exception_type
end

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def file
  @file
end

#fingerprintObject

Returns the value of attribute fingerprint.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def fingerprint
  @fingerprint
end

#functionObject

Returns the value of attribute function.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def function
  @function
end

#messageObject

Returns the value of attribute message.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def message
  @message
end

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def 
  @metadata
end

#requestObject

Returns the value of attribute request.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def request
  @request
end

#stack_traceObject

Returns the value of attribute stack_trace.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def stack_trace
  @stack_trace
end

#timestampObject

Returns the value of attribute timestamp.



9
10
11
# File 'lib/bugstack/event.rb', line 9

def timestamp
  @timestamp
end

Instance Method Details

#to_payload(config) ⇒ Hash

Serialize to the standard BugStack API payload.

Parameters:

Returns:

  • (Hash)


40
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
71
72
73
74
75
# File 'lib/bugstack/event.rb', line 40

def to_payload(config)
  payload = {
    "apiKey" => config.api_key,
    "error" => {
      "message" => @message,
      "stackTrace" => @stack_trace,
      "file" => @file,
      "function" => @function,
      "fingerprint" => @fingerprint
    },
    "environment" => {
      "language" => @environment[:language],
      "languageVersion" => @environment[:language_version],
      "framework" => @environment[:framework].to_s,
      "frameworkVersion" => @environment[:framework_version].to_s,
      "os" => @environment[:os],
      "sdkVersion" => @environment[:sdk_version]
    },
    "timestamp" => @timestamp
  }

  if @request
    payload["request"] = {
      "route" => @request[:route].to_s,
      "method" => @request[:method].to_s
    }
  end

  payload["projectId"] = config.project_id unless config.project_id.empty?

  meta = @metadata.dup
  meta["autoFix"] = true if config.auto_fix
  payload["metadata"] = meta unless meta.empty?

  payload
end