skylight 0.2.7 → 0.3.0.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/ext/checksums.yml +3 -0
  3. data/ext/extconf.rb +90 -0
  4. data/ext/skylight.map +4 -0
  5. data/ext/skylight_native.c +613 -0
  6. data/lib/skylight.rb +50 -7
  7. data/lib/skylight/config.rb +7 -1
  8. data/lib/skylight/helpers.rb +2 -2
  9. data/lib/skylight/instrumenter.rb +9 -5
  10. data/lib/skylight/messages.rb +13 -13
  11. data/lib/skylight/messages/error.rb +10 -6
  12. data/lib/skylight/messages/hello.rb +4 -45
  13. data/lib/skylight/messages/trace.rb +62 -103
  14. data/lib/skylight/messages/trace_envelope.rb +19 -0
  15. data/lib/skylight/native.rb +80 -0
  16. data/lib/skylight/normalizers/process_action.rb +1 -3
  17. data/lib/skylight/probes.rb +1 -1
  18. data/lib/skylight/subscriber.rb +1 -1
  19. data/lib/skylight/util/clock.rb +13 -6
  20. data/lib/skylight/version.rb +1 -1
  21. data/lib/skylight/worker/builder.rb +1 -1
  22. data/lib/skylight/worker/collector.rb +20 -32
  23. data/lib/skylight/worker/connection.rb +2 -2
  24. data/lib/skylight/worker/embedded.rb +18 -0
  25. data/lib/skylight/worker/server.rb +3 -3
  26. data/lib/skylight/worker/standalone.rb +9 -10
  27. data/lib/sql_lexer.rb +0 -1
  28. data/lib/sql_lexer/lexer.rb +50 -4
  29. data/lib/sql_lexer/version.rb +1 -1
  30. metadata +19 -22
  31. data/lib/skylight/messages/annotation.rb +0 -13
  32. data/lib/skylight/messages/base.rb +0 -24
  33. data/lib/skylight/messages/batch.rb +0 -12
  34. data/lib/skylight/messages/endpoint.rb +0 -12
  35. data/lib/skylight/messages/event.rb +0 -12
  36. data/lib/skylight/messages/span.rb +0 -166
  37. data/lib/skylight/vendor/beefcake.rb +0 -292
  38. data/lib/skylight/vendor/beefcake/buffer.rb +0 -119
  39. data/lib/skylight/vendor/beefcake/decode.rb +0 -107
  40. data/lib/skylight/vendor/beefcake/encode.rb +0 -132
@@ -1,119 +0,0 @@
1
- module Skylight
2
- module Beefcake
3
- class Buffer
4
- MinUint32 = 0
5
- MaxUint32 = (1<<32)-1
6
- MinInt32 = -(1<<31)
7
- MaxInt32 = (1<<31)-1
8
-
9
- MinUint64 = 0
10
- MaxUint64 = (1<<64)-1
11
- MinInt64 = -(1<<63)
12
- MaxInt64 = (1<<63)-1
13
-
14
- MaxFixnum = (1 << (1.size * 8 - 2) - 1)
15
-
16
- def self.wire_for(type)
17
- case type
18
- when Class
19
- if encodable?(type)
20
- 2
21
- else
22
- raise UnknownType, type
23
- end
24
- when :int32, :uint32, :sint32, :int64, :uint64, :sint64, :bool, Module
25
- 0
26
- when :fixed64, :sfixed64, :double
27
- 1
28
- when :string, :bytes
29
- 2
30
- when :fixed32, :sfixed32, :float
31
- 5
32
- else
33
- raise UnknownType, type
34
- end
35
- end
36
-
37
- def self.encodable?(type)
38
- return false if ! type.is_a?(Class)
39
- type < Message
40
- end
41
-
42
- attr_accessor :buf
43
-
44
- alias :to_s :buf
45
- alias :to_str :buf
46
-
47
- class OutOfRangeError < StandardError
48
- def initialize(n)
49
- super("Value of of range: %d" % [n])
50
- end
51
- end
52
-
53
- class BufferOverflowError < StandardError
54
- def initialize(s)
55
- super("Too many bytes read for %s" % [s])
56
- end
57
- end
58
-
59
- class UnknownType < StandardError
60
- def initialize(s)
61
- super("Unknown type '%s'" % [s])
62
- end
63
- end
64
-
65
- def initialize(buf="")
66
- unless String === buf
67
- raise ArgumentError, "buf must be a string"
68
- end
69
-
70
- self.buf = buf
71
- end
72
-
73
- if ''.respond_to?(:force_encoding)
74
- def buf=(buf)
75
- @buf = buf.force_encoding(BINARY)
76
- end
77
- end
78
-
79
- def length
80
- @buf.respond_to?(:bytesize) ? @buf.bytesize : @buf.length
81
- end
82
-
83
- BINARY = 'BINARY'.freeze
84
-
85
- # Detect a ruby encodings bug, as far as I know, this exists in
86
- # most versions fo JRuby as well as 1.9.2
87
- def self.current_ruby_has_encoding_bug?
88
- base = "\0\1".force_encoding('BINARY')
89
- base << "BUG".encode("UTF-8")
90
- base.encoding.to_s == 'UTF-8'
91
- end
92
-
93
- if ''.respond_to?(:force_encoding) && current_ruby_has_encoding_bug?
94
- def <<(bytes)
95
- buf << bytes
96
- buf.force_encoding(BINARY)
97
- buf
98
- end
99
- else
100
- def <<(bytes)
101
- buf << bytes
102
- end
103
- end
104
-
105
- def read(n)
106
- case n
107
- when Class
108
- n.decode(read_string)
109
- when Symbol
110
- __send__("read_#{n}")
111
- when Module
112
- read_uint64
113
- else
114
- buf.slice!(0, n)
115
- end
116
- end
117
- end
118
- end
119
- end
@@ -1,107 +0,0 @@
1
- require 'skylight/vendor/beefcake/buffer'
2
-
3
- module Skylight
4
- module Beefcake
5
- class Buffer
6
-
7
- def read_info
8
- n = read_uint64
9
- fn = n >> 3
10
- wire = n & 0x7
11
-
12
- [fn, wire]
13
- end
14
-
15
- def read_string
16
- read(read_uint64)
17
- end
18
- alias :read_bytes :read_string
19
-
20
- def read_fixed32
21
- bytes = read(4)
22
- bytes.unpack("V").first
23
- end
24
-
25
- def read_fixed64
26
- bytes = read(8)
27
- x, y = bytes.unpack("VV")
28
- x + (y << 32)
29
- end
30
-
31
- def read_int64
32
- n = read_uint64
33
- if n > MaxInt64
34
- n -= (1 << 64)
35
- end
36
- n
37
- end
38
- alias :read_int32 :read_int64
39
-
40
- def read_uint64
41
- n = shift = 0
42
- while true
43
- if shift >= 64
44
- raise BufferOverflowError, "varint"
45
- end
46
- b = buf.slice!(0)
47
-
48
- ## 1.8.6 to 1.9 Compat
49
- if b.respond_to?(:ord)
50
- b = b.ord
51
- end
52
-
53
- n |= ((b & 0x7F) << shift)
54
- shift += 7
55
- if (b & 0x80) == 0
56
- return n
57
- end
58
- end
59
- end
60
- alias :read_uint32 :read_uint64
61
-
62
- def read_sint64
63
- decode_zigzag(read_uint64)
64
- end
65
- alias :read_sint32 :read_sint64
66
-
67
- def read_sfixed32
68
- decode_zigzag(read_fixed32)
69
- end
70
-
71
- def read_sfixed64
72
- decode_zigzag(read_fixed64)
73
- end
74
-
75
- def read_float
76
- bytes = read(4)
77
- bytes.unpack("e").first
78
- end
79
-
80
- def read_double
81
- bytes = read(8)
82
- bytes.unpack("E").first
83
- end
84
-
85
- def read_bool
86
- read_int32 != 0
87
- end
88
-
89
- def skip(wire)
90
- case wire
91
- when 0 then read_uint64
92
- when 1 then read_fixed64
93
- when 2 then read_string
94
- when 5 then read_fixed32
95
- end
96
- end
97
-
98
-
99
- private
100
-
101
- def decode_zigzag(n)
102
- (n >> 1) ^ -(n & 1)
103
- end
104
-
105
- end
106
- end
107
- end
@@ -1,132 +0,0 @@
1
- require 'skylight/vendor/beefcake/buffer'
2
-
3
- module Skylight
4
- module Beefcake
5
- class Buffer
6
-
7
- def append(type, val, fn)
8
- if fn != 0
9
- wire = Buffer.wire_for(type)
10
- append_info(fn, wire)
11
- end
12
-
13
- __send__(HANDLERS[type], val)
14
- end
15
-
16
- def append_info(fn, wire)
17
- append_uint32((fn << 3) | wire)
18
- end
19
-
20
- def append_fixed32(n, tag=false)
21
- if n < MinUint32 || n > MaxUint32
22
- raise OutOfRangeError, n
23
- end
24
-
25
- self << [n].pack("V")
26
- end
27
-
28
- def append_fixed64(n)
29
- if uint64?(n)
30
- raise OutOfRangeError, n
31
- end
32
-
33
- self << [n & 0xFFFFFFFF, n >> 32].pack("VV")
34
- end
35
-
36
- def append_int32(n)
37
- if n < MinInt32 || n > MaxInt32
38
- raise OutOfRangeError, n
39
- end
40
-
41
- append_int64(n)
42
- end
43
-
44
- def append_uint32(n)
45
- if n < MinUint32 || n > MaxUint32
46
- raise OutOfRangeError, n
47
- end
48
-
49
- append_uint64(n)
50
- end
51
-
52
- def append_int64(n)
53
- if n < MinInt64 || n > MaxInt64
54
- raise OutOfRangeError, n
55
- end
56
-
57
- if n < 0
58
- n += (1 << 64)
59
- end
60
-
61
- append_uint64(n)
62
- end
63
-
64
- def append_sint32(n)
65
- append_uint32((n << 1) ^ (n >> 31))
66
- end
67
-
68
- def append_sfixed32(n)
69
- append_fixed32((n << 1) ^ (n >> 31))
70
- end
71
-
72
- def append_sint64(n)
73
- append_uint64((n << 1) ^ (n >> 63))
74
- end
75
-
76
- def append_sfixed64(n)
77
- append_fixed64((n << 1) ^ (n >> 63))
78
- end
79
-
80
- def uint64?(n)
81
- if n < MinUint64
82
- false
83
- elsif n < MaxFixnum
84
- true
85
- else
86
- n <= MaxUint64
87
- end
88
- end
89
-
90
- def append_uint64(n)
91
- unless uint64?(n)
92
- raise OutOfRangeError, n
93
- end
94
-
95
- while true
96
- bits = n & 0x7F
97
- n >>= 7
98
- if n == 0
99
- return self << bits
100
- end
101
- self << (bits | 0x80)
102
- end
103
- end
104
-
105
- def append_float(n)
106
- self << [n].pack("e")
107
- end
108
-
109
- def append_double(n)
110
- self << [n].pack("E")
111
- end
112
-
113
- def append_bool(n)
114
- append_int64(n ? 1 : 0)
115
- end
116
-
117
- def append_string(s)
118
- append_uint64(s.length)
119
- self << s
120
- end
121
- alias :append_bytes :append_string
122
-
123
- HANDLERS = instance_methods.reduce({}) do |hash, meth|
124
- if meth.to_s =~ /^append_(.*)$/
125
- hash[$1.to_sym] = meth
126
- end
127
-
128
- hash
129
- end
130
- end
131
- end
132
- end