newrelic_moped 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- collection = operation.collection
17
+ if operation.respond_to?(:collection)
18
+ collection = operation.collection
16
19
 
17
- self.class.trace_execution_scoped(["Moped::process[#{collection}]"]) do
18
- t0 = Time.now
20
+ self.class.trace_execution_scoped(["Moped::process[#{collection}]"]) do
21
+ t0 = Time.now
19
22
 
20
- begin
21
- process_without_newrelic_trace(operation, &callback)
22
- ensure
23
- elapsed_time = (Time.now - t0).to_f
24
- NewRelic::Agent.instance.transaction_sampler.notice_sql(operation.log_inspect,
25
- nil, elapsed_time)
26
- NewRelic::Agent.instance.sql_sampler.notice_sql(operation.log_inspect, nil,
27
- nil, elapsed_time)
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
@@ -1,3 +1,3 @@
1
1
  module NewrelicMoped
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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.2
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-07-26 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in newrelic-moped.gemspec
4
- gemspec