GithubHelp home page GithubHelp logo

mpilquist / skunk-arguments-tracing-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zcox/skunk-arguments-tracing-example

0.0 1.0 0.0 10 KB

Demonstrates Skunk tracing/logging arguments

Scala 100.00%

skunk-arguments-tracing-example's Introduction

Simple example that shows Skunk leaking database query/command arguments to tracing and logging. These arguments can contain sensitive data, PII, etc, which should not be exposed to tracing/logging backends.

This example is based on the Skunk command example and uses the Natchez log tracing backend.

docker compose up -d
sbt run

Note that Skunk leaks all inserted data to the tracing backend, in the arguments field of the bind trace:

  "arguments" : "Bob,12",
  "arguments" : "John,2,George,3,Paul,6,Ringo,3",

On a Postgres error/exception (e.g. primary key violation), Skunk leaks the arguments to the tracing backend in the error.argument.n.value fields:

  "error.argument.1.value" : "Bob",
  "error.argument.2.value" : "12",

And the error.detail field:

 "error.detail" : "Key (name)=(Bob) already exists."

If the Postgres error/exception occurs within a transaction, then something within Skunk appears to log the error, with arguments, directly to stdout/stderr. We have not found a way to prevent this.

skunk.exception.PostgresErrorException:
๐Ÿ”ฅ
๐Ÿ”ฅ  Postgres ERROR 23505 raised in _bt_check_unique (nbtinsert.c:664)
๐Ÿ”ฅ
๐Ÿ”ฅ    Problem: Duplicate key value violates unique constraint "pets_pkey".
๐Ÿ”ฅ     Detail: Key (name)=(Bob) already exists.
๐Ÿ”ฅ
๐Ÿ”ฅ  The statement under consideration was defined
๐Ÿ”ฅ    at /Users/ZCox/code/zcox/skunk-arguments-tracing-example/src/main/scala/Main.scala:27
๐Ÿ”ฅ
๐Ÿ”ฅ    INSERT INTO pets VALUES ($1, $2)
๐Ÿ”ฅ
๐Ÿ”ฅ  and the arguments were provided
๐Ÿ”ฅ    at /Users/ZCox/code/zcox/skunk-arguments-tracing-example/src/main/scala/Main.scala:48
๐Ÿ”ฅ
๐Ÿ”ฅ    $1 varchar    Bob
๐Ÿ”ฅ    $2 int2       12
๐Ÿ”ฅ
๐Ÿ”ฅ  If this is an error you wish to trap and handle in your application, you can do
๐Ÿ”ฅ  so with a SqlState extractor. For example:
๐Ÿ”ฅ
๐Ÿ”ฅ    doSomething.recoverWith { case SqlState.UniqueViolation(ex) =>  ...}
๐Ÿ”ฅ

skunk.exception.PostgresErrorException: Duplicate key value violates unique constraint "pets_pkey".
  at skunk.net.protocol.Execute$$anon$1$$anonfun$$nestedInanonfun$apply$2$1.$anonfun$applyOrElse$8(Execute.scala:69)
  at flatten$extension @ skunk.util.Pool$.$anonfun$ofF$2(Pool.scala:103)
  at flatMap @ skunk.net.BufferedMessageSocket$$anon$1.$anonfun$receive$1(BufferedMessageSocket.scala:150)
  at get @ skunk.util.Pool$.free$1(Pool.scala:156)
  at flatMap @ skunk.net.BufferedMessageSocket$$anon$1.receive(BufferedMessageSocket.scala:147)

skunk-arguments-tracing-example's People

Contributors

zcox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.