-
Notifications
You must be signed in to change notification settings - Fork 685
Update database instrumentations to follow semantic conventions #175
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
Changes from 4 commits
90aed52
ab76f56
e19b3ba
a9070ab
99d6dfc
793cbc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,21 +73,23 @@ def started(self, event: monitoring.CommandStartedEvent): | |
span = self._tracer.start_span(name, kind=SpanKind.CLIENT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In terms of the name, I think we can remove the "DATABASE_TYPE" portion and just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT: We can leave these in until the specs are finalized. |
||
if span.is_recording(): | ||
span.set_attribute("component", DATABASE_TYPE) | ||
span.set_attribute("db.type", DATABASE_TYPE) | ||
span.set_attribute("db.instance", event.database_name) | ||
span.set_attribute("db.system", DATABASE_TYPE) | ||
span.set_attribute("db.name", event.database_name) | ||
span.set_attribute("db.statement", statement) | ||
if event.connection_id is not None: | ||
span.set_attribute("net.peer.name", event.connection_id[0]) | ||
span.set_attribute("net.peer.port", event.connection_id[1]) | ||
|
||
# pymongo specific, not specified by spec | ||
span.set_attribute("db.mongo.operation_id", event.operation_id) | ||
span.set_attribute("db.mongo.request_id", event.request_id) | ||
span.set_attribute( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove these attributes as they are not in the semantic conventions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @toumorokoshi also expressed the same concern on this attrs. I will remove them. |
||
"db.mongodb.operation_id", event.operation_id | ||
) | ||
span.set_attribute("db.mongodb.request_id", event.request_id) | ||
|
||
for attr in COMMAND_ATTRIBUTES: | ||
_attr = event.command.get(attr) | ||
if _attr is not None: | ||
span.set_attribute("db.mongo." + attr, str(_attr)) | ||
span.set_attribute("db.mongodb." + attr, str(_attr)) | ||
|
||
# Add Span to dictionary | ||
self._span_dict[_get_span_dict_key(event)] = span | ||
|
@@ -106,7 +108,7 @@ def succeeded(self, event: monitoring.CommandSucceededEvent): | |
return | ||
if span.is_recording(): | ||
span.set_attribute( | ||
"db.mongo.duration_micros", event.duration_micros | ||
"db.mongodb.duration_micros", event.duration_micros | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And these should be removed as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec doesn't have these either. |
||
) | ||
span.end() | ||
|
||
|
@@ -119,7 +121,7 @@ def failed(self, event: monitoring.CommandFailedEvent): | |
return | ||
if span.is_recording(): | ||
span.set_attribute( | ||
"db.mongo.duration_micros", event.duration_micros | ||
"db.mongodb.duration_micros", event.duration_micros | ||
) | ||
span.set_status(Status(StatusCode.ERROR, event.failure)) | ||
span.end() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,14 @@ | |
def _extract_conn_attributes(conn_kwargs): | ||
""" Transform redis conn info into dict """ | ||
attributes = { | ||
"db.type": "redis", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Span name for redis needs to be fixed too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is span attribute. The span name for redis is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I only highlighted this because Github didn't let point to the above code. Simiarly to pymemcache for redis, is there not a concept of "statement" or "command"? The string "redis.command" doesn't really tell me much in terms of what logical operation redis is doing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agree. |
||
"db.instance": conn_kwargs.get("db", 0), | ||
"db.system": "redis", | ||
"db.name": conn_kwargs.get("db", 0), | ||
} | ||
try: | ||
attributes["db.url"] = "redis://{}:{}".format( | ||
conn_kwargs["host"], conn_kwargs["port"] | ||
) | ||
except KeyError: | ||
pass # don't include url attribute | ||
attributes["net.peer.name"] = conn_kwargs["host"] | ||
attributes["net.peer.port"] = conn_kwargs["port"] | ||
except KeyError: # Connected using unix socket | ||
attributes["net.peer.name"] = conn_kwargs["path"] | ||
|
||
return attributes | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the span name should be a low-cardinality value representing the executed statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also add
db.name
as a span attribute to be consistent with the other instrumentations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The span name for all pymemcache commands is
memcached.command
. Regardingdb.name
there isdb.system
which is set to here. Do you think we needdb.name
set to same as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar in how to use pymemcache, but does that mean there is no "command" or "statement" that is executed?
Yes, we have
db.name
in other instrumentations so we should be consistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has commands. Yes we should be using them instead of hard-coded
memcached.command
for span name. I don't thinkdb.name
is applicable for memcached.