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(grpc-js): add @grpc/grpc-js plugin #1201

Merged
merged 20 commits into from
Jul 21, 2020

Conversation

markwolff
Copy link
Member

@markwolff markwolff commented Jun 16, 2020

Which problem is this PR solving?

Short description of the changes

Not a lot of "new" code here. Most of it is copied or moved over from the existing grpc plugin.

  • Adds patching for @grpc/grpc-js library
  • Creates new @opentelemetry/grpc-utils private package which contains shared test suite that will be used by @opentelemetry/plugin-grpc / @opentelemetry/plugin-grpc-js. This code is what was previously in grpc.test.ts.
    • I do not think it is useful longterm to share patching here since there are a few subtle internal differences between grpc and @grpc/grpc-js and they could further diverge in the future.
    • Opentelemetry "span management" could be shared, however! (e.g. attributes, statuses, links, etc)
- opentelemetry-plugin-grpc-js
- - opentelemetry-grpc-utils/test
- opentelemetry-plugin-grpc
- - opentelemetry-grpc-utils/test

@markwolff markwolff changed the title Feat/add grpc js plugin feat(grpc-js): add @grpc/grpc-js plugin Jun 16, 2020
@codecov
Copy link

codecov bot commented Jun 16, 2020

Codecov Report

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

@@            Coverage Diff             @@
##           master    #1201      +/-   ##
==========================================
+ Coverage   92.37%   92.69%   +0.32%     
==========================================
  Files         181      193      +12     
  Lines        4378     4804     +426     
  Branches      922      982      +60     
==========================================
+ Hits         4044     4453     +409     
- Misses        334      351      +17     
Impacted Files Coverage Δ
...ry-plugin-xml-http-request/src/enums/EventNames.ts 100.00% <0.00%> (ø)
...ackages/opentelemetry-plugin-grpc-js/src/grpcJs.ts 100.00% <0.00%> (ø)
...packages/opentelemetry-plugin-grpc-js/src/utils.ts 88.88% <0.00%> (ø)
...s/opentelemetry-plugin-grpc-js/src/client/utils.ts 96.59% <0.00%> (ø)
...y-plugin-grpc-js/src/server/serverStreamAndBidi.ts 100.00% <0.00%> (ø)
...telemetry-plugin-grpc-js/src/server/patchServer.ts 95.00% <0.00%> (ø)
...-plugin-grpc-js/src/server/clientStreamAndUnary.ts 100.00% <0.00%> (ø)
...s/opentelemetry-plugin-grpc-js/src/server/index.ts 100.00% <0.00%> (ø)
...s/opentelemetry-plugin-grpc-js/src/client/index.ts 100.00% <0.00%> (ø)
...plugin-grpc-js/src/client/loadPackageDefinition.ts 100.00% <0.00%> (ø)
... and 2 more

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.

just first pass as the pr is big

packages/opentelemetry-plugin-grpc-js/src/grpcJs.ts Outdated Show resolved Hide resolved
.map(methodName => methods[methodName].originalName)
.filter(
originalName =>
// eslint-disable-next-line no-prototype-builtins
Copy link
Member

Choose a reason for hiding this comment

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

should we disable this rule completely ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, do you mean for the entire project? I am not opposed... I think the only benefit it has for this project is to gently discourage using builtins unless necessary

Copy link
Member

Choose a reason for hiding this comment

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

we are patching many things, so I guess this might be not needed rule at all for this project, this is just my thought :)

packages/opentelemetry-plugin-grpc-js/src/client/utils.ts Outdated Show resolved Hide resolved
@obecny
Copy link
Member

obecny commented Jun 16, 2020

what's happened to unit tests ?

@markwolff
Copy link
Member Author

what's happened to unit tests ?

The API layers between grpc & @grpc/grpc-js are the same and so I've moved the tests to a shared & unpublished @opentelemetry/grpc-utils package.

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.

have 2 questions yet, but it lgtm

packages/opentelemetry-plugin-grpc-js/src/grpcJs.ts Outdated Show resolved Hide resolved
super('@opentelemetry/plugin-grpc-js', VERSION);
}

protected patch(): typeof grpcJs {
throw new Error('Method not implemented.');
this.tracer = this._tracer;
Copy link
Member

Choose a reason for hiding this comment

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

should this be somehow unpatched in unpatch

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. This would be to prevent a dangling reference on this reference right? I've added jsdoc comment to their declarations and nulled them out here via

(this.tracer as Tracer | null) = null;
(this.logger ...) = null

Copy link
Member

Choose a reason for hiding this comment

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

I don't think a dangling reference here is a big deal as there can only ever be one of them. If there was a new reference on each call to patch then maybe it would be a problem.

@mayurkale22
Copy link
Member

@open-telemetry/javascript-approvers ^^

Copy link

@sk- sk- left a comment

Choose a reason for hiding this comment

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

Added suggestions around slices for copying an object, which we can change to use the spread operator instead, which has been supported since node 5. See https://node.green/#ES2015-syntax-spread-syntax-for-iterable-objects

packages/opentelemetry-grpc-utils/test/grpcUtils.test.ts Outdated Show resolved Hide resolved
packages/opentelemetry-grpc-utils/test/grpcUtils.test.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc-js/src/client/utils.ts Outdated Show resolved Hide resolved
packages/opentelemetry-grpc-utils/test/grpcUtils.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

lgtm

): void {
let spanEnded = false;
const endSpan = () => {
if (!spanEnded) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking that we should expose a property on the SDK's span that represent if the span has been ended. There are few plugins that implement something like this which add memory overhead for nothing, WDYT ?

@dyladan
Copy link
Member

dyladan commented Jul 21, 2020

@sk- thanks for your thorough review :)

@mayurkale22 mayurkale22 merged commit e056558 into open-telemetry:master Jul 21, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
… becoming an owner (open-telemetry#1201)

* chore(instrumentation-graphql): turn off failing test and releases

* chore: keep releasing GraphQL

* chore: fix wording on readme

* chore: apply @dyladan's suggestions

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for @grpc/grpc-js 1.x
6 participants