Skip to content

Commit 1aa5680

Browse files
authored
feat: add instrumentation for newer MongoDB.Client methods (#1732)
* Instrument CountDocuments and CountDocumentsAsync * Refactor to simplify test logic and driver version logic * Instrument EstimatedDocumentCount(Async) Also add test for AggregateAsync * Instrument and test AggregateToCollection(Async) * Instrument and test ListCollectionNames(Async) * Refactor database tests * Instrument and test Db.Aggregate(Async) * Instrument and test Db.AggregateToCollection(Async) * Instrument and test Db.Watch(Async) * Refactor indexmanager tests to use theory * Test stability improvements
1 parent beb32bf commit 1aa5680

File tree

5 files changed

+639
-527
lines changed

5 files changed

+639
-527
lines changed

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MongoDb26/Instrumentation.xml

+104-90
Original file line numberDiff line numberDiff line change
@@ -4,105 +4,119 @@ Copyright 2020 New Relic Corporation. All rights reserved.
44
SPDX-License-Identifier: Apache-2.0
55
-->
66
<extension xmlns="urn:newrelic-extension">
7-
<instrumentation>
8-
<tracerFactory name="MongoCollectionImplWrapper">
9-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionImpl`1">
10-
<exactMethodMatcher methodName="AggregateAsync"/>
11-
<exactMethodMatcher methodName="BulkWriteAsync"/>
12-
<exactMethodMatcher methodName="CountAsync"/>
13-
<exactMethodMatcher methodName="DistinctAsync"/>
14-
<exactMethodMatcher methodName="FindAsync"/>
15-
<exactMethodMatcher methodName="FindOneAndDeleteAsync"/>
16-
<exactMethodMatcher methodName="FindOneAndReplaceAsync"/>
17-
<exactMethodMatcher methodName="FindOneAndUpdateAsync"/>
18-
<exactMethodMatcher methodName="MapReduceAsync"/>
19-
<exactMethodMatcher methodName="WatchAsync"/>
20-
21-
<exactMethodMatcher methodName="Aggregate"/>
22-
<exactMethodMatcher methodName="BulkWrite"/>
23-
<exactMethodMatcher methodName="Count"/>
24-
<exactMethodMatcher methodName="Distinct"/>
25-
<exactMethodMatcher methodName="FindSync"/>
26-
<exactMethodMatcher methodName="FindOneAndDelete"/>
27-
<exactMethodMatcher methodName="FindOneAndReplace"/>
28-
<exactMethodMatcher methodName="FindOneAndUpdate"/>
29-
<exactMethodMatcher methodName="MapReduce"/>
30-
<exactMethodMatcher methodName="Watch"/>
31-
</match>
32-
</tracerFactory>
7+
<instrumentation>
8+
<tracerFactory name="MongoCollectionImplWrapper">
9+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionImpl`1">
10+
<exactMethodMatcher methodName="AggregateAsync"/>
11+
<exactMethodMatcher methodName="AggregateToCollectionAsync"/>
12+
<exactMethodMatcher methodName="BulkWriteAsync"/>
13+
<exactMethodMatcher methodName="CountAsync"/>
14+
<exactMethodMatcher methodName="CountDocumentsAsync"/>
15+
<exactMethodMatcher methodName="DistinctAsync"/>
16+
<exactMethodMatcher methodName="EstimatedDocumentCountAsync"/>
17+
<exactMethodMatcher methodName="FindAsync"/>
18+
<exactMethodMatcher methodName="FindOneAndDeleteAsync"/>
19+
<exactMethodMatcher methodName="FindOneAndReplaceAsync"/>
20+
<exactMethodMatcher methodName="FindOneAndUpdateAsync"/>
21+
<exactMethodMatcher methodName="MapReduceAsync"/>
22+
<exactMethodMatcher methodName="WatchAsync"/>
3323

34-
<tracerFactory name="AsyncCursorWrapper">
35-
<match assemblyName="MongoDB.Driver.Core" className="MongoDB.Driver.Core.Operations.AsyncCursor`1">
36-
<exactMethodMatcher methodName="GetNextBatch"/>
37-
<exactMethodMatcher methodName="GetNextBatchAsync"/>
38-
</match>
39-
</tracerFactory>
24+
<exactMethodMatcher methodName="Aggregate"/>
25+
<exactMethodMatcher methodName="AggregateToCollection"/>
26+
<exactMethodMatcher methodName="BulkWrite"/>
27+
<exactMethodMatcher methodName="Count"/>
28+
<exactMethodMatcher methodName="CountDocuments"/>
29+
<exactMethodMatcher methodName="Distinct"/>
30+
<exactMethodMatcher methodName="EstimatedDocumentCount"/>
31+
<exactMethodMatcher methodName="FindSync"/>
32+
<exactMethodMatcher methodName="FindOneAndDelete"/>
33+
<exactMethodMatcher methodName="FindOneAndReplace"/>
34+
<exactMethodMatcher methodName="FindOneAndUpdate"/>
35+
<exactMethodMatcher methodName="MapReduce"/>
36+
<exactMethodMatcher methodName="Watch"/>
37+
</match>
38+
</tracerFactory>
4039

41-
<tracerFactory name="MongoDatabaseWrapper">
42-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoDatabaseImpl">
43-
<exactMethodMatcher methodName="CreateCollection"/>
44-
<exactMethodMatcher methodName="CreateView"/>
45-
<exactMethodMatcher methodName="DropCollection"/>
46-
<exactMethodMatcher methodName="ListCollections"/>
47-
<exactMethodMatcher methodName="RenameCollection"/>
48-
<exactMethodMatcher methodName="RunCommand"/>
40+
<tracerFactory name="AsyncCursorWrapper">
41+
<match assemblyName="MongoDB.Driver.Core" className="MongoDB.Driver.Core.Operations.AsyncCursor`1">
42+
<exactMethodMatcher methodName="GetNextBatch"/>
43+
<exactMethodMatcher methodName="GetNextBatchAsync"/>
44+
</match>
45+
</tracerFactory>
4946

50-
<exactMethodMatcher methodName="CreateCollectionAsync"/>
51-
<exactMethodMatcher methodName="CreateViewAsync"/>
52-
<exactMethodMatcher methodName="DropCollectionAsync"/>
53-
<exactMethodMatcher methodName="ListCollectionsAsync"/>
54-
<exactMethodMatcher methodName="RenameCollectionAsync"/>
55-
<exactMethodMatcher methodName="RunCommandAsync"/>
56-
</match>
57-
</tracerFactory>
47+
<tracerFactory name="MongoDatabaseWrapper">
48+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoDatabaseImpl">
49+
<exactMethodMatcher methodName="Aggregate"/>
50+
<exactMethodMatcher methodName="AggregateToCollection"/>
51+
<exactMethodMatcher methodName="CreateCollection"/>
52+
<exactMethodMatcher methodName="CreateView"/>
53+
<exactMethodMatcher methodName="DropCollection"/>
54+
<exactMethodMatcher methodName="ListCollections"/>
55+
<exactMethodMatcher methodName="ListCollectionNames"/>
56+
<exactMethodMatcher methodName="RenameCollection"/>
57+
<exactMethodMatcher methodName="RunCommand"/>
58+
<exactMethodMatcher methodName="Watch"/>
5859

59-
<tracerFactory name="MongoQueryProviderImplWrapper">
60-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.Linq.MongoQueryProviderImpl`1">
61-
<exactMethodMatcher methodName="ExecuteModel"/>
62-
<exactMethodMatcher methodName="ExecuteModelAsync"/>
63-
</match>
64-
</tracerFactory>
60+
<exactMethodMatcher methodName="AggregateAsync"/>
61+
<exactMethodMatcher methodName="AggregateToCollectionAsync"/>
62+
<exactMethodMatcher methodName="CreateCollectionAsync"/>
63+
<exactMethodMatcher methodName="CreateViewAsync"/>
64+
<exactMethodMatcher methodName="DropCollectionAsync"/>
65+
<exactMethodMatcher methodName="ListCollectionsAsync"/>
66+
<exactMethodMatcher methodName="ListCollectionNamesAsync"/>
67+
<exactMethodMatcher methodName="RenameCollectionAsync"/>
68+
<exactMethodMatcher methodName="RunCommandAsync"/>
69+
<exactMethodMatcher methodName="WatchAsync"/>
70+
</match>
71+
</tracerFactory>
6572

66-
<tracerFactory name="MongoIndexManagerBaseWrapper">
67-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoIndexManagerBase`1">
68-
<exactMethodMatcher methodName="CreateOne"/>
69-
<exactMethodMatcher methodName="CreateOneAsync"/>
70-
</match>
71-
</tracerFactory>
73+
<tracerFactory name="MongoQueryProviderImplWrapper">
74+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.Linq.MongoQueryProviderImpl`1">
75+
<exactMethodMatcher methodName="ExecuteModel"/>
76+
<exactMethodMatcher methodName="ExecuteModelAsync"/>
77+
</match>
78+
</tracerFactory>
7279

73-
<tracerFactory name="MongoIndexManagerWrapper">
74-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionImpl`1+MongoIndexManager">
75-
<exactMethodMatcher methodName="CreateMany"/>
76-
<exactMethodMatcher methodName="DropAll"/>
77-
<exactMethodMatcher methodName="DropOne"/>
78-
<exactMethodMatcher methodName="List"/>
80+
<tracerFactory name="MongoIndexManagerBaseWrapper">
81+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoIndexManagerBase`1">
82+
<exactMethodMatcher methodName="CreateOne"/>
83+
<exactMethodMatcher methodName="CreateOneAsync"/>
84+
</match>
85+
</tracerFactory>
7986

80-
<exactMethodMatcher methodName="CreateManyAsync"/>
81-
<exactMethodMatcher methodName="DropAllAsync"/>
82-
<exactMethodMatcher methodName="DropOneAsync"/>
83-
<exactMethodMatcher methodName="ListAsync"/>
84-
</match>
85-
</tracerFactory>
87+
<tracerFactory name="MongoIndexManagerWrapper">
88+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionImpl`1+MongoIndexManager">
89+
<exactMethodMatcher methodName="CreateMany"/>
90+
<exactMethodMatcher methodName="DropAll"/>
91+
<exactMethodMatcher methodName="DropOne"/>
92+
<exactMethodMatcher methodName="List"/>
8693

87-
<tracerFactory name="MongoCollectionBaseWrapper">
88-
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionBase`1">
89-
<exactMethodMatcher methodName="DeleteMany"/>
90-
<exactMethodMatcher methodName="DeleteOne"/>
91-
<exactMethodMatcher methodName="InsertOne"/>
92-
<exactMethodMatcher methodName="InsertMany"/>
93-
<exactMethodMatcher methodName="ReplaceOne"/>
94-
<exactMethodMatcher methodName="UpdateMany"/>
95-
<exactMethodMatcher methodName="UpdateOne"/>
94+
<exactMethodMatcher methodName="CreateManyAsync"/>
95+
<exactMethodMatcher methodName="DropAllAsync"/>
96+
<exactMethodMatcher methodName="DropOneAsync"/>
97+
<exactMethodMatcher methodName="ListAsync"/>
98+
</match>
99+
</tracerFactory>
96100

97-
<exactMethodMatcher methodName="DeleteManyAsync"/>
98-
<exactMethodMatcher methodName="DeleteOneAsync"/>
99-
<exactMethodMatcher methodName="InsertOneAsync"/>
100-
<exactMethodMatcher methodName="InsertManyAsync"/>
101-
<exactMethodMatcher methodName="ReplaceOneAsync"/>
102-
<exactMethodMatcher methodName="UpdateManyAsync"/>
103-
<exactMethodMatcher methodName="UpdateOneAsync"/>
104-
</match>
105-
</tracerFactory>
101+
<tracerFactory name="MongoCollectionBaseWrapper">
102+
<match assemblyName="MongoDB.Driver" className="MongoDB.Driver.MongoCollectionBase`1">
103+
<exactMethodMatcher methodName="DeleteMany"/>
104+
<exactMethodMatcher methodName="DeleteOne"/>
105+
<exactMethodMatcher methodName="InsertOne"/>
106+
<exactMethodMatcher methodName="InsertMany"/>
107+
<exactMethodMatcher methodName="ReplaceOne"/>
108+
<exactMethodMatcher methodName="UpdateMany"/>
109+
<exactMethodMatcher methodName="UpdateOne"/>
110+
111+
<exactMethodMatcher methodName="DeleteManyAsync"/>
112+
<exactMethodMatcher methodName="DeleteOneAsync"/>
113+
<exactMethodMatcher methodName="InsertOneAsync"/>
114+
<exactMethodMatcher methodName="InsertManyAsync"/>
115+
<exactMethodMatcher methodName="ReplaceOneAsync"/>
116+
<exactMethodMatcher methodName="UpdateManyAsync"/>
117+
<exactMethodMatcher methodName="UpdateOneAsync"/>
118+
</match>
119+
</tracerFactory>
106120

107121
</instrumentation>
108122
</extension>

0 commit comments

Comments
 (0)