Skip to content

Instantly share code, notes, and snippets.

@hkwi
Created July 1, 2019 08:21
Show Gist options
  • Save hkwi/de9aed272ef72f86d754e6e08eb479dc to your computer and use it in GitHub Desktop.
Save hkwi/de9aed272ef72f86d754e6e08eb479dc to your computer and use it in GitHub Desktop.
opentracing instrumentation for flask_restplus and flask_sqlalchemy
from flask import Flask
from flask_restplus import Api, Resource
from flask_sqlalchemy import SQLAlchemy
from flask_opentracing import FlaskTracing
from jaeger_client import Config
from opentracing_instrumentation import get_current_span
from opentracing_instrumentation.client_hooks import install_all_patches
import requests
import sqlalchemy_opentracing
install_all_patches()
c = Config(config={"sampler":{"type":"const","param":1},"logging":True},service_name="test6",validate=True)
def initialize_tracer():
return c.initialize_tracer()
app=Flask(__name__)
tr = FlaskTracing(initialize_tracer, True, app)
db = SQLAlchemy(app)
api = Api(app)
class dA(db.Model):
__tablename__ = "a"
id = db.Column(db.String(36), primary_key=True)
@api.route("/a")
class A(Resource):
def get(self):
assert requests.get("http://example.org").ok
sqlalchemy_opentracing.set_parent_span(db.session, get_current_span())
return dA.query.all()
db.create_all()
app.run(host="0.0.0.0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment