Skip to content

Instantly share code, notes, and snippets.

mattupstate /
Last active June 5, 2023 20:50
Decorator vs ASGI spect middleware execution issue with FastAPI

Decorator vs ASGI Spec Middleware with FastAPI and ddtrace Correlation

This illustrates something unexpected about middleware with FastAPI and ddtrace. Below is are two examples of the log output from the minimal application provided here. The first being the log output when the decorator style middleware is added. The second when the decorator style middleware is removed, notice the trace and span ID values are 0. The question is, what is going such that the trace/span ID is only available in the ASGI spec when the decorator style is also applied.

declare module 'humio' {
interface Options {
ssl?: boolean;
host: string;
port: number;
basePath?: string;
dataspaceId?: string;
sessionId?: string;
includeClientMetadata?: boolean;
includeSessionId?: boolean;
mattupstate /
Last active July 21, 2020 17:39
Just a clever way to set an RDS master password with Terraform and Ansible to prevent the password from being stored in plain text
resource "aws_db_instance" "core" {
username = "postgres"
password = "changeme"
resource "null_resource" "master_password" {
triggers {
db_host = "${aws_db_instance.address}"
mattupstate / put-s3-bucket-notification-configuration
Last active January 11, 2022 03:31
Example of how to configure S3 bucket notifications from the command line
#!/usr/bin/env python
import argparse
import sys
import boto3
except ImportError:
print('Please install boto3 to use this tool')

Keybase proof

I hereby claim:

  • I am mattupstate on github.
  • I am mattupstate ( on keybase.
  • I have a public key whose fingerprint is 141F 4546 6A68 8F3D D2C7 0603 28D4 7F5D D3BC 77D5

To claim this, I am signing this object:

mattupstate / output.rst
Created May 19, 2015 23:14
uWSGI heka.statmetric message

2015-05-19 23:11:38.372266224 +0000 UTC












users-frontend-machine1.counters.uwsgi.worker.1.delta_requests.rate 0.000000 1432077098

users-frontend-machine1.counters.uwsgi.worker.1.delta_requests.count 0 1432077098 users-frontend-machine1.counters.uwsgi.worker.2.delta_requests.rate 0.000000 1432077098 users-frontend-machine1.counters.uwsgi.worker.2.delta_requests.count 0 1432077098

mattupstate /
Created May 19, 2015 18:24
Ansible module to gather a Cloudformation stack outputs into variable scope
# -*- coding: utf-8 -*-
import boto
from boto import cloudformation
except ImportError:
HAS_BOTO = False
mattupstate /
Last active September 27, 2020 17:56
A script to generate an SSH config from Consul's HTTP API
#!/usr/bin/env python3
Renders a partial SSH configuration file from Nodes and Services
located in a specified Consul catalog and then merges other partial
config files into the main ~/.ssh/config file. The Consul based SSH
config follows a convention for the SSH host::
Host <consul-cluster-name>-<service-name>-<node-address>
User <ssh-user>
Hostname <consul-node-address>
mattupstate /
Created February 5, 2015 03:37
JSON Patch SQLAlchemy models w/ Flask
from dictalchemy import make_class_dictable
from flask import Flask, request, jsonify, json
from flask_sqlalchemy import SQLAlchemy
from jsonpatch import JsonPatch, JsonPatchException
app = Flask(__name__)
app.debug = True
db = SQLAlchemy(app)
mattupstate /
Created December 10, 2014 21:29
python url62 implementation
import string
import uuid
alphabet = string.digits + string.ascii_letters
def base62_encode(n):
ret = ''
while n > 0:
ret = alphabet[n % 62] + ret
n /= 62