Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mongodb plugin #205

Merged
merged 7 commits into from
Nov 15, 2019

Conversation

vmarchaud
Copy link
Member

@vmarchaud vmarchaud commented Aug 17, 2019

@codecov-io
Copy link

codecov-io commented Aug 17, 2019

Codecov Report

Merging #205 into master will increase coverage by 0.11%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #205      +/-   ##
==========================================
+ Coverage   92.33%   92.44%   +0.11%     
==========================================
  Files         146      145       -1     
  Lines        7047     7111      +64     
  Branches      621      621              
==========================================
+ Hits         6507     6574      +67     
+ Misses        540      537       -3
Impacted Files Coverage Δ
packages/opentelemetry-tracing/src/config.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/src/utility.ts 100% <0%> (ø) ⬆️
...ry-tracing/test/export/SimpleSpanProcessor.test.ts 100% <0%> (ø) ⬆️
...try-node/test/instrumentation/PluginLoader.test.ts 100% <0%> (ø) ⬆️
...pe-async-hooks/test/AsyncHooksScopeManager.test.ts 100% <0%> (ø) ⬆️
...ry-tracing/test/export/ConsoleSpanExporter.test.ts 100% <0%> (ø) ⬆️
...ntelemetry-tracing/test/MultiSpanProcessor.test.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-web/src/WebTracer.ts 100% <0%> (ø) ⬆️
...telemetry-scope-base/test/NoopScopeManager.test.ts 100% <0%> (ø) ⬆️
...y-tracing/test/export/InMemorySpanExporter.test.ts 100% <0%> (ø) ⬆️
... and 5 more

@vmarchaud vmarchaud force-pushed the add-mongodb-plugin branch 3 times, most recently from 8b746cb to 9bef9cb Compare August 21, 2019 21:58
Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added initial comments, what are the version are the supported versions? I think we should target 1-3. Also, we should have unit tests for all supported versions. WDYT?

.circleci/config.yml Outdated Show resolved Hide resolved
packages/opentelemetry-node-tracer/src/NodeTracer.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/test/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/test/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
const error = args[0];
if (error instanceof Error) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why CanonicalCode.UNKNOWN?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it hard to set the correct code depending on the mongodb error, and simpler to just set it as unknown. I don't think it would bring a lot of value to parse the error from mongodb to set the correct error code.

packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
Copy link
Member

@OlivierAlbertini OlivierAlbertini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR look good. Added comments.


/** MongoDB instrumentation plugin for OpenTelemetry */
export class MongoDBPlugin extends BasePlugin<MongoDB> {
private readonly SERVER_FNS = ['insert', 'update', 'remove'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we should prefix private properties with "_"

packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/test/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
@vmarchaud
Copy link
Member Author

Note that the plugin is currently not working, i will make the pr ready for review when it will be

@vmarchaud
Copy link
Member Author

Some update on this: I have started to port opencensus code without success for now, i'm still checking if it should patch mongodb or mongodb-core. I didn't have too much time to look into it in September but it should be better in October (so i'm pretty sure this will not be part of the alpha releases).

@vmarchaud
Copy link
Member Author

vmarchaud commented Oct 13, 2019

Initial implementation is working, feel free to review it althrough i didn't finish yet, as @mayurkale22 said we need to add some tags on each span.

The instrumentation is actually done against mongobdb-core which the lowest level package used by everyone however the maintainers actually merged it with the mongodb package recently so we will need to find a solution to make it work for both.

packages/opentelemetry-plugin-mongodb/package.json Outdated Show resolved Hide resolved
private readonly _SERVER_METHODS = ['insert', 'update', 'remove', 'command'];
private readonly _CURSOR_METHODS = ['_next', 'next'];

protected readonly _supportedVersions = ['>=2 <3'];
Copy link
Member

@OlivierAlbertini OlivierAlbertini Oct 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use supportedVersions from BasePlugin and add tests in order to be sure that plugin is not loaded for other versions (if possible)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to use supportedVersions but i don't think we need to test that it behave correctly in the plugin, it would argue that it need to be done only where the behavior is implemented (ie. in PluginLoader)

packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/package.json Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/package.json Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/src/mongodb.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-mongodb/test/mongodb.test.ts Outdated Show resolved Hide resolved
@vmarchaud
Copy link
Member Author

First round of review has been taken into account ! Here are the attributes i add to each span:

{ 'peer.hostname': 'localhost',
  'peer.port': '27017',
  'db.instance': 'opentelemetry-tests.test',
  'db.type': 'mongodb',
  component: 'mongodb-core',
  'db.statement': '{"a":"?"}' }

@vmarchaud
Copy link
Member Author

I can't reproduce the linting issue in local, for me everything is fine.

@dyladan
Copy link
Member

dyladan commented Nov 11, 2019

@vmarchaud after doing a lerna clean do rm packages/*/**/yarn.lock then do lerna bootstrap. There's a version issue. One of the linting related packages must have updated a patch version that was not in fact backwards compatible.

@vmarchaud
Copy link
Member Author

@mayurkale22 Rebased, should be good to merge !

@dyladan
Copy link
Member

dyladan commented Nov 11, 2019

@vmarchaud do I understand correctly that this only instruments mongodb-core and that the mongodb package is still not instrumented as it no longer depends on mongodb-core?

Looks like it was removed in mongodb/node-mongodb-native@16f9a1c#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L20

@vmarchaud
Copy link
Member Author

@dyladan Yeah indeed, i didn't knew when i started the plugin that it was dropped from mongodb. In the future we will need to decide if we replace this plugin by a mongodb one that will support all versions.

@vmarchaud
Copy link
Member Author

I've rebased & addressed comments from @dyladan @markwolff, please review again ! thanks

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just 2 minor questions

@@ -5,7 +5,6 @@
"outDir": "build"
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
"src/**/*.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all tsconfig.ts has "test" too, what's the reason of removing it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a typescript issue when compiling:

Argument of type 'SimpleSpanProcessor' is not assignable to parameter of type 'SpanProcessor'.
  Types of property 'onStart' are incompatible.
    Type '(span: import("/home/vmarchaud/opentelemetry/opentelemetry-js/packages/opentelemetry-plugin-mongodb-core/node_modules/@opentelemetry/tracing/build/src/Span").Span) => void' is not assignable to type '(span: import("/home/vmarchaud/opentelemetry/opentelemetry-js/packages/opentelemetry-types/build/src/trace/span").Span) => void'.
      Types of parameters 'span' and 'span' are incompatible.
        Type 'Span' is missing the following properties from type 'Span': _tracer, spanContext, kind, attributes, and 17 more.ts(2345)

Which makes no sense since i had the same setup as other plugins then i found out that compiling the test aren't useful since we run them using ts-mocha which was working, i believe we could remove that from all other packages too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging PR now, please open an issue to discuss this separately.

@mayurkale22 mayurkale22 merged commit d80cf56 into open-telemetry:master Nov 15, 2019
Plugins automation moved this from In progress to Done Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Plugins
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants