Skip to content

Commit

Permalink
ZO-4267: support dict and list params for sql tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
stollero authored and louika committed Mar 1, 2024
1 parent b842483 commit 9887322
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/zeit/connector/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,19 @@ def __init__(self, engine, **kw):
def start_span(self, *args, **kw):
return zeit.cms.tracing.start_span(__name__ + '.tracing', *args, **kw)

def _write(self, buffer, params):
for k, v in params.items():
buffer.write('%s=%r\n' % (k, str(v)[:100]))

def _before_cur_exec(self, conn, cursor, statement, params, context, executemany):
statement, params = super()._before_cur_exec(
conn, cursor, statement, params, context, executemany
)
p = StringIO()
for k, v in params.items():
p.write('%s=%r\n' % (k, str(v)[:100]))
if isinstance(params, (list, tuple)):
for param in params:
self._write(p, param)
elif isinstance(params, dict):
self._write(p, params)
context._otel_span.set_attribute('db.parameters', p.getvalue())
return statement, params

0 comments on commit 9887322

Please sign in to comment.