Skip to content

Commit

Permalink
aioredis instrumentation fix with extra context and statement (#1406)
Browse files Browse the repository at this point in the history
* aioredis instrumentation fix with extra context and statement

* CHANGELOG

* Add db context to existing span, rather than a new span

Also add to redis, not just aioredis

* Simplify args checking

Co-authored-by: Colton Myers <colton.myers@gmail.com>
Co-authored-by: Colton Myers <colton@myers.fm>
  • Loading branch information
3 people authored Aug 30, 2022
1 parent 070e0c7 commit a4413c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
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

0 comments on commit a4413c1

Please sign in to comment.