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

Instrumenting Redis #21

Closed
wants to merge 53 commits into from
Closed

Instrumenting Redis #21

wants to merge 53 commits into from

Conversation

codeboten
Copy link
Contributor

@codeboten codeboten commented Apr 4, 2020

Porting the existing redis instrumentation to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Patcher interface.

The process to make this happen is pretty straight forward:

  1. move the redis code into the instrumentors directory
  2. move tests
  3. added setup/version files and move code into a similar directory structure to other opentelemetry integrations
  4. fixed relative import paths to using ddtrace package
  5. update the code to use opentelemetry API
  6. update the tests
  7. add tests to tox

Couple of TODOs left:

  1. the original redis instrumentation set a couple of metrics in the metadata, this could be a good opportunity to use the metrics API
  2. pin versions of API & SDK

NOTE: This currently still uses some utility functions in the ddtrace package.

fixes #15

@codeboten codeboten marked this pull request as ready for review April 7, 2020 20:04
@codeboten codeboten requested a review from a team April 9, 2020 18:24
docker-compose.yml Outdated Show resolved Hide resolved
pytest.ini Outdated Show resolved Hide resolved
assert span.attributes["service"] == self.TEST_SERVICE

def test_patch_unpatch(self):
# Test patch idempotence
Copy link
Contributor

Choose a reason for hiding this comment

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

opentelemetry.instrumentor.BaseInstrumentor.instrument already takes care of idempotence. It would be better to move the code inside patch to _instrument in order to be able to benefit from this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it makes sense to test the idempotency of patch/unpatch for anyone using it to programmatically enable instrumentation

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

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

Some more minor comments, I tested and it works with a basic example.

I haven't reviewed the exact attributes you are setting on the span, as those come from datadog I'll suppose they are fine.

import redis

# You can patch redis specifically
patch()

Choose a reason for hiding this comment

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

I strongly think this should be using also the instrumentor interface, but will ignore for now until we clarify those ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I'd rather not block here until the auto-instrumentation interface is completed. Here's an issue to track this: #38



def traced_execute_command(func, instance, args, kwargs):
tracer = trace.get_tracer(_DEFAULT_SERVICE, __version__)

Choose a reason for hiding this comment

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

I think this need some more discussion, creating a new tracer for each operation doesn't look like a good solution to me. Somehow the integration should have access to a tracer and avoid creating it for each operation call. I opened an issue for a related discussion open-telemetry/opentelemetry-python#585.

pipeline.execute()

spans = self.get_spans()
self.assertEqual(len(spans), 2)

Choose a reason for hiding this comment

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

Out of curiosity, what is the second span and why there is not any test on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment to clarify, also updated the test to use different set parameters

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal 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 a minor comment that could be implemented in further PRs.

_CMD = "redis.command"


def patch(tracer=None):

Choose a reason for hiding this comment

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

Maybe it's a good idea to update right now to take a TracerProvider as described in open-telemetry/opentelemetry-python#585. Up to you.

@codeboten
Copy link
Contributor Author

Closing in favour of open-telemetry/opentelemetry-python#595

@codeboten codeboten closed this Apr 17, 2020
toumorokoshi pushed a commit to open-telemetry/opentelemetry-python that referenced this pull request Apr 27, 2020
Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.

Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.

This is replacing open-telemetry/opentelemetry-python-contrib#21

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Chris Kleinknecht <libc@google.com>
NathanielRN pushed a commit to NathanielRN/opentelemetry-python-contrib-1 that referenced this pull request Oct 17, 2020
NathanielRN pushed a commit to NathanielRN/opentelemetry-python-contrib-1 that referenced this pull request Oct 20, 2020
…y#595)

Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.

Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.

This is replacing open-telemetry#21

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Chris Kleinknecht <libc@google.com>
NathanielRN pushed a commit to NathanielRN/opentelemetry-python-contrib-1 that referenced this pull request Oct 24, 2020
…y#595)

Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.

Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.

This is replacing open-telemetry#21

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Chris Kleinknecht <libc@google.com>
NathanielRN pushed a commit to NathanielRN/opentelemetry-python-contrib-1 that referenced this pull request Nov 2, 2020
…y#595)

Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.

Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.

This is replacing open-telemetry#21

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Chris Kleinknecht <libc@google.com>
NathanielRN pushed a commit to NathanielRN/opentelemetry-python-contrib-1 that referenced this pull request Nov 23, 2020
…y#595)

Porting the existing redis instrumentation from the contrib repo to using the OpenTelemetry API and the OpenTelemetry Auto-instrumentation Instrumentor interface.

Similiar to the sqlalchemy PR, the main thing that will need updating is to remove the patch/unpatch methods once the instrumentor interface changes have been merged.

This is replacing open-telemetry#21

Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Chris Kleinknecht <libc@google.com>
@codeboten codeboten deleted the instrumentor-redis branch November 24, 2020 17:05
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 instrumentor for Redis
3 participants