Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created January 11, 2023 07:21
Show Gist options
  • Save pandada8/71ebece6eb2007519ebd224e9a0c5882 to your computer and use it in GitHub Desktop.
Save pandada8/71ebece6eb2007519ebd224e9a0c5882 to your computer and use it in GitHub Desktop.
PymongoInstrumentor with query detail
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