govuk_app_config 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 392722d9260ccaa86d8c644cc18c744f68fff73e
4
- data.tar.gz: 1ac8c30697b380b69c1650afa4867240409a433a
3
+ metadata.gz: '089341e237b45993c1de26ae8fcc53b765c37f1f'
4
+ data.tar.gz: '096f6ff793400709eaf33bd73efcacb0068896d0'
5
5
  SHA512:
6
- metadata.gz: 2a6386a6e6283f987a671948f2ddbfd69662f18fd4df1f974a5ed5f4578e8e3901859920d9ff1ddc5e3770bb5826c445624da644715b1ac5bd711b2ad942c954
7
- data.tar.gz: c33474d08b24146bf1c47f364d74b7c43cb93fcc29abbecdde830d0c927b4d3308c52797d18153d1fb48e9eac2c89f1845189acb7cd69d07ca4c6d39018c791c
6
+ metadata.gz: 84d313cb9e2ae553f7a87184578b7cb6946e963cd132614736c0b9e4ad7b49e37e2602bbf14cf3723ce3fb1a3b59e9cedf440a9077859edbbccc42284dc062bc
7
+ data.tar.gz: 5e00d1dee3208dd26ddec7046f6bf7ab3049c840bb5975a9ffd49ad7f43a1753d1f5304337cbc3b32786f788b6a115590a5f2e7e2799d7a17fcdc6b5632229da
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ spec/examples.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ * First actual release with support for Sentry
6
+
7
+ ## 0.1.0
8
+
9
+ Empty gem.
data/README.md CHANGED
@@ -14,6 +14,47 @@ And then execute:
14
14
 
15
15
  ## Usage
16
16
 
17
+ ### Automatic error reporting
18
+
19
+ If you include `govuk_app_config` in your `Gemfile`, Rails' autoloading mechanism will make sure that your application is configured to send errors Sentry.
20
+
21
+ If you use the gem outside of Rails you'll have to explicitly require it:
22
+
23
+ ```rb
24
+ require 'govuk_app_config/configure'
25
+ ```
26
+
27
+ Your app will have to have the following environment variables set:
28
+
29
+ - `SENTRY_DSN` - the [Data Source Name (DSN)][dsn] for Sentry
30
+ - `SENTRY_CURRENT_ENV` - production, staging or integration
31
+ - `GOVUK_STATSD_PREFIX` - a Statsd prefix like `govuk.apps.application-name`
32
+
33
+ [dsn]: https://docs.sentry.io/quickstart/#about-the-dsn
34
+
35
+ ### Manual error reporting
36
+
37
+ Report something to Sentry manually:
38
+
39
+ ```rb
40
+ GovukError.notify("Something went terribly wrong")
41
+ ```
42
+
43
+ ```rb
44
+ GovukError.notify(ArgumentError.new("Or some exception object"))
45
+ ```
46
+
47
+ Extra parameters are:
48
+
49
+ ```rb
50
+ GovukError.notify(
51
+ "Oops",
52
+ extra: { offending_content_id: '123' }, # Additional context for this event. Must be a hash. Children can be any native JSON type.
53
+ level: 'debug', # debug, info, warning, error, fatal
54
+ tags: { key: 'value' } # Tags to index with this event. Must be a mapping of strings.
55
+ )
56
+ ```
57
+
17
58
  ## License
18
59
 
19
60
  [MIT License][LICENSE.md]
@@ -21,7 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.add_dependency "statsd-ruby", "~> 1.4.0"
25
+ spec.add_dependency "sentry-raven", "~> 2.6.3"
26
+
24
27
  spec.add_development_dependency "bundler", "~> 1.15"
25
28
  spec.add_development_dependency "rake", "~> 10.0"
26
29
  spec.add_development_dependency "rspec", "~> 3.6.0"
30
+ spec.add_development_dependency "climate_control"
31
+ spec.add_development_dependency "webmock"
27
32
  end
@@ -1,4 +1,4 @@
1
1
  require "govuk_app_config/version"
2
-
3
- module GovukAppConfig
4
- end
2
+ require "govuk_app_config/govuk_statsd"
3
+ require "govuk_app_config/govuk_error"
4
+ require "govuk_app_config/configure"
@@ -0,0 +1,24 @@
1
+ if defined?(Airbrake)
2
+ raise "This gem isn't compatible with Airbrake. Please remove it from the Gemfile."
3
+ end
4
+
5
+ Raven.configure do |config|
6
+ # We need this until https://github.com/getsentry/raven-ruby/pull/736 is released
7
+ config.current_environment = ENV["SENTRY_CURRENT_ENV"]
8
+
9
+ # We're misusing the `should_capture` block here to hook into raven until
10
+ # there's a better way: https://github.com/getsentry/raven-ruby/pull/750
11
+ config.should_capture = Proc.new {
12
+ GovukStatsd.increment("errors_occurred")
13
+
14
+ # For backwards compatibility
15
+ GovukStatsd.increment("errbit.errors_occurred")
16
+
17
+ # Return true so that we don't accidentally skip the error
18
+ true
19
+ }
20
+
21
+ config.transport_failure_callback = Proc.new {
22
+ GovukStatsd.increment("error_reports_failed")
23
+ }
24
+ end
@@ -0,0 +1,13 @@
1
+ require "sentry-raven"
2
+ require "govuk_app_config/govuk_statsd"
3
+
4
+ module GovukError
5
+ def self.notify(exception_or_message, args = {})
6
+ # Allow users to use `parameters` as a key like the Airbrake
7
+ # client, allowing easy upgrades.
8
+ args[:extra] ||= {}
9
+ args[:extra].merge!(parameters: args.delete(:parameters))
10
+
11
+ Raven.capture_exception(exception_or_message, args)
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require "statsd"
2
+
3
+ module GovukStatsd
4
+ def self.increment(*args)
5
+ client.increment(*args)
6
+ end
7
+
8
+ def self.client
9
+ @statsd_client ||= begin
10
+ statsd_client = ::Statsd.new("localhost")
11
+ statsd_client.namespace = ENV["GOVUK_STATSD_PREFIX"].to_s
12
+ statsd_client
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -10,6 +10,34 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: statsd-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sentry-raven
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.6.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.3
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,34 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: 3.6.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: climate_control
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
55
111
  description: Base configuration for GOV.UK applications
56
112
  email:
57
113
  - govuk-dev@digital.cabinet-office.gov.uk
@@ -62,6 +118,7 @@ files:
62
118
  - ".gitignore"
63
119
  - ".rspec"
64
120
  - ".ruby-version"
121
+ - CHANGELOG.md
65
122
  - Gemfile
66
123
  - Jenkinsfile
67
124
  - LICENSE.md
@@ -71,6 +128,9 @@ files:
71
128
  - bin/setup
72
129
  - govuk_app_config.gemspec
73
130
  - lib/govuk_app_config.rb
131
+ - lib/govuk_app_config/configure.rb
132
+ - lib/govuk_app_config/govuk_error.rb
133
+ - lib/govuk_app_config/govuk_statsd.rb
74
134
  - lib/govuk_app_config/version.rb
75
135
  homepage: https://github.com/alphagov/govuk_app_config
76
136
  licenses: