Created
January 11, 2023 07:21
-
-
Save pandada8/71ebece6eb2007519ebd224e9a0c5882 to your computer and use it in GitHub Desktop.
PymongoInstrumentor with query detail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def request_hook(span: Span, event: monitoring.CommandStartedEvent): | |
# add detail query info to span | |
if span.is_recording(): | |
match event.command_name: | |
case "find": | |
span.set_attribute("filter", dumps(event.command.get("filter"))) | |
case "update": | |
updates = event.command.get("updates") | |
span.set_attribute("filter", dumps(updates.get('q'))) | |
span.set_attribute("update", dumps(updates.get('u'))) | |
span.set_attribute("multi", dumps(updates.get('multi'))) | |
span.set_attribute("upsert", dumps(updates.get('upsert'))) | |
case "delete": | |
span.set_attribute("filter", event.command.get("deletes")) | |
case "insert": | |
span.set_attribute("documents", dumps(event.command.get("documents"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment