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: memcached instrumentation #539

Merged
merged 25 commits into from Jun 30, 2021

Conversation

rauno56
Copy link
Member

@rauno56 rauno56 commented Jun 17, 2021

Which problem is this PR solving?

Adds auto-instrumentation for memcached.

Short description of the changes

We're monkey-pathing an public generic command function all methods use internally.

@rauno56 rauno56 requested a review from a team as a code owner June 17, 2021 12:14
@codecov
Copy link

codecov bot commented Jun 17, 2021

Codecov Report

Merging #539 (4956469) into main (a8465a2) will decrease coverage by 0.03%.
The diff coverage is n/a.

❗ Current head 4956469 differs from pull request most recent head 9fde92b. Consider uploading reports for the commit 9fde92b to get more accurate results

@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
- Coverage   94.95%   94.91%   -0.04%     
==========================================
  Files         162      166       +4     
  Lines       10102    10313     +211     
  Branches     1000     1026      +26     
==========================================
+ Hits         9592     9789     +197     
- Misses        510      524      +14     
Impacted Files Coverage Δ
...telemetry-instrumentation-memcached/src/version.ts 100.00% <0.00%> (ø)
...y-instrumentation-memcached/src/instrumentation.ts 96.42% <0.00%> (ø)
...entelemetry-instrumentation-memcached/src/utils.ts 81.25% <0.00%> (ø)
...metry-instrumentation-memcached/test/index.test.ts 93.47% <0.00%> (ø)

import { InstrumentationConfig as BaseInstrumentationConfig } from '@opentelemetry/instrumentation';

export interface InstrumentationConfig extends BaseInstrumentationConfig {
collectCommand?: boolean;
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 use enhancedDatabaseReporting like other db instrumentation do (ex: mongodb) so its consistent ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The name enhancedDatabaseReporting

  1. is not descriptive by itself and;
  2. sounds like it can affect multiple aspects of how the instrumentation works.

I'd personally stay away from such configuration options anywhere.
Happy to change it for you if that's a breaker though! :)

Copy link
Member

Choose a reason for hiding this comment

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

We inherited this from Opencensus, i don't mind changing it but i would prefer to make it the same for all instrumentation anyway. Could you use enhancedDatabaseReporting and open an issue to discuss this ?

Copy link
Member Author

@rauno56 rauno56 Jun 28, 2021

Choose a reason for hiding this comment

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

Could you please share a reference to that in OpenCensus?

I think having config-parity is nice between instrumentations that are drop-in-replacements of each other or at least for the same library.
Since many of the auto-instrumentations will be provided by 3rd parties we can never ensure there is a finite list of options used across all instrumentations across all libs.

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 share a reference to that in OpenCensus?

I was wrong that wasn't from Opencensus directly but from the google cloud tracer sdk (https://github.com/googleapis/cloud-trace-nodejs/search?q=enhancedDatabaseReporting.
You can lookup the initial proposal here: open-telemetry/opentelemetry-js#214

Since many of the auto-instrumentations will be provided by 3rd parties we can never ensure there is a finite list of options used across all instrumentations across all libs.

We cannot ensure consistency with 3rd party instrumentations but we can at least for 1st party instrumentation.

There was a discussion at the time here about this: open-telemetry/opentelemetry-js#614

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the info, @vmarchaud! 🙏 I renamed the config option.

Copy link
Member

Choose a reason for hiding this comment

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

I join the voice of not using enhancedDatabaseReporting parameter. Would be happy to see it replaced with meaningful names everywhere

@obecny
Copy link
Member

obecny commented Jun 28, 2021

in general lgtm, I'm missing just one thing to be able to verify this easily, a working example so that I can generate spans myself, can you please add the example ?

@rauno56
Copy link
Member Author

rauno56 commented Jun 29, 2021

in general lgtm, I'm missing just one thing to be able to verify this easily, a working example so that I can generate spans myself, can you please add the example ?

Added an example!

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.

👍

examples/memcached/tracer.js Outdated Show resolved Hide resolved
});

query.callback = api.context.bind(
context,
Copy link
Member

Choose a reason for hiding this comment

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

did not actually run it, but wouldn't setting the context this way make it so that every span started inside the callback will be the child of the (KIND=CLIENT) memcached span.
Not sure if it's intentional, but I think this is something we try to avoid in instrumentations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was thinking about it as well while implementing it. In some cases it makes sense, in others, not.

What's the correct way to implement it, @vmarchaud , @obecny ?

Copy link
Member

Choose a reason for hiding this comment

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

Since you use .with when calling wrapQueryCompiler you shouldn't need to .bind here (except if the memcached client is loosing context, for example if they have internal queues), if it works without i believe can you can remove

Copy link
Member

Choose a reason for hiding this comment

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

@vmarchaud - do you expect the callback to have the memcached span context? or the parent context?

Copy link
Member

Choose a reason for hiding this comment

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

parent context, we want to have the memcached context only within the internal code that does the request.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, but current implementation is setting the Memcached span as context for the callback.
So do we agree to change it? @rauno56

Copy link
Member

Choose a reason for hiding this comment

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

Since you use .with when calling wrapQueryCompiler you shouldn't need to .bind here (except if the memcached client is loosing context, for example if they have internal queues), if it works without i believe can you can remove

@vmarchaud sorry I was reading your reply without full attention. I think it should still be binded, but to parent context, but not sure about it. better to try and see how it behaves

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

@vmarchaud
Copy link
Member

@rauno56 Should be good to merge after fixing the CI

@dyladan dyladan added the enhancement New feature or request label Jun 30, 2021
@dyladan dyladan merged commit c1b6eec into open-telemetry:main Jun 30, 2021
@rauno56 rauno56 deleted the feat/memcached-instrumentation branch June 30, 2021 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants