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

aioredis instrumentation fix with extra context and statement #1406

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ endif::[]

// Unreleased changes go here
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
//[float]
//===== Features
//
[float]
===== Features

* Add redis query to context data for redis instrumentation {pull}1406[#1406]

[float]
===== Bug fixes

Expand Down
8 changes: 7 additions & 1 deletion elasticapm/instrumentation/packages/asyncio/aioredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ class RedisConnectionInstrumentation(AbstractInstrumentedModule):

def call(self, module, method, wrapped, instance, args, kwargs):
span = execution_context.get_span()
if span and span.subtype == "aioredis":
db_context = None
if args and len(args) > 1:
func_name = args[0].decode("utf-8") if isinstance(args[0], bytes) else args[0]
db_context = {"type": "query", "statement": "{} {}".format(func_name, args[1])}
if span and span.subtype == self.name:
span.context["destination"] = _get_destination_info(instance)
if db_context:
span.context["db"] = db_context
return wrapped(*args, **kwargs)


Expand Down
8 changes: 7 additions & 1 deletion elasticapm/instrumentation/packages/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ class RedisConnectionInstrumentation(AbstractInstrumentedModule):

def call(self, module, method, wrapped, instance, args, kwargs):
span = execution_context.get_span()
if span and span.subtype == "redis":
db_context = None
if args and len(args) > 1:
func_name = args[0].decode("utf-8") if isinstance(args[0], bytes) else args[0]
db_context = {"type": "query", "statement": "{} {}".format(func_name, args[1])}
if span and span.subtype == self.name:
span.context["destination"] = get_destination_info(instance)
if db_context:
span.context["db"] = db_context
return wrapped(*args, **kwargs)


Expand Down