Data Logging with Golang: How to Store Customer Details Securely

Vadzim Zapolski-Dounar
Apr 22 · 5 min read
Image for post
Image for post
A Shutterstock image

The problem: How do we find a balance between full contextual logging and preventing any privacy violations?


Hands on: Sample Logger and it’s pitfalls

Sample logger
Sample controller
Main function
Protocol buffers for Company
1970/01/01 00:00:00 error: failed to process company id:11 owner:{id:1 name:"Batman" email:"batman@cave.com" title:{id:100001 name:"CLSO - Chief Life Savior Officer"}} coOwner:{id:2 name:"Catwoman" email:"catwoman@box.com" title:{id:100002 name:"CCO - Chef Cuddling Officer"}} size:3

Advanced Logger with parameters sanitization

Image for post
Image for post
Sanitizing before logging
Protocol options extension
company.proto with the newly introduced option for logField
Image for post
Image for post
Differences after applying newly introduced option for logField

Reflection magic for sanitizing

Sanitize function which calls sanitizeProtoMessage
sanitizeProtoMessage recursive — goes over all Message fields to extract the logField
Extracting logField option for specific field
Filtering out empty prefixes
1970/01/01 00:00:00 error: failed to process company map[co_owner_profession_id:100002 co_owner_user_id:2 company_id:11 owner_profession_id:100001 owner_user_id:1 size:3]
Image for post
Image for post
The difference after applying sanitization of fields based on reflection

Pipedrive Engineering

Stories from the developers at Pipedrive and developers who…

Thanks to Mikk Mangus

Vadzim Zapolski-Dounar

Written by

Principle developer @ Pipedrive, hacking in NodeJS and Golang

Pipedrive Engineering

Stories from the developers at Pipedrive and developers who work with Pipedrive

Vadzim Zapolski-Dounar

Written by

Principle developer @ Pipedrive, hacking in NodeJS and Golang

Pipedrive Engineering

Stories from the developers at Pipedrive and developers who work with Pipedrive

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store