Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 7a70149

Browse files
authored
Merge pull request #41 from helgi/patch-2
Support referencing env vars in the postgresql configuration
2 parents 884aad3 + 17cd284 commit 7a70149

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

newrelic_python_agent/plugins/postgresql.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import psycopg2
77
from psycopg2 import extensions
88
from psycopg2 import extras
9+
import os
910

1011
from newrelic_python_agent.plugins import base
1112

@@ -277,10 +278,16 @@ def connection_arguments(self):
277278
filtered_args = ["name", "superuser", "relation_stats"]
278279
args = {}
279280
for key in set(self.config) - set(filtered_args):
281+
value = self.config[key]
282+
# If value starts with $ and exists as an env var, use that value
283+
if value[0] == "$":
284+
# strip the $, check if the env var exists, otherwise fallback
285+
value = os.getenv(value, value)
286+
280287
if key == 'dbname':
281-
args['database'] = self.config[key]
288+
args['database'] = value
282289
else:
283-
args[key] = self.config[key]
290+
args[key] = value
284291
return args
285292

286293
def poll(self):

0 commit comments

Comments
 (0)