Skip to content

Commit 63d8e56

Browse files
P403n1x87mabdinurmajorgreys
authored
fix: use psycopg2 DSN parser to parse DSN (#5272)
This change fixes an issue with DSN parsing with the psycopg2 integration, likely introduced after the refactor of #4294. Fixes #5269. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [ ] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [ ] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [ ] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment. --------- Co-authored-by: Munir Abdinur <[email protected]> Co-authored-by: Tahir H. Butt <[email protected]> Co-authored-by: Tahir H. Butt <[email protected]>
1 parent bdb1805 commit 63d8e56

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

ddtrace/contrib/psycopg/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from psycopg2.extensions import connection
77
from psycopg2.extensions import cursor
8+
from psycopg2.extensions import parse_dsn
89

910
from ddtrace import config
1011
from ddtrace.internal.constants import COMPONENT
@@ -15,7 +16,6 @@
1516
from ...ext import SpanTypes
1617
from ...ext import db
1718
from ...ext import net
18-
from ...ext import sql
1919

2020

2121
class TracedCursor(cursor):
@@ -66,7 +66,7 @@ def __init__(self, *args, **kwargs):
6666
super(TracedConnection, self).__init__(*args, **kwargs)
6767

6868
# add metadata (from the connection, string, etc)
69-
dsn = sql.parse_pg_dsn(self.dsn)
69+
dsn = parse_dsn(self.dsn)
7070
self._datadog_tags = {
7171
net.TARGET_HOST: dsn.get("host"),
7272
net.TARGET_PORT: dsn.get("port"),

ddtrace/contrib/psycopg/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
import psycopg2
4+
from psycopg2.extensions import parse_dsn
45
from psycopg2.sql import Composable
56

67
from ddtrace import Pin
@@ -13,7 +14,6 @@
1314
from ddtrace.ext import SpanTypes
1415
from ddtrace.ext import db
1516
from ddtrace.ext import net
16-
from ddtrace.ext import sql
1717
from ddtrace.internal.constants import COMPONENT
1818
from ddtrace.vendor import wrapt
1919

@@ -108,7 +108,7 @@ def patch_conn(conn, traced_conn_cls=Psycopg2TracedConnection):
108108
c = traced_conn_cls(conn)
109109

110110
# fetch tags from the dsn
111-
dsn = sql.parse_pg_dsn(conn.dsn)
111+
dsn = parse_dsn(conn.dsn)
112112
tags = {
113113
net.TARGET_HOST: dsn.get("host"),
114114
net.TARGET_PORT: dsn.get("port"),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
psycopg2: Fixes a bug with DSN parsing integration.

0 commit comments

Comments
 (0)