Skip to content

mapgears/sqlalchemy-zipkin

 
 

Repository files navigation

SQLAlchemy-Zipkin

An zipkin extension for SQLAlchemy library based on py_zipkin.

Installation

pip install SQLAlchemy-Zipkin

Usage

import requests
import sqlalchemy_zipkin


PREAMBLE = sqlalchemy_zipkin.ZIPKIN_THRIFT_PREAMBLE


def http_transport(encoded_span):
    # type: (bytes) -> None

    # The collector expects a thrift-encoded list of spans. Instead of
    # decoding and re-encoding the already thrift-encoded message, we can just
    # add header bytes that specify that what follows is a list of length 1.
    url = 'http://zipkin:9411/api/v1/spans'

    body = PREAMBLE + encoded_span
    requests.post(
        url,
        data=body,
        headers={'Content-Type': 'application/x-thrift'},
    )


 sqla_instance = sqlalchemy_zipkin.SqlAlchemyZipkinInstrumentation(
     http_transport, sample_rate=50.0)
 sqla_instance.start()

Reference

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%