-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extending SQLCommenter support of dbapi into psycopg2 (#940)
* Added configuration for sqlcommenter * Fixed linting errors * Updated CHANGELOG.md * Unit test case for sqlcommenter in psycopg2 * Merge conflict resolved * Update CHANGELOG.md * psycopg2 sqlcommenter integration test * linting changes * linting changes * linting changes * linting changes * linting changes * version compatability issue fix Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> Co-authored-by: Leighton Chen <lechen@microsoft.com>
- Loading branch information
1 parent
2f74c90
commit e861b93
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_sqlcommenter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2020, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import psycopg2 | ||
from test_psycopg_functional import ( | ||
POSTGRES_DB_NAME, | ||
POSTGRES_HOST, | ||
POSTGRES_PASSWORD, | ||
POSTGRES_PORT, | ||
POSTGRES_USER, | ||
) | ||
|
||
from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor | ||
from opentelemetry.test.test_base import TestBase | ||
|
||
|
||
class TestFunctionalPsycopg(TestBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls._connection = None | ||
cls._cursor = None | ||
cls._tracer = cls.tracer_provider.get_tracer(__name__) | ||
Psycopg2Instrumentor().instrument(enable_commenter=True) | ||
cls._connection = psycopg2.connect( | ||
dbname=POSTGRES_DB_NAME, | ||
user=POSTGRES_USER, | ||
password=POSTGRES_PASSWORD, | ||
host=POSTGRES_HOST, | ||
port=POSTGRES_PORT, | ||
) | ||
cls._connection.set_session(autocommit=True) | ||
cls._cursor = cls._connection.cursor() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
if cls._cursor: | ||
cls._cursor.close() | ||
if cls._connection: | ||
cls._connection.close() | ||
Psycopg2Instrumentor().uninstrument() | ||
|
||
def test_commenter_enabled(self): | ||
self._cursor.execute("SELECT 1;") | ||
self.assertRegex( | ||
self._cursor.query.decode("ascii"), | ||
r"SELECT 1; /\*traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/", | ||
) |