Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit bccd6be

Browse files
authored
Enforce/strictNullChecks: MongoDB Plugin (#412)
1 parent 3876e91 commit bccd6be

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

packages/opencensus-instrumentation-mongodb/src/mongodb.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export class MongoDBPlugin extends BasePlugin {
7575
return function(
7676
// tslint:disable-next-line:no-any
7777
this: mongodb.Server, ns: string, command: any,
78-
options: {}|Function,
79-
callback: Function|undefined): mongodb.Server {
78+
options: {}|Function, callback: Function): mongodb.Server {
8079
const resultHandler =
8180
typeof options === 'function' ? options : callback;
8281
if (plugin.tracer.currentRootSpan && arguments.length > 0 &&

packages/opencensus-instrumentation-mongodb/test/test-mongodb.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {CoreTracer, RootSpan, Span, SpanEventListener, SpanKind} from '@opencensus/core';
18-
import {logger} from '@opencensus/core';
17+
import {CoreTracer, RootSpan, SpanEventListener, SpanKind} from '@opencensus/core';
1918
import * as assert from 'assert';
20-
import {accessSync} from 'fs';
21-
import * as http from 'http';
22-
import * as mocha from 'mocha';
2319
import * as mongodb from 'mongodb';
24-
import * as semver from 'semver';
25-
2620
import {plugin} from '../src/';
27-
import {MongoDBPlugin} from '../src/';
2821

2922
export type MongoDBAccess = {
3023
client: mongodb.MongoClient,
@@ -110,7 +103,7 @@ describe('MongoDBPlugin', () => {
110103
before((done) => {
111104
tracer.start({samplingRate: 1});
112105
tracer.registerSpanEventListener(rootSpanVerifier);
113-
plugin.enable(mongodb, tracer, VERSION, {}, null);
106+
plugin.enable(mongodb, tracer, VERSION, {}, '');
114107
accessCollection(URL, DB_NAME, COLLECTION_NAME)
115108
.then(result => {
116109
client = result.client;
@@ -218,7 +211,7 @@ describe('MongoDBPlugin', () => {
218211
describe('Instrumenting command operations', () => {
219212
it('should create a child span for create index', (done) => {
220213
tracer.startRootSpan({name: 'indexRootSpan'}, (rootSpan: RootSpan) => {
221-
collection.createIndex({a: 1}, null, (err, result) => {
214+
collection.createIndex({a: 1}, (err, result) => {
222215
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0);
223216
rootSpan.end();
224217
assert.ifError(err);
@@ -282,7 +275,7 @@ describe('MongoDBPlugin', () => {
282275

283276
it('should not create a child span for command', (done) => {
284277
tracer.startRootSpan({name: 'indexRootSpan'}, (rootSpan: RootSpan) => {
285-
collection.createIndex({a: 1}, null, (err, result) => {
278+
collection.createIndex({a: 1}, (err, result) => {
286279
assert.strictEqual(rootSpanVerifier.endedRootSpans.length, 0);
287280
rootSpan.end();
288281
assert.ifError(err);

packages/opencensus-instrumentation-mongodb/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"pretty": true,
88
"module": "commonjs",
99
"target": "es6",
10-
"strictNullChecks": false
10+
"strictNullChecks": true,
11+
"noUnusedLocals": true
1112
},
1213
"include": [
1314
"src/**/*.ts",
@@ -17,4 +18,3 @@
1718
"node_modules"
1819
]
1920
}
20-

0 commit comments

Comments
 (0)