Skip to content

Commit 5fdf8cf

Browse files
committed
Have our project have a setup and files for publishing.
1 parent f31f08d commit 5fdf8cf

8 files changed

Lines changed: 158 additions & 25 deletions

File tree

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include VERSION LICENSE

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.PHONY: test install clean clean-build clean-pyc build
2+
3+
install:
4+
python setup.py install
5+
6+
clean: clean-build clean-pyc
7+
8+
clean-build:
9+
python setup.py clean
10+
rm -fr build/
11+
rm -fr dist/
12+
rm -fr .eggs/
13+
rm -fr .cache/
14+
find . -name '*.egg-info' -exec rm -fr {} +
15+
find . -name '*.egg' -exec rm -rf {} +
16+
17+
clean-pyc:
18+
find . -name '*.pyc' -exec rm -f {} +
19+
find . -name '*.pyo' -exec rm -f {} +
20+
find . -name '*~' -exec rm -f {} +
21+
find . -name '__pycache__' -exec rm -fr {} +
22+
23+
build:
24+
python setup.py build
25+

README.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
11
######################
22
SQLAlchemy Opentracing
33
######################
4+
5+
This package enables OpenTracing support for SQLAlchemy.
6+
7+
Installation
8+
============
9+
10+
Run the following command::
11+
12+
$ pip install sqlalchemy_opentracing
13+
14+
Getting started
15+
===============
16+
17+
Please see the examples directory. Overall, basic usage requires that a tracer gets set, an Engine (or Connection) is registered, and statements get their parent spans assigned (if any):
18+
19+
.. code-block:: python
20+
21+
import sqlalchemy_opentracing
22+
23+
sqlalchemy_opentracing.init_tracing(tracer) # A OpenTracing compatible tracer.
24+
sqlalchemy_opentracing.register_connectable(engine) # A valid SQLAlchemy Engine object.
25+
26+
with engine.begin() as conn:
27+
sel = select([users])
28+
sqlalchemy_opentracing.set_traced(sel)
29+
conn.execute(sel)
30+
31+
By default, only statements marked to be traced are taken into account (explicitly through set_traced() or implicitly when registering its parent span through set_parent_span()). Alternatively, you can enable tracing of all queries under the registered Engine/Connection:
32+
33+
.. code-block:: python
34+
35+
sqlalchemy_opentracing.init_tracing(tracer, trace_all=True)
36+
sqlalchemy_opentracing.register_connectable(engine)
37+
38+
# this statement will be traced too (without a parent span, though)
39+
with engine.begin() as conn:
40+
sel = select([users])
41+
conn.execute(sel)
42+
43+
Further information
44+
===================
45+
46+
If you’re interested in learning more about the OpenTracing standard, please visit `opentracing.io`_ or `join the mailing list`_. If you would like to implement OpenTracing in your project and need help, feel free to send us a note at `community@opentracing.io`_.
47+
48+
.. _opentracing.io: http://opentracing.io/
49+
.. _join the mailing list: http://opentracing.us13.list-manage.com/subscribe?u=180afe03860541dae59e84153&id=19117aa6cd
50+
.. _community@opentracing.io: community@opentracing.io
51+

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

examples/child-spans.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
from sqlalchemy import MetaData, Table, Integer, String, Column, create_engine
3+
from sqlalchemy import select
4+
from sqlalchemy.schema import CreateTable
5+
6+
import lightstep
7+
import sqlalchemy_opentracing
8+
9+
DB_LOCATION = '/tmp/simple.db'
10+
11+
tracer = lightstep.Tracer(
12+
component_name='sqlalchemy-childspans',
13+
access_token='{your_lightstep_token}'
14+
)
15+
16+
17+
if __name__ == '__main__':
18+
os.remove(DB_LOCATION) # cleanup
19+
20+
engine = create_engine('sqlite:///%s' % DB_LOCATION)
21+
conn = engine.connect()
22+
23+
sqlalchemy_opentracing.init_tracing(tracer)
24+
sqlalchemy_opentracing.register_connectable(engine)
25+
26+
span = tracer.start_span('create sample')
27+
28+
# 1. Create a table
29+
metadata = MetaData()
30+
users = Table('users', metadata,
31+
Column('id', Integer, primary_key=True),
32+
Column('name', String),
33+
)
34+
creat = CreateTable(users)
35+
sqlalchemy_opentracing.set_parent_span(creat, span)
36+
conn.execute(creat)
37+
38+
# 2. Insert a single value.
39+
ins = users.insert().values(name='John Doe', id=1)
40+
sqlalchemy_opentracing.set_parent_span(ins, span)
41+
conn.execute(ins)
42+
43+
# 3. Select the new value.
44+
sel = select([users])
45+
sqlalchemy_opentracing.set_parent_span(sel, span)
46+
print conn.execute(sel).fetchone()
47+
48+
span.finish()
49+
tracer.flush()
50+

examples/simple.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
1-
import os
21
from sqlalchemy import MetaData, Table, Integer, String, Column, create_engine
3-
from sqlalchemy import select
42
from sqlalchemy.schema import CreateTable
53

64
import lightstep
75
import sqlalchemy_opentracing
86

9-
DB_LOCATION = '/tmp/simple.db'
10-
117
tracer = lightstep.Tracer(
128
component_name='sqlalchemy-simple',
139
access_token='{your_lightstep_token}'
1410
)
1511

16-
1712
if __name__ == '__main__':
18-
os.remove(DB_LOCATION) # cleanup
19-
20-
engine = create_engine('sqlite:///%s' % DB_LOCATION)
21-
conn = engine.connect()
13+
engine = create_engine('sqlite:///:memory:')
2214

2315
sqlalchemy_opentracing.init_tracing(tracer)
2416
sqlalchemy_opentracing.register_connectable(engine)
2517

26-
span = tracer.start_span('create sample')
27-
28-
# 1. Create a table
2918
metadata = MetaData()
3019
users = Table('users', metadata,
3120
Column('id', Integer, primary_key=True),
3221
Column('name', String),
3322
)
34-
span = tracer.start_span('create sample')
3523
creat = CreateTable(users)
36-
sqlalchemy_opentracing.set_parent_span(creat, span)
37-
conn.execute(creat)
38-
39-
# 2. Insert a single value.
40-
ins = users.insert().values(name='John Doe', id=1)
41-
sqlalchemy_opentracing.set_parent_span(ins, span)
42-
conn.execute(ins)
24+
sqlalchemy_opentracing.set_traced(creat)
4325

44-
# 3. Select the new value.
45-
sel = select([users])
46-
sqlalchemy_opentracing.set_parent_span(sel, span)
47-
print conn.execute(sel).fetchone()
26+
with engine.begin() as conn:
27+
conn.execute(creat)
4828

49-
span.finish()
5029
tracer.flush()
5130

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.rst

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from setuptools import setup
2+
3+
version = open('VERSION').read()
4+
setup(
5+
name='sqlalchemy_opentracing',
6+
version=version,
7+
url='https://github.com/carlosalberto/python-sqlalchemy/',
8+
download_url='https://github.com/carlosalberto/python-sqlalchemy/tarball/'+version,
9+
license='BSD',
10+
author='Carlos Alberto Cortez',
11+
author_email='calberto.cortez@gmail.com',
12+
description='OpenTracing support for SQLAlchemy',
13+
long_description=open('README.rst').read(),
14+
packages=['sqlalchemy_opentracing'],
15+
platforms='any',
16+
install_requires=[
17+
'sqlalchemy',
18+
'opentracing>=1.1,<1.2'
19+
],
20+
classifiers=[
21+
'Intended Audience :: Developers',
22+
'License :: OSI Approved :: BSD License',
23+
'Operating System :: OS Independent',
24+
'Programming Language :: Python',
25+
'Topic :: Software Development :: Libraries :: Python Modules',
26+
]
27+
)

0 commit comments

Comments
 (0)