Superskyyy commented on code in PR #263:
URL: https://github.com/apache/skywalking-python/pull/263#discussion_r1059685450
##########
skywalking/plugins/sw_redis.py:
##########
@@ -35,16 +35,121 @@ def install():
def _sw_send_command(this: Connection, *args, **kwargs):
peer = f'{this.host}:{this.port}'
- op = args[0]
+ cmd, key = args[0], args[1]
+
+ if cmd in OPERATIONS_WRITE:
+ op = 'write'
+ elif cmd in OPERATIONS_READ:
+ op = 'read'
+ else:
+ op = ''
+
context = get_context()
- with context.new_exit_span(op=f'Redis/{op}' or '/', peer=peer,
component=Component.Redis) as span:
+ with context.new_exit_span(op=f'Redis/{cmd}' or '/', peer=peer,
component=Component.Redis) as span:
span.layer = Layer.Cache
res = _send_command(this, *args, **kwargs)
- span.tag(TagDbType('Redis'))
- span.tag(TagDbInstance(this.db))
- span.tag(TagDbStatement(op))
+ span.tag(TagCacheType('Redis'))
+ span.tag(TagCacheKey(key))
+ span.tag(TagCacheCmd(cmd))
+ span.tag(TagCacheOp(op))
return res
Connection.send_command = _sw_send_command
+
+
+OPERATIONS_WRITE = set({'GETSET',
Review Comment:
Btw please move the definition of globals to top to reflect a Pythonic
convention.
##########
CHANGELOG.md:
##########
@@ -8,6 +8,7 @@
- Add reporter for PVM runtime metrics (default:disabled) (#238, #247)
- Add Greenlet profiler (#246)
- Add test and support for Python Slim base images (#249)
+ - Add support for the tags of Virtual Cache for Redis (#10212)
Review Comment:
we use the # of PR here I think, so should be (#263)
```suggestion
- Add support for the tags of Virtual Cache for Redis (#263)
```
##########
skywalking/plugins/sw_redis.py:
##########
@@ -35,16 +35,121 @@ def install():
def _sw_send_command(this: Connection, *args, **kwargs):
peer = f'{this.host}:{this.port}'
- op = args[0]
+ cmd, key = args[0], args[1]
+
+ if cmd in OPERATIONS_WRITE:
+ op = 'write'
+ elif cmd in OPERATIONS_READ:
+ op = 'read'
+ else:
+ op = ''
+
context = get_context()
- with context.new_exit_span(op=f'Redis/{op}' or '/', peer=peer,
component=Component.Redis) as span:
+ with context.new_exit_span(op=f'Redis/{cmd}' or '/', peer=peer,
component=Component.Redis) as span:
span.layer = Layer.Cache
res = _send_command(this, *args, **kwargs)
- span.tag(TagDbType('Redis'))
- span.tag(TagDbInstance(this.db))
- span.tag(TagDbStatement(op))
+ span.tag(TagCacheType('Redis'))
+ span.tag(TagCacheKey(key))
+ span.tag(TagCacheCmd(cmd))
+ span.tag(TagCacheOp(op))
return res
Connection.send_command = _sw_send_command
+
+
+OPERATIONS_WRITE = set({'GETSET',
Review Comment:
Is there a place where you get this complete set of supported commands for
redis-py? I mean in case there are updates to supported commands we need a
reference list to update the two sets. (if you have a url please simply add a
comment to the url)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]