Skip to main content

Framework Integrations

Ready made libraries

There are some ready to go libraries for some languages that configure the ORM and includes a middleware.


An official Django integration available that will wrap all requests in transactions and automatically annotate them:


There is an official project for automatically annotating Pheonix project using Ecto.


For a few other languages, you can use these templates below to get started annotating transactions:

Python / SQLAlchemy

class StatetraceAnnotation(Base):
__tablename__ = 'statetrace_annotations'
id = Column(Text(), primary_key=True)
kind = Column(Text())
meta = Column(JSON())
payload = Column(JSON())

sess_id = str(uuid.uuid4())
session = Session()
with session.begin():
session_annotation = StatetraceAnnotation(id=sess_id, kind="", meta={}, payload={"session_actor_id": 1})

# For each action you want to annotate, connect with session
session = Session()
with session.begin():
# Do your stuff
# ...

session_annotation = StatetraceAnnotation(id=str(uuid.uuid4()), kind="", meta={}, payload={"action_session_id": sess_id})

TypeScript / TypeORM

import { Entity, PrimaryColumn, Column } from "typeorm";
import { v4 as uuidv4 } from 'uuid';

export class StatetraceAnnotation {

id: string;

kind: string;

meta: json;

payload: json;

const sessionID = uuidv4();

const sessAnnotation = new StatetraceAnnotation(); = sessionID;
sessAnnotation.kind = "";
sessAnnotation.payload = {"session_actor_id": 1};

await getConnection().transaction(async transactionalEntityManager => {
// Do your work
// ...

const annotation = new StatetraceAnnotation(); = uuidv4();
annotation.kind = "";
annotation.payload = {"action_session_id": sessionID};