Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test PR #6

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2b89356
initial commit of sqlalchemy instrumentation
Apr 16, 2020
1ce3640
adding instrumentation code and test
Apr 16, 2020
dab0d5e
adding integration tests
Apr 16, 2020
b79a08a
cleaning up
Apr 16, 2020
a9d70ad
use psycopg2 parse_dsn method
Apr 16, 2020
295f0f6
more cleanup
Apr 16, 2020
e0be528
adding license headers
Apr 16, 2020
6023635
apply semantic conventions
Apr 16, 2020
b7465cc
adding error to status description
Apr 17, 2020
7de0d10
cleaning up tests
Apr 17, 2020
378054f
cleaning up comments
Apr 17, 2020
7e7b24a
Merge branch 'master' into add-sqlalchemy
Apr 17, 2020
38d4450
isort fixes
Apr 17, 2020
7ef2cdf
Apply suggestions from code review
Apr 17, 2020
ffe2c90
use TestBase
Apr 17, 2020
d91b73d
fix missing dep and lint
Apr 18, 2020
76a6141
fix lint
Apr 18, 2020
8f94ce3
cleaning up docs, adding manifest, receive tracer_provider
Apr 20, 2020
24cf7ea
Merge remote-tracking branch 'origin/master' into add-sqlalchemy
Apr 20, 2020
8362198
removing reload
Apr 20, 2020
7accae8
Apply suggestions from code review
Apr 21, 2020
adb0220
minor cleanup of examples (#603)
Apr 21, 2020
4879c46
Removing reload in testbase (#604)
Apr 21, 2020
ca11d27
Update ext/opentelemetry-instrumentation-sqlalchemy/setup.cfg
Apr 22, 2020
65538cf
auto-instr: Add support for programmatic instrumentation (#579)
ocelotl Apr 22, 2020
58f9166
update changelog
Apr 23, 2020
7654c90
sdk: Improve console span exporter (#505)
mauriciovasquezbernal Apr 23, 2020
0ada248
ext: Expect tracer provider instead of tracer in integrations (#602)
mauriciovasquezbernal Apr 23, 2020
93e537c
updating branch to use latest changes in master
Apr 23, 2020
fc39a59
Merge remote-tracking branch 'origin/master' into add-sqlalchemy
Apr 24, 2020
6a9f708
rename from instrumentation to ext
Apr 24, 2020
9f37c48
finish renaming
Apr 24, 2020
633b7a9
move patch code into Instrumentor
Apr 25, 2020
91a71f2
minor fixes
Apr 25, 2020
5d03e46
Merge remote-tracking branch 'origin/master' into add-sqlalchemy
Apr 26, 2020
90bb1ec
lint fixes
Apr 26, 2020
256a52d
simplifying tests
Apr 26, 2020
490951a
test: Add missing dependency (#614)
ocelotl Apr 27, 2020
8f0e584
tests: pin pylint (#618)
Apr 27, 2020
a832bb0
redis: Porting redis instrumentation from contrib repo (#595)
Apr 27, 2020
47ae2fb
Merge branch 'master' into add-sqlalchemy
Apr 27, 2020
5d675ee
api: Add several configuration related fixes (#583)
ocelotl Apr 27, 2020
8e3ed35
ext/requests: Add instrumentor (#597)
mauriciovasquezbernal Apr 27, 2020
8c360a1
ext/pymongo: Add instrumentor (#612)
mauriciovasquezbernal Apr 27, 2020
fced29b
cleaning up tests, removing mock
Apr 28, 2020
a03b0c4
removing trace_engine, cleaning up docstrings
Apr 28, 2020
963c482
add link to sqlalchemy
Apr 28, 2020
1b0163a
setattr is no longer needed
Apr 28, 2020
184cf45
updating example, adding test for auto-instrumentation
Apr 28, 2020
bb74381
Merge remote-tracking branch 'origin/master' into add-sqlalchemy
Apr 28, 2020
1c731b8
cleaning unnecessary check
Apr 28, 2020
e66172f
fix example
Apr 28, 2020
bdd9925
infra: reduce build time by running longest job early (#626)
Apr 29, 2020
123e2c5
Merge branch 'master' into add-sqlalchemy
c24t Apr 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ exclude =
ext/opentelemetry-ext-jaeger/src/opentelemetry/ext/jaeger/gen/
ext/opentelemetry-ext-jaeger/build/*
docs/examples/opentelemetry-example-app/src/opentelemetry_example_app/grpc/gen/
docs/examples/opentelemetry-example-app/build/*
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*
known_first_party=opentelemetry,opentelemetry_example_app
known_third_party=psutil,pytest
known_third_party=psutil,pytest,redis,redis_opentracing
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ language: python
cache: pip

python:
- 'pypy3'
- '3.8'
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- 'pypy3'

#matrix:
# allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pylint~=2.3
pylint==2.4.4
flake8~=3.7
isort~=4.3
black>=19.3b0,==19.*
Expand Down
9 changes: 6 additions & 3 deletions docs/examples/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library.
trace.set_tracer_provider(TracerProvider())
tracer_provider = trace.get_tracer_provider()

# Enable instrumentation in the requests library.
http_requests.RequestsInstrumentor().instrument()

# Configure a console span exporter.
exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
tracer_provider.add_span_processor(span_processor)
trace.get_tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(tracer_provider)
response = requests.get(url="http://127.0.0.1:5000/")
15 changes: 9 additions & 6 deletions docs/examples/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library.
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.
http_requests.enable(trace.get_tracer_provider())
http_requests.RequestsInstrumentor().instrument()
app = flask.Flask(__name__)
app.wsgi_app = OpenTelemetryMiddleware(app.wsgi_app)

# Configure a console span exporter.
exporter = ConsoleSpanExporter()
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

tracer = trace.get_tracer(__name__)


@app.route("/")
def hello():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
SimpleExportSpanProcessor,
)

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
# It must be done before instrumenting any library
trace.set_tracer_provider(TracerProvider())

opentelemetry.ext.http_requests.RequestsInstrumentor().instrument()
FlaskInstrumentor().instrument()

trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)

FlaskInstrumentor().instrument()

app = flask.Flask(__name__)
opentelemetry.ext.http_requests.enable(trace.get_tracer_provider())


@app.route("/")
Expand Down
7 changes: 7 additions & 0 deletions docs/ext/redis/redis.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry Redis Instrumentation
===================================

.. automodule:: opentelemetry.ext.redis
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/ext/sqlalchemy/sqlalchemy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OpenTelemetry SQLAlchemy Instrumentation
========================================

.. automodule:: opentelemetry.ext.sqlalchemy
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ And let's write a small Flask application that sends an HTTP request, activating
)

app = flask.Flask(__name__)
opentelemetry.ext.http_requests.enable(trace.get_tracer_provider())
opentelemetry.ext.http_requests.RequestsInstrumentor().instrument()

@app.route("/")
def hello():
Expand Down
1 change: 1 addition & 0 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sortfirst=
opentelemetry-sdk
opentelemetry-auto-instrumentation
ext/opentelemetry-ext-wsgi
ext/opentelemetry-ext-dbapi
ext/*

[lintroots]
Expand Down
107 changes: 57 additions & 50 deletions ext/opentelemetry-ext-docker-tests/tests/check_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mysql.connector
import psycopg2
import pymongo
import redis

MONGODB_COLLECTION_NAME = "test"
MONGODB_DB_NAME = os.getenv("MONGODB_DB_NAME", "opentelemetry-tests")
Expand All @@ -33,76 +34,82 @@
POSTGRES_PASSWORD = os.getenv("POSTGRESQL_HOST", "testpassword")
POSTGRES_PORT = int(os.getenv("POSTGRESQL_PORT", "5432"))
POSTGRES_USER = os.getenv("POSTGRESQL_HOST", "testuser")
REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
REDIS_PORT = int(os.getenv("REDIS_PORT ", "6379"))
RETRY_COUNT = 5
RETRY_INTERVAL = 5 # Seconds

logger = logging.getLogger(__name__)


def retryable(func):
def wrapper():
# Try to connect to DB
for i in range(RETRY_COUNT):
try:
func()
return
except Exception as ex: # pylint: disable=broad-except
logger.error(
"waiting for %s, retry %d/%d [%s]",
func.__name__,
i + 1,
RETRY_COUNT,
ex,
)
time.sleep(RETRY_INTERVAL)
raise Exception("waiting for {} failed".format(func.__name__))

return wrapper


@retryable
def check_pymongo_connection():
# Try to connect to DB
for i in range(RETRY_COUNT):
try:
client = pymongo.MongoClient(
MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000
)
db = client[MONGODB_DB_NAME]
collection = db[MONGODB_COLLECTION_NAME]
collection.find_one()
client.close()
break
except Exception as ex:
if i == RETRY_COUNT - 1:
raise (ex)
logger.exception(ex)
time.sleep(RETRY_INTERVAL)
client = pymongo.MongoClient(
MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000
)
db = client[MONGODB_DB_NAME]
collection = db[MONGODB_COLLECTION_NAME]
collection.find_one()
client.close()


@retryable
def check_mysql_connection():
# Try to connect to DB
for i in range(RETRY_COUNT):
try:
connection = mysql.connector.connect(
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT,
database=MYSQL_DB_NAME,
)
connection.close()
break
except Exception as ex:
if i == RETRY_COUNT - 1:
raise (ex)
logger.exception(ex)
time.sleep(RETRY_INTERVAL)
connection = mysql.connector.connect(
user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
port=MYSQL_PORT,
database=MYSQL_DB_NAME,
)
connection.close()


@retryable
def check_postgres_connection():
# Try to connect to DB
for i in range(RETRY_COUNT):
try:
connection = psycopg2.connect(
dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER,
password=POSTGRES_PASSWORD,
host=POSTGRES_HOST,
port=POSTGRES_PORT,
)
connection.close()
break
except Exception as ex:
if i == RETRY_COUNT - 1:
raise (ex)
logger.exception(ex)
time.sleep(RETRY_INTERVAL)
connection = psycopg2.connect(
dbname=POSTGRES_DB_NAME,
user=POSTGRES_USER,
password=POSTGRES_PASSWORD,
host=POSTGRES_HOST,
port=POSTGRES_PORT,
)
connection.close()


@retryable
def check_redis_connection():
connection = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
connection.hgetall("*")


def check_docker_services_availability():
# Check if Docker services accept connections
check_pymongo_connection()
check_mysql_connection()
check_postgres_connection()
check_redis_connection()


check_docker_services_availability()
4 changes: 4 additions & 0 deletions ext/opentelemetry-ext-docker-tests/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ services:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: opentelemetry-tests
otredis:
image: redis:4.0-alpine
ports:
- "127.0.0.1:6379:6379"

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pymongo import MongoClient

from opentelemetry import trace as trace_api
from opentelemetry.ext.pymongo import trace_integration
from opentelemetry.ext.pymongo import PymongoInstrumentor
from opentelemetry.test.test_base import TestBase

MONGODB_HOST = os.getenv("MONGODB_HOST ", "localhost")
Expand All @@ -31,7 +31,7 @@ class TestFunctionalPymongo(TestBase):
def setUpClass(cls):
super().setUpClass()
cls._tracer = cls.tracer_provider.get_tracer(__name__)
trace_integration(cls.tracer_provider)
PymongoInstrumentor().instrument()
client = MongoClient(
MONGODB_HOST, MONGODB_PORT, serverSelectionTimeoutMS=2000
)
Expand Down Expand Up @@ -94,3 +94,23 @@ def test_delete(self):
with self._tracer.start_as_current_span("rootSpan"):
self._collection.delete_one({"name": "testName"})
self.validate_spans()

def test_uninstrument(self):
# check that integration is working
self._collection.find_one()
spans = self.memory_exporter.get_finished_spans()
self.memory_exporter.clear()
self.assertEqual(len(spans), 1)

# uninstrument and check not new spans are created
PymongoInstrumentor().uninstrument()
self._collection.find_one()
spans = self.memory_exporter.get_finished_spans()
self.memory_exporter.clear()
self.assertEqual(len(spans), 0)

# re-enable and check that it works again
PymongoInstrumentor().instrument()
self._collection.find_one()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
Loading