appdash 0.6.0 → 0.6.1

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: 832463798ecc366655cfe139b52dfdab61e4ad14
4
- data.tar.gz: f5b7db5b952464cfe30f1aa93c673bb4252d2a9d
3
+ metadata.gz: 600ac6a714c1c25d63a282f1e2995c280e858b19
4
+ data.tar.gz: d465ba502a447dea8b85236887dcda663f3aa811
5
5
  SHA512:
6
- metadata.gz: 87131161bf4489115b1b559e342180e4538e9e48363e314ff9e947b393ccf8592bff625a7022d168ba7fb94f19f2786eb52451d63b4b01734f95aa192f41aee9
7
- data.tar.gz: 04963a82c52bedb5fbd7a5b93feca849c0494b95b98e9a5264126ad2529339110b0eddc73622c9db5b33aeb12c0d483f1d342cb7c905e6772583c86e27eb1f2d
6
+ metadata.gz: 912e56d21fbe32ae827d509357f631735f95068e1a85122f59d8f6826177acf96cd474a76b26b63fa13c731fcd22655ea3a0914a5063cb3a7b3c6691fd5e1b00
7
+ data.tar.gz: 583bd30c42842628bfc8ad7e7422353a003a8d719569109ea9028b1345a3511b7fb2cd6d4a76d988e6e0b2f714d18f6fbbeba0a8bc57ba03fad360a42ef0b45b
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.1.1
5
+ - 2.0.0
6
+ - 1.9.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appdash (0.6.0)
4
+ appdash (0.6.1)
5
5
  protobuf
6
6
 
7
7
  GEM
@@ -24,6 +24,8 @@ GEM
24
24
  thor
25
25
  thread_safe
26
26
  rack (1.6.4)
27
+ rack-test (0.6.3)
28
+ rack (>= 1.0)
27
29
  rake (10.4.2)
28
30
  rspec (3.4.0)
29
31
  rspec-core (~> 3.4.0)
@@ -50,6 +52,7 @@ DEPENDENCIES
50
52
  appdash!
51
53
  bundler
52
54
  rack
55
+ rack-test
53
56
  rake
54
57
  rspec
55
58
 
data/README.md CHANGED
@@ -24,6 +24,18 @@ Collect spans:
24
24
  s.log "a log entry with a timestamp"
25
25
  end
26
26
 
27
+ Rack middleware:
28
+
29
+ require 'sinatra'
30
+ require 'appdash/middleware'
31
+
32
+ client = Appdash::Client.new host: "remote.host", port: 7701
33
+ use Appdash::Middleware, client
34
+
35
+ get '/' do
36
+ "OK"
37
+ end
38
+
27
39
  For full options and event types, please see the [Documentation](http://www.rubydoc.info/gems/appdash).
28
40
 
29
41
  ## Contributing
data/appdash.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "appdash"
5
- s.version = "0.6.0"
5
+ s.version = "0.6.1"
6
6
  s.authors = ["Black Square Media"]
7
7
  s.email = ["dimitrij@blacksquaremedia.com"]
8
8
  s.summary = %q{Appdash client for ruby}
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency(%q<rack>)
21
21
  s.add_development_dependency(%q<bundler>)
22
22
  s.add_development_dependency(%q<rspec>)
23
+ s.add_development_dependency(%q<rack-test>)
23
24
  end
@@ -39,7 +39,7 @@ module Appdash
39
39
  def annotation(key, value = nil)
40
40
  case value
41
41
  when DateTime, Time
42
- value = value.strftime('%FT%T%:z')
42
+ value = value.strftime('%FT%T.%6N%:z')
43
43
  when NilClass
44
44
  # ignore
45
45
  else
@@ -27,7 +27,7 @@ module Appdash
27
27
  def parse_request(req)
28
28
  data = {
29
29
  method: req.request_method,
30
- url: req.url,
30
+ path: req.fullpath,
31
31
  scheme: req.scheme,
32
32
  host: req.host,
33
33
  remote_ip: req.ip,
@@ -44,7 +44,7 @@ module Appdash
44
44
 
45
45
  def parse_response(resp)
46
46
  {
47
- content_length: resp.length,
47
+ content_length: resp.content_length,
48
48
  status_code: resp.status
49
49
  }
50
50
  end
@@ -0,0 +1,39 @@
1
+ require 'appdash'
2
+ require 'rack'
3
+ require 'appdash/event/rack_server'
4
+
5
+ module Appdash
6
+ # Middleware is a rack middleware that can be used to add tracing to Rack servers.
7
+ # It creates a span per incoming request and stores it on the 'appdash.span' key on the env.
8
+ class Middleware
9
+ ENV_KEY = 'appdash.span'.freeze
10
+
11
+ def initialize(app, client)
12
+ @app = app
13
+ @client = client
14
+ end
15
+
16
+ def call(env)
17
+ recv = Time.now
18
+ span = env[ENV_KEY] = @client.span
19
+
20
+ status, headers, body = @app.call(env)
21
+ span.event build(recv, env, status, headers)
22
+ [status, headers, body]
23
+ ensure
24
+ env[ENV_KEY].flush if env.key?(ENV_KEY)
25
+ end
26
+
27
+ private
28
+
29
+ def build(recv, env, status, headers)
30
+ Appdash::Event::RackServer.new Rack::Request.new(env), nil,
31
+ response: {
32
+ status_code: status,
33
+ content_length: headers['Content-Length'],
34
+ },
35
+ recv: recv
36
+ end
37
+
38
+ end
39
+ end
@@ -14,7 +14,7 @@ RSpec.describe Appdash::Event::Base do
14
14
  "Name" => "Query",
15
15
  "SomeOther" => "2",
16
16
  "Sub.ReqURL" => "http://example.com/path",
17
- "Sub.Nest.V"=>"2015-01-01T00:00:00+00:00",
17
+ "Sub.Nest.V"=>"2015-01-01T00:00:00.000000+00:00",
18
18
  "_schema:test"=>"",
19
19
  )
20
20
  end
@@ -14,7 +14,7 @@ RSpec.describe Appdash::Event::Log do
14
14
  it "should annotate" do
15
15
  expect(atoh(subject.to_a)).to eq(
16
16
  "Msg" => "Hi",
17
- "Time" => "2001-02-03T04:05:06+00:00",
17
+ "Time" => "2001-02-03T04:05:06.000000+00:00",
18
18
  "_schema:log" => "",
19
19
  )
20
20
  end
@@ -5,7 +5,7 @@ RSpec.describe Appdash::Event::RackServer do
5
5
  let(:time) { Time.utc(2001,2,3,4,5,6) }
6
6
  let(:response) { Rack::Response.new([], 201, 'Content-Length' => 33) }
7
7
  let(:request) do
8
- env = Rack::MockRequest.env_for("http://example.com:8080/", "REMOTE_ADDR" => "10.10.10.10", 'CONTENT_LENGTH' => 12, 'HTTP_USER_AGENT' => 'Test/1.0')
8
+ env = Rack::MockRequest.env_for("http://example.com:8080/path?a=1", "REMOTE_ADDR" => "10.10.10.10", 'CONTENT_LENGTH' => 12, 'HTTP_USER_AGENT' => 'Test/1.0')
9
9
  Rack::Request.new(env)
10
10
  end
11
11
 
@@ -24,12 +24,12 @@ RSpec.describe Appdash::Event::RackServer do
24
24
  "Server.Request.Method" => "GET",
25
25
  "Server.Request.Scheme" => "http",
26
26
  "Server.Request.RemoteIP" => "10.10.10.10",
27
- "Server.Request.URL" => "http://example.com:8080/",
27
+ "Server.Request.Path" => "/path?a=1",
28
28
  "Server.Request.UserAgent" => "Test/1.0",
29
- "Server.Response.ContentLength" => "0",
29
+ "Server.Response.ContentLength" => "33",
30
30
  "Server.Response.StatusCode" => "201",
31
31
  "Server.Route" => "createPost",
32
- "Server.Send" => "2001-02-03T04:05:06+00:00",
32
+ "Server.Send" => "2001-02-03T04:05:06.000000+00:00",
33
33
  "_schema:HTTPServer" => "",
34
34
  )
35
35
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Appdash::Middleware do
4
+ include Rack::Test::Methods
5
+
6
+ let(:mock_socket) { double("TCPSocket", shutdown: nil) }
7
+ before { allow(TCPSocket).to receive(:new).and_return(mock_socket) }
8
+
9
+ let(:app) do
10
+ mware = described_class
11
+ client = Appdash::Client.new
12
+
13
+ Rack::Builder.new do
14
+ use mware, client
15
+ run ->_ { [200, {'Content-Type' => 'text/plain'}, ["OK"]] }
16
+ end
17
+ end
18
+
19
+ it 'should trace requests' do
20
+ expect(mock_socket).to receive(:write) do |msg|
21
+ expect(msg.size).to eq(406)
22
+ end
23
+ get '/'
24
+ expect(last_response.status).to eq(200)
25
+ end
26
+
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'rspec'
2
2
  require 'rack'
3
+ require 'rack/test'
3
4
  require 'appdash'
5
+ require 'appdash/middleware'
4
6
 
5
7
  helpers = Module.new do
6
-
7
8
  def atoh(annotations)
8
9
  annotations.inject({}) {|h, a| h[a.key] = a.value; h }
9
10
  end
10
-
11
11
  end
12
12
 
13
13
  RSpec.configure do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appdash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: protobuf
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
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'
83
97
  description: Ruby client for Appdash, Sourcegraph's application tracing system, based
84
98
  on Google's Dapper
85
99
  email:
@@ -89,6 +103,8 @@ extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - ".editorconfig"
106
+ - ".gitignore"
107
+ - ".travis.yml"
92
108
  - Gemfile
93
109
  - Gemfile.lock
94
110
  - MIT-LICENCE
@@ -105,6 +121,7 @@ files:
105
121
  - lib/appdash/event/rack_server.rb
106
122
  - lib/appdash/event/span_name.rb
107
123
  - lib/appdash/events.rb
124
+ - lib/appdash/middleware.rb
108
125
  - lib/appdash/span.rb
109
126
  - lib/appdash/span/id.rb
110
127
  - lib/appdash/wire.rb
@@ -114,6 +131,7 @@ files:
114
131
  - spec/appdash/event/message_spec.rb
115
132
  - spec/appdash/event/rack_server_spec.rb
116
133
  - spec/appdash/event/span_name_spec.rb
134
+ - spec/appdash/middleware_spec.rb
117
135
  - spec/appdash/span/id_spec.rb
118
136
  - spec/appdash/span_spec.rb
119
137
  - spec/appdash/wire_spec.rb
@@ -148,6 +166,7 @@ test_files:
148
166
  - spec/appdash/event/message_spec.rb
149
167
  - spec/appdash/event/rack_server_spec.rb
150
168
  - spec/appdash/event/span_name_spec.rb
169
+ - spec/appdash/middleware_spec.rb
151
170
  - spec/appdash/span/id_spec.rb
152
171
  - spec/appdash/span_spec.rb
153
172
  - spec/appdash/wire_spec.rb