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(plugin): add grpc plugin #215

Merged
merged 19 commits into from
Sep 11, 2019

Conversation

markwolff
Copy link
Member

@markwolff markwolff commented Aug 22, 2019

Which problem is this PR solving?

Short description of the changes

  • Adds trace collection plugin for gRPC

TODOs

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.

Look good. Added few comments. methods and properties (private and protected) should be prefixed with "_"


export class GrpcPlugin extends BasePlugin<grpc> {
static readonly component = 'grpc';
static readonly ATTRIBUTE_GRPC_KIND = 'grpc.kind'; // SERVER or CLIENT
Copy link
Member

Choose a reason for hiding this comment

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

Should move to AttributeNames, WDYT?

// TODO: Delete if moving internal file loaders to BasePlugin
// --- Note: Incorrectly ordered: Begin internal file loader --- //
// tslint:disable-next-line:no-any
protected internalFilesExports: { [key: string]: any };
Copy link
Member

Choose a reason for hiding this comment

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

Should be prefixed by _

// TODO: Remove this once issue is resolved
// https://github.com/open-telemetry/opentelemetry-js/issues/193
this._logger = new NoopLogger();
this.internalFilesExports = this.loadInternalFiles();
Copy link
Member Author

Choose a reason for hiding this comment

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

this can be removed pending discussion #216

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.

This is a great start :) Added a few comments, during initial glance. Will add more once ready for review.

packages/opentelemetry-plugin-grpc/package.json Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
@markwolff markwolff marked this pull request as ready for review August 30, 2019 20:54
@@ -247,29 +237,23 @@ export class GrpcPlugin extends BasePlugin<grpc> {
const self = this;

const spanName = `grpc.${name.replace('/', '')}`;
const parentSpan = plugin._getSpanContext(call.metadata);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this calling a private function on the plugin? If so, why does it need to do that?

Copy link
Member Author

Choose a reason for hiding this comment

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

It only needs it because it needs the binary format parser which is a member of this._tracer. I suppose it could be made a helper function similar to your other proposal, but a tracer (or the binary format parser directly) would need to be passed in instead. What do you think?

* Convert a grpc status code to an opentelemetry Canonical code. For now, the enums are exactly the same
* @param status
*/
private static _grpcStatusCodeToCanonicalCode(
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than making this private static, what would you think about just having it be a non-exported function in the file? I personally find that cleaner for helper functions than attaching them to a class

Copy link
Member

Choose a reason for hiding this comment

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

+1

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 have an existing utils.ts already. Maybe I can just move them inside there?

@@ -6,7 +6,7 @@
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json test/**/*.ts",
"test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to keep it standardized everywhere, either change all packages script to test/**/*.test.ts or keep it test/**/*.ts. WDYT?

packages/opentelemetry-plugin-grpc/package.json Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc-types.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-grpc/src/grpc.ts Outdated Show resolved Hide resolved
* Convert a grpc status code to an opentelemetry Canonical code. For now, the enums are exactly the same
* @param status
*/
private static _grpcStatusCodeToCanonicalCode(
Copy link
Member

Choose a reason for hiding this comment

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

+1

metadata: grpcModule.Metadata;
status: GrpcStatus;
// tslint:disable-next-line:no-any
request?: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work for this to be of unknown type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to unknown type (and a few other places where it made sense)

* limitations under the License.
*/

// Equivalent to lodash _.findIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing this utility rather than pulling in lodash itself! (I have seen vulnerabilities on it recently and wouldn't want to expose OpenTelemetry customers to that risk)

@mayurkale22
Copy link
Member

LGTM. @OlivierAlbertini @bg451 @danielkhan Could you please approve this one, if everything looks good, Thanks :)

@markwolff
Copy link
Member Author

markwolff commented Sep 9, 2019

A note about this and #216, I intend to complete this PR and then stub out the internalFilesExports functionality in a separate PR which will also rip out that functionality from this plugin (https://github.com/open-telemetry/opentelemetry-js/pull/215/files#diff-671cbf0fed27b96717e412e39a4dfc30R65). I have no other changes pending for this PR (other than parsing PluginConfig), so if it looks good to everyone else, it can be completed.


plugin._logger.debug(
'patch func: %s',
JSON.stringify(spanOptions)
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity/ignorance, will this json.stringify be executed when logging is not DEBUG?

Copy link
Member Author

@markwolff markwolff Sep 11, 2019

Choose a reason for hiding this comment

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

Yes, it would be executed and then passed to a noop function. Seems wasteful so I'll put this (and anything similar I find) behind an if.

edit: AFAIK the current logging "level" is not implemented/exposed anywhere? If so, I will make this change in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

LogLevel is already implemented and exposed here :

Copy link
Member

Choose a reason for hiding this comment

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

This will be called even if the log level is not matched. This is an expensive call, let's address this in a separate PR.

@mayurkale22 mayurkale22 merged commit c675c86 into open-telemetry:master Sep 11, 2019
@mayurkale22 mayurkale22 mentioned this pull request Sep 11, 2019
@markwolff markwolff deleted the add-grpc-plugin branch September 12, 2019 12:41
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
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.

6 participants