sentry-lambda 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad08bff4fbb6098f51ce9ce99a77284cfa00386c179cfc4e404b5a17f7eaf3f8
4
- data.tar.gz: 932075b39a53866dab84b13b2803dfe1cc67920238d45eb6e1672f0ed59dcbe7
3
+ metadata.gz: 43b6fafbed0760ae029ded6e4355f60f12a452f9ea27f78e4ec9f0aa42ac09bd
4
+ data.tar.gz: 84092e98e21a358016c3ee1a00676b277495e00b46b3fed36c0729b3d5c29d7f
5
5
  SHA512:
6
- metadata.gz: 877fc54307159269887ba1b2694a04eec079fdabf07bfbb487f16bb3e6512bc302a91521342c02b76fbcfa9016dfb73e032b39ce1a6eaf4e68465c06bf5e0910
7
- data.tar.gz: d807cefd42842fb190bb85abb72c8b6ae2324795cb6360fcf2bf68aac1748f16f9e7e50c32fcabd67d384035578d60d0556624edfc424d1971cd184b6abb5fcb
6
+ metadata.gz: fefe3c9173a7f5acf45b60ec4073132b0f85f7db3bdede84865e2af0b2062c4d31a534718e2d119afe4b6fed1ddc2ea03348942f4f2d015bcbfa18f175fa6cae
7
+ data.tar.gz: 7313cc92c8ae7cc65751f15a30119f7300211a5ecac22f332424bf02cad6ddea945637fb9aaafe5a14dccaf89feb5822804bb6ca8301d3e99d58c98b2c5b54be
data/lib/sentry/lambda.rb CHANGED
@@ -1,16 +1,17 @@
1
1
  require "sentry-ruby"
2
2
  require "sentry/integrable"
3
3
  require "sentry/lambda/capture_exceptions"
4
+ require "sentry/lambda/null_context"
4
5
 
5
6
  module Sentry
6
7
  module Lambda
7
8
  extend Integrable
8
9
  register_integration name: 'lambda', version: Sentry::Lambda::VERSION
9
10
 
10
- def self.wrap_handler(event:, context:, capture_timeout_warning: false)
11
+ def self.wrap_handler(event:, context: NullContext.new, capture_timeout_warning: false)
11
12
  CaptureExceptions.new(
12
13
  aws_event: event,
13
- aws_context: context,
14
+ aws_context: context || NullContext.new,
14
15
  capture_timeout_warning: capture_timeout_warning
15
16
  ).call do
16
17
  yield
@@ -3,9 +3,9 @@ module Sentry
3
3
  class CaptureExceptions
4
4
  TIMEOUT_WARNING_BUFFER = 1500 # Buffer time required to send timeout warning to Sentry
5
5
 
6
- def initialize(aws_event:, aws_context:, capture_timeout_warning: false)
6
+ def initialize(aws_event:, aws_context: NullContext.new, capture_timeout_warning: false)
7
7
  @aws_event = aws_event
8
- @aws_context = aws_context
8
+ @aws_context = aws_context || NullContext.new
9
9
  @capture_timeout_warning = capture_timeout_warning
10
10
  end
11
11
 
@@ -30,8 +30,8 @@ module Sentry
30
30
 
31
31
  Sentry.with_scope do |scope|
32
32
  start_time = Time.now.utc
33
- initial_remaining_time_in_milis = @aws_context.get_remaining_time_in_millis
34
- execution_expiration_time = Time.now.utc + ((initial_remaining_time_in_milis || 0)/1000.0)
33
+ initial_remaining_time_in_millis = @aws_context.get_remaining_time_in_millis
34
+ execution_expiration_time = Time.now.utc + ((initial_remaining_time_in_millis || 0)/1000.0)
35
35
 
36
36
  scope.clear_breadcrumbs
37
37
  scope.set_transaction_name(@aws_context.function_name)
@@ -53,7 +53,11 @@ module Sentry
53
53
 
54
54
  event.extra = event.extra.merge(
55
55
  "cloudwatch logs": {
56
- url: _get_cloudwatch_logs_url(@aws_context, start_time),
56
+ url: _get_cloudwatch_logs_url(
57
+ @aws_context.log_group_name,
58
+ @aws_context.log_stream_name,
59
+ start_time
60
+ ),
57
61
  log_group: @aws_context.log_group_name,
58
62
  log_stream: @aws_context.log_stream_name
59
63
  }
@@ -101,12 +105,12 @@ module Sentry
101
105
  Sentry.capture_exception(exception)
102
106
  end
103
107
 
104
- def _get_cloudwatch_logs_url(aws_context, start_time)
108
+ def _get_cloudwatch_logs_url(log_group_name, log_stream_name, start_time)
105
109
  formatstring = "%Y-%m-%dT%H:%M:%SZ"
106
110
  region = ENV['AWS_REGION']
107
111
 
108
112
  "https://console.aws.amazon.com/cloudwatch/home?region=#{region}" \
109
- "#logEventViewer:group=#{aws_context.log_group_name};stream=#{aws_context.log_stream_name}" \
113
+ "#logEventViewer:group=#{log_group_name};stream=#{log_stream_name}" \
110
114
  ";start=#{start_time.strftime(formatstring)};end=#{(Time.now.utc + 2).strftime(formatstring)}"
111
115
  end
112
116
  end
@@ -0,0 +1,27 @@
1
+ module Sentry
2
+ module Lambda
3
+ # This class exists to allow nil to quack like an AWS context object, primarily for the purpose of supporting
4
+ # automated tests which don't supply a context object.
5
+ class NullContext
6
+ def get_remaining_time_in_millis
7
+ 0
8
+ end
9
+
10
+ def function_name
11
+ 'n/a'
12
+ end
13
+
14
+ def function_version
15
+ 'n/a'
16
+ end
17
+
18
+ def invoked_function_arn
19
+ 'n/a'
20
+ end
21
+
22
+ def aws_request_id
23
+ 'n/a'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Lambda
3
- VERSION = "0.1.2"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sentry-ruby-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.4.0.pre.beta
19
+ version: 4.5.0.pre.beta.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.4.0.pre.beta
26
+ version: 4.5.0.pre.beta.1
27
27
  description: A gem that provides AWS Lambda integration for the Sentry error logger
28
28
  email: gateway@paymentspring.com
29
29
  executables: []
@@ -37,6 +37,7 @@ files:
37
37
  - lib/sentry-lambda.rb
38
38
  - lib/sentry/lambda.rb
39
39
  - lib/sentry/lambda/capture_exceptions.rb
40
+ - lib/sentry/lambda/null_context.rb
40
41
  - lib/sentry/lambda/version.rb
41
42
  homepage: https://github.com/paymentspring/sentry-ruby
42
43
  licenses: