gn-tracker 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6d17c1fe62491b91eba0a5e0e7369b7acd20b10ee37675ea333e2e0b13baef0
4
+ data.tar.gz: 99523c2972eaf4bcd9161c18312fa2e1a425fafacbffeb4577d7c6f2d636d8dd
5
+ SHA512:
6
+ metadata.gz: f72a03588f668e0fc2a6df6c8d3bb4bf8351eb993ff4a09d492d098eeef6fb5a3f5c3fe09fa2072b308288eb6f01762b15217805a5b7949fcab893443c5dc4f7
7
+ data.tar.gz: c31a0ecfacc2a2972fe333bc31bb4f863babf8f77cee2316d6f7b14c87ef4695ffa45bc65a2dfa9339957f32dbae4fd5a7ff5dcaf80f5b84e959ab2bdf340ad6
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ /.bundle
3
+ /tmp
4
+ /vendor/bundle
@@ -0,0 +1,83 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - bin/*
8
+ - config.ru
9
+ - config/application.rb
10
+ - config/boot.rb
11
+ - config/environment.rb
12
+ - config/environments/development.rb
13
+ - config/environments/production.rb
14
+ - config/environments/test.rb
15
+ - config/initializers/airbrake.rb
16
+ - config/initializers/application_controller_renderer.rb
17
+ - config/initializers/backtrace_silencers.rb
18
+ - config/initializers/cookies_serializer.rb
19
+ - config/initializers/filter_parameter_logging.rb
20
+ - config/initializers/inflections.rb
21
+ - config/initializers/mime_types.rb
22
+ - config/initializers/wrap_parameters.rb
23
+ - config/puma.rb
24
+ - config/spring.rb
25
+ - db/schema.rb
26
+ - db/seeds/**/*
27
+ - Gemfile.lock
28
+ - Rakefile
29
+ - script/rails
30
+
31
+ Documentation:
32
+ Enabled: false
33
+
34
+ Metrics/BlockLength:
35
+ Exclude:
36
+ - "spec/**/*"
37
+
38
+ Metrics/LineLength:
39
+ Max: 120
40
+
41
+ Naming/VariableNumber:
42
+ EnforcedStyle: snake_case
43
+
44
+ RSpec/EmptyExampleGroup:
45
+ Exclude:
46
+ - spec/factories/*
47
+
48
+ RSpec/EmptyLineAfterExampleGroup:
49
+ Exclude:
50
+ - spec/factories/*
51
+
52
+ RSpec/MissingExampleGroupArgument:
53
+ Exclude:
54
+ - spec/factories/*
55
+
56
+ SpaceAroundEqualsInParameterDefault:
57
+ EnforcedStyle: space
58
+
59
+ Style/Lambda:
60
+ EnforcedStyle: literal
61
+
62
+ Style/PercentLiteralDelimiters:
63
+ PreferredDelimiters:
64
+ '%i': '[]'
65
+ '%I': '[]'
66
+ '%r': ()
67
+ '%w': '[]'
68
+ '%W': '[]'
69
+
70
+ Style/PercentQLiterals:
71
+ EnforcedStyle: upper_case_q
72
+
73
+ Style/StringLiterals:
74
+ EnforcedStyle: double_quotes
75
+
76
+ Style/StringLiteralsInInterpolation:
77
+ EnforcedStyle: double_quotes
78
+
79
+ Style/TrailingCommaInArrayLiteral:
80
+ EnforcedStyleForMultiline: comma
81
+
82
+ Style/TrailingCommaInHashLiteral:
83
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1,5 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/getninjas/dotfiles/master/.rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.5
@@ -0,0 +1,7 @@
1
+ # Contributor Code of Conduct
2
+
3
+ The GetNinjas team is committed to fostering a welcoming community.
4
+
5
+ **Our Code of Conduct can be found here**:
6
+
7
+ https://www.contributor-covenant.org/version/1/4/code-of-conduct
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gn-tracker (0.4.0)
5
+ logstash-logger
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ byebug (11.0.1)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ jaro_winkler (1.5.3)
15
+ logstash-event (1.2.02)
16
+ logstash-logger (0.26.1)
17
+ logstash-event (~> 1.2)
18
+ method_source (0.9.2)
19
+ parallel (1.17.0)
20
+ parser (2.6.4.1)
21
+ ast (~> 2.4.0)
22
+ pry (0.12.2)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.9.0)
25
+ pry-byebug (3.7.0)
26
+ byebug (~> 11.0)
27
+ pry (~> 0.10)
28
+ rainbow (3.0.0)
29
+ rake (13.0.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.2)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.5)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.3)
43
+ rubocop (0.75.0)
44
+ jaro_winkler (~> 1.5.1)
45
+ parallel (~> 1.10)
46
+ parser (>= 2.6)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 1.7)
50
+ rubocop-performance (1.5.0)
51
+ rubocop (>= 0.71.0)
52
+ rubocop-rspec (1.36.0)
53
+ rubocop (>= 0.68.1)
54
+ ruby-progressbar (1.10.1)
55
+ unicode-display_width (1.6.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler
62
+ gn-tracker!
63
+ pry-byebug
64
+ rake
65
+ rspec
66
+ rubocop-performance
67
+ rubocop-rspec
68
+
69
+ BUNDLED WITH
70
+ 1.17.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 GetNinjas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ ### Installation
2
+
3
+ ```ruby
4
+ gem 'gn-tracker'
5
+ ```
6
+
7
+ ### Configuration
8
+
9
+ ```ruby
10
+ require "gn/tracker"
11
+
12
+ Gn::Tracker.configure do |config|
13
+ config.application = "YourApp"
14
+ config.path = "/var/www/example/shared/logstash"
15
+ end
16
+ ```
17
+
18
+ ### Unstruct Event
19
+
20
+ Just call `track_unstruct_event` method:
21
+
22
+ ```ruby
23
+ require "gn/tracker"
24
+
25
+ tracker = Gn::Tracker.new
26
+ tracker.track_unstruct_event(message: { a: 1 }, schema: "iglu:br.com.example.com/schema/1.0.0")
27
+ ```
28
+
29
+ The attributes `message` and `schema` are mandatory. If you want to send an event for a different application, you can specify an `application`:
30
+
31
+ ```ruby
32
+ require "gn/tracker"
33
+
34
+ tracker = Gn::Tracker.new
35
+
36
+ tracker.track_unstruct_event(
37
+ message: { a: 1 },
38
+ schema: "iglu:br.com.example.com/schema/1.0.0",
39
+ application: "Kituno"
40
+ )
41
+ ```
42
+
43
+ You can pass the argument `true_timestamp` (in milliseconds):
44
+
45
+ ```ruby
46
+ require "gn/tracker"
47
+
48
+ tracker = Gn::Tracker.new
49
+ tracker.track_unstruct_event(
50
+ message: { a: 1 },
51
+ schema: "iglu:br.com.example.com/schema/1.0.0",
52
+ application: "Kituno",
53
+ true_timestamp: "1509471096577"
54
+ )
55
+ ```
56
+
57
+ and pass the argument `contexts` (array with aditional contexts):
58
+
59
+ ```ruby
60
+ require "gn/tracker"
61
+
62
+ contexts = [
63
+ {
64
+ schema: "iglu:br.com.example.com/another_schema/1.0.0",
65
+ message: { b: 2 }
66
+ },
67
+
68
+ {
69
+ schema: "iglu:br.com.example.com/third_schema/1.0.0",
70
+ message: { c: 3 }
71
+ }
72
+ ]
73
+
74
+ tracker = Gn::Tracker.new
75
+
76
+ tracker.track_unstruct_event(
77
+ message: { a: 1 },
78
+ schema: "iglu:br.com.example.com/schema/1.0.0",
79
+ application: "Kituno",
80
+ contexts: contexts
81
+ )
82
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gn/tracker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'gn/tracker/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.authors = ["GetNinjas"]
9
+ spec.bindir = "exe"
10
+ spec.email = ["tech@getninjas.com.br"]
11
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
12
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ spec.homepage = "http://www.getninjas.com.br"
14
+ spec.license = "MIT"
15
+ spec.name = "gn-tracker"
16
+ spec.require_paths = ["lib"]
17
+ spec.summary = "Gem which encapsulates logstash-logger"
18
+ spec.version = Gn::Tracker::VERSION
19
+
20
+ spec.add_runtime_dependency "logstash-logger"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rubocop-performance"
27
+ spec.add_development_dependency "rubocop-rspec"
28
+ end
@@ -0,0 +1,52 @@
1
+ require "gn/tracker/version"
2
+ require "logstash-logger"
3
+
4
+ module Gn
5
+ class Tracker
6
+ class << self
7
+ attr_writer :configuration
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+
18
+ def initialize
19
+ @logger = LogStashLogger.new(
20
+ type: :file,
21
+ sync: true,
22
+ path: self.class.configuration.path
23
+ )
24
+ end
25
+
26
+ def track_unstruct_event(
27
+ message:,
28
+ schema:,
29
+ application: self.class.configuration.application,
30
+ true_timestamp: DateTime.now.strftime('%Q'),
31
+ contexts: []
32
+ )
33
+ event = LogStash::Event.new(
34
+ message: message.to_json,
35
+ application: application,
36
+ schema: schema,
37
+ true_timestamp: true_timestamp,
38
+ contexts: contexts.to_json
39
+ )
40
+ @logger.info event
41
+ end
42
+
43
+ class Configuration
44
+ attr_accessor :application, :path
45
+
46
+ def initialize
47
+ @application = ENV.fetch('GN_TRACKER_APPLICATION') { 'GN_TRACKER' }
48
+ @path = '/tmp/logstash'
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gn
4
+ class Tracker
5
+ VERSION = "0.4.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gn-tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - GetNinjas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
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: rubocop-rspec
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'
111
+ description:
112
+ email:
113
+ - tech@getninjas.com.br
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rubocop-https---raw-githubusercontent-com-getninjas-dotfiles-master--rubocop-yml"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - gn-tracker.gemspec
131
+ - lib/gn/tracker.rb
132
+ - lib/gn/tracker/version.rb
133
+ homepage: http://www.getninjas.com.br
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Gem which encapsulates logstash-logger
156
+ test_files: []