Skip to content

Instantly share code, notes, and snippets.

View jakedsouza's full-sized avatar

Jake Dsouza jakedsouza

View GitHub Profile
@jakedsouza
jakedsouza / README.md
Created September 12, 2023 05:23 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@jakedsouza
jakedsouza / README.md
Created September 12, 2023 05:23 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@jakedsouza
jakedsouza / postgres_queries_and_commands.sql
Created August 27, 2021 23:18 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
### Keybase proof
I hereby claim:
* I am jakedsouza on github.
* I am jakedsouza (https://keybase.io/jakedsouza) on keybase.
* I have a public key whose fingerprint is 3886 5AF8 36A8 6800 B680 AF7C AB02 9F80 4173 1D39
To claim this, I am signing this object:
@jakedsouza
jakedsouza / README.md
Created May 17, 2018 21:17 — forked from subfuzion/README.md
vim/neovim configuration

I recently switched over to neovim (see my screenshots at the bottom). Below is my updated config file.

It's currently synchronized with my .vimrc config except for a block of neovim-specific terminal key mappings.

This is still a work in progress (everyone's own config is always a labor of love), but I'm already extremely pleased with how well this is working for me with neovim. While terminal mode isn't enough to make me stop using tmux, it is quite good and I like having it since it simplifies my documentation workflow for yanking terminal output to paste in a markdown buffer.

These days I primarily develop in Go. I'm super thrilled and grateful for fatih/vim-go,

@jakedsouza
jakedsouza / ubuntu.sh
Created February 17, 2018 00:44
Minimal ubuntu setup
#!/bin/bash
require_root() {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
}
update_apt() {
@jakedsouza
jakedsouza / Prometheus.md
Created February 16, 2018 02:18
Prometheus notes
### gen certs
# Create your CA crt and key:
openssl req -new -x509 -nodes -newkey rsa:4096 \
-extensions v3_ca -sha256 -days 3650 \
-subj "/C=US/ST=CA/L=Palo Alto/O=Jakes Inc./CN=Jake Certificate Authority" \
-keyout ca.key \
-out ca.crt
chmod 600 ca.key
@jakedsouza
jakedsouza / main.go
Created October 23, 2016 09:11 — forked from mschoebel/main.go
Snippet: login/logout (Golang)
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"net/http"
)
// cookie handling
@jakedsouza
jakedsouza / bumpversion.sh
Created October 5, 2016 06:03 — forked from pete-otaqui/bumpversion.sh
Bump a software project's VERSION, add the CHANGES, and tag with GIT
#!/bin/bash
# works with a file called VERSION in the current directory,
# the contents of which should be a semantic version number
# such as "1.2.3"
# this script will display the current version, automatically
# suggest a "minor" version update, and ask for input to use
# the suggestion, or a newly entered value.