sequel-honeycomb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 563059aeb0bcc2c53d36bc14456ac6346bdacda5
4
+ data.tar.gz: 841c083196afe773b21876ad7d264c46850ef0c9
5
+ SHA512:
6
+ metadata.gz: 50c72255601b002aa62efb5642a6d95dc1550a4d3c07a3f5daf839a42cb1ea153b74d08b75c071aef44159784f7199e3293bd399e9c2fe85e491085e72234ac8
7
+ data.tar.gz: 4d95721e25438a29577250a473714cc97d6bda6f845219eaa1027331b1d39c199023e4daf44c9fc6b2507900957476a00332b46dfd08f452e6314c014c2a79f6
@@ -0,0 +1,4 @@
1
+ module Honeycomb
2
+ GEM_NAME = 'honeycomb'
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,7 @@
1
+ begin
2
+ gem 'sequel'
3
+
4
+ require 'sequel/extensions/honeycomb'
5
+ rescue Gem::LoadError
6
+ warn 'sequel not detected, not enabling sequel-honeycomb'
7
+ end
@@ -0,0 +1,23 @@
1
+ module Sequel
2
+ module Honeycomb
3
+ module AutoInstall
4
+ class << self
5
+ def available?(**_)
6
+ gem 'sequel'
7
+ true
8
+ rescue Gem::LoadError
9
+ false
10
+ end
11
+
12
+ def auto_install!(honeycomb_client:, logger: nil)
13
+ require 'sequel'
14
+ require 'sequel/extensions/honeycomb'
15
+
16
+ # TODO is this the right way?
17
+ # TODO inject client
18
+ Sequel::Database.extension :honeycomb
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ module Sequel
2
+ module Extensions
3
+ module Honeycomb
4
+ def self.included(mod)
5
+ # TODO ugh clean this up
6
+ puts "included"
7
+ @_honeycomb ||= begin
8
+ puts "HONEYCOMBING"
9
+ if defined?(::Honeycomb.client)
10
+ ::Honeycomb.client.tap do |klient|
11
+ puts "client is #{klient.nil? ? :nil : :lin}"
12
+ end
13
+ else
14
+ raise "Can't work without magic global Honeycomb.client at the moment"
15
+ end
16
+ end
17
+ mod.class_exec(@_honeycomb) do |honeycomb_|
18
+ define_method(:honeycomb) { honeycomb_ }
19
+ end
20
+ end
21
+
22
+ def execute(sql, opts=OPTS, &block)
23
+ raise 'something went horribly wrong' unless honeycomb # TODO
24
+
25
+ event = honeycomb.event
26
+
27
+ event.add_field :table, first_source_table rescue nil
28
+ event.add_field :sql, sql
29
+ start = Time.now
30
+ adding_span_metadata_if_available(event) do
31
+ super
32
+ end
33
+ rescue Exception => e
34
+ if event
35
+ event.add_field :exception_class, e.class
36
+ event.add_field :exception_message, e.message
37
+ end
38
+ raise
39
+ ensure
40
+ if start && event
41
+ finish = Time.now
42
+ duration = finish - start
43
+ event.add_field :durationMs, duration * 1000
44
+ event.send
45
+ end
46
+ end
47
+
48
+ private
49
+ def adding_span_metadata_if_available(event)
50
+ return yield unless defined?(::Honeycomb.trace_id)
51
+
52
+ trace_id = ::Honeycomb.trace_id
53
+ name = first_source_table rescue 'sql'
54
+
55
+ event.add_field :traceId, trace_id if trace_id
56
+ span_id = SecureRandom.uuid
57
+ event.add_field :id, span_id
58
+ event.add_field :serviceName, 'sequel'
59
+ event.add_field :name, name if name
60
+
61
+ ::Honeycomb.with_span_id(span_id) do |parent_span_id|
62
+ event.add_field :parentId, parent_span_id
63
+ yield
64
+ end
65
+ end
66
+ end
67
+
68
+ Sequel::Dataset.register_extension(:honeycomb, Honeycomb)
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ module Sequel
2
+ module Honeycomb
3
+ GEM_NAME = 'sequel-honeycomb'
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-honeycomb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam Stokes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: bump
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: rake
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: rspec
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: yard
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
+ description: " TO DO *is* a description\n"
84
+ email:
85
+ - sam@honeycomb.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/honeycomb/version.rb
91
+ - lib/sequel-honeycomb.rb
92
+ - lib/sequel-honeycomb/auto_install.rb
93
+ - lib/sequel/extensions/honeycomb.rb
94
+ - lib/sequel/honeycomb/version.rb
95
+ homepage: https://github.com/honeycombio/sequel-honeycomb
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.11
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Instrument your Sequel queries with Honeycomb
119
+ test_files: []