bugloco 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: b5679112575fa2fbe7e3c7772015ea3d7da268de
4
- data.tar.gz: 2c9c8eefbb3fdda13a5db613f61fce766d267299
3
+ metadata.gz: f77f2e45084fd90245873bae6177592eab5c0cfa
4
+ data.tar.gz: 26e56be260f658a023966e125490bcb71ccb1997
5
5
  SHA512:
6
- metadata.gz: ce19403311ddd6a37dbbdd1d5ed8d93812333650de17a65ebbd93e51b2aae8ce4fb3d27ba7043c788ca88d83275d7e642a93c018079987138b81b017d2f8fbbd
7
- data.tar.gz: 51fa242e0a98946f031924831c13cdd05c3fa5878b99229a15353ffbbc1fe8af1020a07ffed5db7f1639ce1d2a4c786a651951d16e82ba6ad7161567f0e281df
6
+ metadata.gz: 1275e34393868460335ff64794d38cf591118dab58645441448b16c9c38eac5f2c3c58e7b20f977e76171da5f5c52c34217bded77d15e442967b29b4cf9c5868
7
+ data.tar.gz: 41656a91b8b9f55dba3becea2e62ab8d9966249262d139e76290cc58d9d8b47712458afedb53297d5cec3271df41a24b3e919260cb3f265a3624cc2af0323e8d
@@ -0,0 +1,25 @@
1
+ module Bugloco
2
+ class Cache
3
+ NAMESPACE = "bugloco"
4
+
5
+ class << self
6
+ def reset!
7
+ Thread.current[NAMESPACE] = {}
8
+ end
9
+
10
+ def get(key)
11
+ value = Thread.current[NAMESPACE][key] rescue nil
12
+
13
+ if block_given?
14
+ yield value
15
+ else
16
+ return value
17
+ end
18
+ end
19
+
20
+ def set(key, value)
21
+ Thread.current[NAMESPACE][key] = value
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,4 @@
1
+ require "bugloco/cache"
1
2
  require "bugloco/protobuf/bugloco.pb"
2
3
  require "rack"
3
4
  require "socket"
@@ -46,12 +47,26 @@ module Bugloco
46
47
  load_server_info
47
48
  load_backtrace
48
49
  load_stack
50
+ load_custom
49
51
 
50
52
  @proto_message
51
53
  end
52
54
 
53
55
  private
54
56
 
57
+ def load_custom
58
+ return unless Bugloco.config.custom_keys
59
+
60
+ Bugloco.config.custom_keys.each do |custom_key|
61
+ value = Bugloco::Cache.get(custom_key) || ""
62
+
63
+ @proto_message.custom << Bugloco::Proto::Pair.new(
64
+ key: custom_key.to_s,
65
+ value: value.to_s,
66
+ )
67
+ end
68
+ end
69
+
55
70
  def load_stack
56
71
  @proto_message.stack = Bugloco.config.stack
57
72
  end
@@ -1,26 +1,26 @@
1
1
  ### Generated by rprotoc. DO NOT EDIT!
2
2
  ### <proto file: /home/wmn/code/bugloco/bugloco-rb/protobufs/bugloco.proto>
3
3
  # syntax = "proto2";
4
- #
4
+ #
5
5
  # package bugloco.proto;
6
- #
6
+ #
7
7
  # enum LocationType {
8
8
  # UNKNOWN = 0;
9
9
  # PROJECT = 1;
10
10
  # GEM = 2;
11
11
  # }
12
- #
12
+ #
13
13
  # enum RunningMode {
14
14
  # TEST = 0;
15
15
  # STAGING = 1;
16
16
  # PRODUCTION = 2;
17
17
  # }
18
- #
18
+ #
19
19
  # enum Status {
20
20
  # SUCCESS = 0;
21
21
  # FAILURE = 1;
22
22
  # }
23
- #
23
+ #
24
24
  # enum ErrorCode {
25
25
  # UNKNOWN_ERROR = 0;
26
26
  # API_KEY_INVALID = 1;
@@ -29,7 +29,7 @@
29
29
  # INVALID_PROTO_MESSAGE = 4;
30
30
  # PROBLEM_PERSISTING_NOTICE = 5;
31
31
  # }
32
- #
32
+ #
33
33
  # message BacktraceEntry {
34
34
  # required bugloco.proto.LocationType location_type = 1;
35
35
  # required string full_path = 2;
@@ -37,38 +37,38 @@
37
37
  # required int32 line_number = 4;
38
38
  # required string function_name = 5;
39
39
  # }
40
- #
40
+ #
41
41
  # message Company {
42
42
  # required string api_key = 1;
43
43
  # }
44
- #
44
+ #
45
45
  # message Project {
46
46
  # required string key = 1;
47
47
  # optional string framework = 2;
48
48
  # optional string version = 3;
49
49
  # }
50
- #
50
+ #
51
51
  # message Pair {
52
52
  # required string key = 1;
53
53
  # required string value = 2;
54
54
  # }
55
- #
55
+ #
56
56
  # message Server {
57
57
  # required string hostname = 1;
58
58
  # optional string os = 2;
59
59
  # }
60
- #
60
+ #
61
61
  # message Notifier {
62
62
  # required string name = 1;
63
63
  # required string version = 2;
64
64
  # }
65
- #
65
+ #
66
66
  # message User {
67
67
  # optional string remote_ip = 1;
68
68
  # optional string remote_host = 2;
69
69
  # optional string user_agent = 3;
70
70
  # }
71
- #
71
+ #
72
72
  # message Request {
73
73
  # repeated bugloco.proto.Pair environment_variables = 1;
74
74
  # repeated bugloco.proto.Pair parameters = 2;
@@ -78,7 +78,7 @@
78
78
  # optional string url = 6;
79
79
  # optional string referer = 7;
80
80
  # }
81
- #
81
+ #
82
82
  # message Notice {
83
83
  # required bugloco.proto.Company company = 1;
84
84
  # required bugloco.proto.Project project = 2;
@@ -90,13 +90,14 @@
90
90
  # optional string stack = 8;
91
91
  # optional bugloco.proto.RunningMode running_mode = 9;
92
92
  # optional bugloco.proto.Server server = 10;
93
+ # repeated bugloco.proto.Pair custom = 11;
93
94
  # }
94
- #
95
+ #
95
96
  # message ErrorMessage {
96
97
  # required string field = 1;
97
98
  # required string message = 2;
98
99
  # }
99
- #
100
+ #
100
101
  # message Response {
101
102
  # required bugloco.proto.Status status = 1;
102
103
  # optional string notice_key = 2;
@@ -198,6 +199,7 @@ module Bugloco
198
199
  optional :string, :stack, 8
199
200
  optional :'bugloco::proto::RunningMode', :running_mode, 9
200
201
  optional :'bugloco::proto::Server', :server, 10
202
+ repeated :'bugloco::proto::Pair', :custom, 11
201
203
  end
202
204
  class ErrorMessage < ::Protobuf::Message
203
205
  defined_in __FILE__
@@ -212,4 +214,4 @@ module Bugloco
212
214
  repeated :'bugloco::proto::ErrorMessage', :error_messages, 4
213
215
  end
214
216
  end
215
- end
217
+ end
@@ -1,3 +1,5 @@
1
+ require "bugloco/cache"
2
+
1
3
  module Bugloco
2
4
  module Rails
3
5
  class Middleware
@@ -6,6 +8,8 @@ module Bugloco
6
8
  end
7
9
 
8
10
  def call(env)
11
+ Bugloco::Cache.reset!
12
+
9
13
  response = @app.call(env)
10
14
 
11
15
  if framework_exception = env["action_dispatch.exception"]
@@ -1,3 +1,3 @@
1
1
  module Bugloco
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -88,6 +88,7 @@ message Notice {
88
88
  optional string stack = 8;
89
89
  optional bugloco.proto.RunningMode running_mode = 9;
90
90
  optional bugloco.proto.Server server = 10;
91
+ repeated bugloco.proto.Pair custom = 11;
91
92
  }
92
93
 
93
94
  message ErrorMessage {
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+ require "bugloco/cache"
3
+
4
+ describe Bugloco::Cache do
5
+ context "#reset!" do
6
+ it "should set the namespace in the current thread to an empty Hash" do
7
+ Bugloco::Cache.reset!
8
+ expect(Thread.current[Bugloco::Cache::NAMESPACE]).to eq({})
9
+ end
10
+ end
11
+
12
+ context "#set" do
13
+ it "should set the key/value in the current thread" do
14
+ Bugloco::Cache.set(:key, "value")
15
+ expect(Thread.current[Bugloco::Cache::NAMESPACE][:key]).to eq("value")
16
+ end
17
+ end
18
+
19
+ context "#get" do
20
+ before do
21
+ @key = :key
22
+ @value = "value"
23
+ Bugloco::Cache.set(@key, @value)
24
+ end
25
+
26
+ it "should be able to get a key/value that was already set" do
27
+ expect(Bugloco::Cache.get(@key)).to eq(@value)
28
+ end
29
+
30
+ it "should yield the value if a block is given" do
31
+ Bugloco::Cache.get(@key) do |value|
32
+ expect(value).to eq(@value)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -124,6 +124,34 @@ describe Bugloco::Notice do
124
124
  expect(@notice_proto_message.server).to eq(expected)
125
125
  end
126
126
 
127
+ context "custom pairs" do
128
+ before do
129
+ Bugloco.config do |config|
130
+ config.custom_keys = [:user_id]
131
+ end
132
+ end
133
+
134
+ it "should include the custom keys with empty value if value was not set" do
135
+ Bugloco::Cache.reset!
136
+ run_rack_app
137
+
138
+ expected = [Bugloco::Proto::Pair.new(key:"user_id", value: "")]
139
+
140
+ expect(@notice_proto_message.custom).to eq(expected)
141
+ end
142
+
143
+ it "should include the custom pairs" do
144
+ Bugloco::Cache.reset!
145
+ Bugloco::Cache.set(:user_id, "123")
146
+
147
+ run_rack_app
148
+
149
+ expected = [Bugloco::Proto::Pair.new(key:"user_id", value: "123")]
150
+
151
+ expect(@notice_proto_message.custom).to eq(expected)
152
+ end
153
+ end
154
+
127
155
  context "rack" do
128
156
  it "should extract the parameters from action dispatch" do
129
157
  run_rack_app :action_dispatch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugloco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wael M. Nasreddine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - bugloco.gemspec
126
126
  - lib/bugloco.rb
127
+ - lib/bugloco/cache.rb
127
128
  - lib/bugloco/configuration.rb
128
129
  - lib/bugloco/notice.rb
129
130
  - lib/bugloco/protobuf/bugloco.pb.rb
@@ -132,6 +133,7 @@ files:
132
133
  - lib/bugloco/railtie.rb
133
134
  - lib/bugloco/version.rb
134
135
  - protobufs/bugloco.proto
136
+ - spec/bugloco/cache_spec.rb
135
137
  - spec/bugloco/configuration_spec.rb
136
138
  - spec/bugloco/notice_spec.rb
137
139
  - spec/bugloco_spec.rb
@@ -161,6 +163,7 @@ signing_key:
161
163
  specification_version: 4
162
164
  summary: Bugloco ruby gem for sending exceptions to Bugloco
163
165
  test_files:
166
+ - spec/bugloco/cache_spec.rb
164
167
  - spec/bugloco/configuration_spec.rb
165
168
  - spec/bugloco/notice_spec.rb
166
169
  - spec/bugloco_spec.rb