Skip to content

Commit 28ac759

Browse files
authored
user agent and logging for neo4j (#344)
* user agent and logging for neo4j * remove changes
1 parent a1c3365 commit 28ac759

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

backend/example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ NUMBER_OF_CHUNKS_TO_COMBINE = ""
1919
GEMINI_ENABLED = True|False
2020
# Enable Google Cloud logs (default is True)
2121
GCP_LOG_METRICS_ENABLED = True|False
22+
NEO4J_USER_AGENT = ""

backend/src/graph_query.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import logging
22
from neo4j import time
33
from neo4j import GraphDatabase
4+
import os
5+
from neo4j.debug import watch
6+
7+
watch("neo4j")
48

59
QUERY_MAP = {
610
"document" : " + [docs] ",
@@ -50,7 +54,7 @@ def get_graphDB_driver(uri, username, password):
5054
"""
5155
try:
5256
logging.info(f"Attempting to connect to the Neo4j database at {uri}")
53-
driver = GraphDatabase.driver(uri, auth=(username, password))
57+
driver = GraphDatabase.driver(uri, auth=(username, password), user_agent=os.environ.get('NEO4J_USER_AGENT'))
5458
logging.info("Connection successful")
5559
return driver
5660
except Exception as e:

backend/src/shared/common_fn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import re
1111
import os
1212
from pathlib import Path
13+
from neo4j.debug import watch
14+
15+
watch("neo4j")
1316

1417
def check_url_source(source_type, yt_url:str=None, queries_list:List[str]=None):
1518
try:
@@ -59,7 +62,7 @@ def get_chunk_and_graphDocument(graph_document_list, chunkId_chunkDoc_list):
5962
return lst_chunk_chunkId_document
6063

6164
def create_graph_database_connection(uri, userName, password, database):
62-
graph = Neo4jGraph(url=uri, database=database, username=userName, password=password)
65+
graph = Neo4jGraph(url=uri, database=database, username=userName, password=password, driver_config={'user_agent':os.environ.get('NEO4J_USER_AGENT')})
6366
return graph
6467

6568

0 commit comments

Comments
 (0)