newrelic_moped 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/newrelic_moped/instrumentation.rb +15 -11
- data/lib/newrelic_moped/version.rb +1 -1
- data/test/instrumentation_test.rb +55 -0
- metadata +5 -4
- data/Gemfile +0 -4
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'new_relic/agent/method_tracer'
|
2
|
+
|
1
3
|
DependencyDetection.defer do
|
2
4
|
@name = :moped
|
3
5
|
|
@@ -12,19 +14,21 @@ DependencyDetection.defer do
|
|
12
14
|
executes do
|
13
15
|
Moped::Node.class_eval do
|
14
16
|
def process_with_newrelic_trace(operation, &callback)
|
15
|
-
|
17
|
+
if operation.respond_to?(:collection)
|
18
|
+
collection = operation.collection
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
self.class.trace_execution_scoped(["Moped::process[#{collection}]"]) do
|
21
|
+
t0 = Time.now
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
begin
|
24
|
+
process_without_newrelic_trace(operation, &callback)
|
25
|
+
ensure
|
26
|
+
elapsed_time = (Time.now - t0).to_f
|
27
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(operation.log_inspect,
|
28
|
+
nil, elapsed_time)
|
29
|
+
NewRelic::Agent.instance.sql_sampler.notice_sql(operation.log_inspect, nil,
|
30
|
+
nil, elapsed_time)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'moped'
|
4
|
+
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/newrelic_moped/instrumentation')
|
6
|
+
|
7
|
+
class FakeOpWithCollection < Struct.new(:collection, :log_inspect)
|
8
|
+
end
|
9
|
+
|
10
|
+
class FakeOpWithoutCollection < Struct.new(:log_inspect)
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestInstrumentation < Test::Unit::TestCase
|
14
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
15
|
+
|
16
|
+
def setup
|
17
|
+
DependencyDetection.detect!
|
18
|
+
NewRelic::Agent.manual_start
|
19
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
20
|
+
@engine.clear_stats
|
21
|
+
|
22
|
+
@sampler = NewRelic::Agent.instance.transaction_sampler
|
23
|
+
@sampler.enable
|
24
|
+
@sampler.reset!
|
25
|
+
@sampler.start_builder
|
26
|
+
|
27
|
+
Moped::Node.class_eval do
|
28
|
+
def process_without_newrelic_trace(operation, &callback)
|
29
|
+
# do nothing
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
@node = Moped::Node.new("127.0.0.1:27017")
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
@sampler.clear_builder
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_handles_operations_with_collections
|
41
|
+
fake_op = FakeOpWithCollection.new([], "Fake")
|
42
|
+
|
43
|
+
assert_nothing_raised do
|
44
|
+
@node.process_with_newrelic_trace(fake_op)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_ignores_operations_without_collection
|
49
|
+
fake_op = FakeOpWithoutCollection.new("Fake")
|
50
|
+
|
51
|
+
assert_nothing_raised do
|
52
|
+
@node.process_with_newrelic_trace(fake_op)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_moped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: New Relic Instrumentation for Moped & Mongoid 3
|
15
15
|
email:
|
@@ -19,7 +19,6 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
|
-
- Gemfile
|
23
22
|
- LICENSE
|
24
23
|
- README.md
|
25
24
|
- Rakefile
|
@@ -27,6 +26,7 @@ files:
|
|
27
26
|
- lib/newrelic_moped/instrumentation.rb
|
28
27
|
- lib/newrelic_moped/version.rb
|
29
28
|
- newrelic_moped.gemspec
|
29
|
+
- test/instrumentation_test.rb
|
30
30
|
homepage: ''
|
31
31
|
licenses: []
|
32
32
|
post_install_message:
|
@@ -51,4 +51,5 @@ rubygems_version: 1.8.23
|
|
51
51
|
signing_key:
|
52
52
|
specification_version: 3
|
53
53
|
summary: New Relic Instrumentation for Moped & Mongoid 3
|
54
|
-
test_files:
|
54
|
+
test_files:
|
55
|
+
- test/instrumentation_test.rb
|
data/Gemfile
DELETED