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): implement redis plugin #503

Merged
merged 16 commits into from
Nov 19, 2019

Conversation

markwolff
Copy link
Member

@markwolff markwolff commented Nov 7, 2019

Which problem is this PR solving?

Short description of the changes

  • Implements Redis plugin to create/propagate spans on client commands.

@codecov-io
Copy link

codecov-io commented Nov 7, 2019

Codecov Report

Merging #503 into master will increase coverage by 0.08%.
The diff coverage is 87.03%.

@@            Coverage Diff            @@
##           master    #503      +/-   ##
=========================================
+ Coverage   90.22%   90.3%   +0.08%     
=========================================
  Files         144     149       +5     
  Lines        7189    7486     +297     
  Branches      651     662      +11     
=========================================
+ Hits         6486    6760     +274     
- Misses        703     726      +23
Impacted Files Coverage Δ
.../opentelemetry-plugin-redis/test/assertionUtils.ts 100% <100%> (ø)
packages/opentelemetry-plugin-redis/src/redis.ts 100% <100%> (ø)
packages/opentelemetry-plugin-redis/src/enums.ts 100% <100%> (ø)
...kages/opentelemetry-plugin-redis/test/testUtils.ts 15% <15%> (ø)
packages/opentelemetry-plugin-redis/src/utils.ts 91.3% <91.3%> (ø)
...ages/opentelemetry-plugin-redis/test/redis.test.ts 92.85% <92.85%> (ø)
packages/opentelemetry-tracing/src/config.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/src/utility.ts 100% <0%> (ø) ⬆️
...telemetry-plugin-grpc/test/utils/assertionUtils.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-tracing/test/Span.test.ts 100% <0%> (ø) ⬆️
... and 17 more

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.

Overall good, just little things to have the same config as other plugin

packages/opentelemetry-plugin-redis/src/redis.ts Outdated Show resolved Hide resolved
packages/opentelemetry-plugin-redis/src/redis.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

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.

Overall LGTM, added a few minor comments.

@@ -8,11 +8,14 @@
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json '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.

Do you think we should remove "private": true to make this package available for the next release?

Copy link
Member Author

@markwolff markwolff Nov 12, 2019

Choose a reason for hiding this comment

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

Agreed. I removed it from this plugin. I think we should also remove it from other "ready" plugins (separate PR). Seems to just be postgres and http2 currently


export enum AttributeNames {
// required by https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md#databases-client-calls
COMPONENT = 'component',
Copy link
Member

Choose a reason for hiding this comment

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

I think we should move these common attributes to either core or base package, this is being used in almost all the plugins. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

SGTM. I'll create an issue for it.


export class RedisPlugin extends BasePlugin<typeof redisTypes> {
static readonly COMPONENT = 'redis';
readonly supportedVersions = ['^2.6.0']; // should be >= 2.6.0
Copy link
Member

Choose a reason for hiding this comment

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

Could you please include supported version in README.md?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 391326b

// New versions of redis (2.4+) use a single options object
// instead of named arguments
if (arguments.length === 1 && typeof cmd === 'object') {
const span = plugin._tracer.startSpan(`redis-${cmd.command}`, {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const span = plugin._tracer.startSpan(`redis-${cmd.command}`, {
const span = plugin._tracer.startSpan(`${RedisPlugin.COMPONENT}-${cmd.command}`, {

@mayurkale22
Copy link
Member

It would be awesome if you can include the example (may be in separate PR)?

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

Minor style suggestions, but LGTM

private _getPatchInternalSendCommand() {
const plugin = this;
return function internal_send_command(original: Function) {
return function internal_send_command_trace(
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 make sense to move this function out of the class and pass in plugin as an argument (would need to wrap with an arrow function)? That could reducer the indentation of 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.

Is this what you had in mind? 8654a71

}

let spanEnded = false;
const endSpan = (err?: Error | null) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be extracted as a helper function at the top level of the module?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I moved it out. I had to get rid of the spanEnded check, but if the span is being ended more than once, its probably a bug that we should log out anyways.

@mayurkale22
Copy link
Member

@markwolff Could you please resolve Dave's comment and rebase with the master, looks good to go.

@mayurkale22 mayurkale22 merged commit fa583fd into open-telemetry:master Nov 19, 2019
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
martinkuba pushed a commit to martinkuba/opentelemetry-js that referenced this pull request Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Plugin][Request]: Redis plugin
6 participants