1717from typing import List , Optional , Tuple , Any , Dict , Union
1818from contextlib import contextmanager
1919from dataclasses import dataclass , field
20+ import json
2021import enum
2122import time
2223import uuid
24+ import platform
2325
2426import dbt .exceptions
2527from dbt .adapters .base import Credentials
@@ -112,6 +114,9 @@ class OracleAdapterCredentials(Credentials):
112114 # Base URL for ADB-S OML REST API
113115 oml_cloud_service_url : Optional [str ] = None
114116
117+ # session info is stored in v$session for each dbt run
118+ session_info : Optional [Dict [str , str ]] = field (default_factory = dict )
119+
115120
116121 _ALIASES = {
117122 'dbname' : 'database' ,
@@ -136,7 +141,8 @@ def _connection_keys(self) -> Tuple[str]:
136141 'service' , 'connection_string' ,
137142 'shardingkey' , 'supershardingkey' ,
138143 'cclass' , 'purity' , 'retry_count' ,
139- 'retry_delay' , 'oml_cloud_service_url'
144+ 'retry_delay' , 'oml_cloud_service_url' ,
145+ 'session_info'
140146 )
141147
142148 @classmethod
@@ -174,6 +180,19 @@ def get_dsn(self) -> str:
174180class OracleAdapterConnectionManager (SQLConnectionManager ):
175181 TYPE = 'oracle'
176182
183+ @staticmethod
184+ def get_session_info (credentials ):
185+ default_action = "DBT RUN"
186+ default_client_identifier = f'dbt-oracle-client-{ uuid .uuid4 ()} '
187+ default_client_info = "_" .join ([platform .node (), platform .machine ()])
188+ default_module = f'dbt-{ dbt_version } '
189+ return {
190+ "action" : credentials .session_info .get ("action" , default_action ),
191+ "client_identifier" : credentials .session_info .get ("client_identifier" , default_client_identifier ),
192+ "clientinfo" : credentials .session_info .get ("client_info" , default_client_info ),
193+ "module" : credentials .session_info .get ("module" , default_module )
194+ }
195+
177196 @classmethod
178197 def open (cls , connection ):
179198 if connection .state == 'open' :
@@ -219,8 +238,14 @@ def open(cls, connection):
219238 try :
220239 handle = oracledb .connect (** conn_config )
221240 # client_identifier and module are saved in corresponding columns in v$session
222- handle .module = f'dbt-{ dbt_version } '
223- handle .client_identifier = f'dbt-oracle-client-{ uuid .uuid4 ()} '
241+ session_info = cls .get_session_info (credentials = credentials )
242+ logger .info (f"Session info :{ json .dumps (session_info )} " )
243+ for k , v in session_info .items ():
244+ try :
245+ setattr (handle , k , v )
246+ except AttributeError :
247+ logger .warning (f"Python driver does not support setting { k } " )
248+
224249 connection .handle = handle
225250 connection .state = 'open'
226251 except oracledb .DatabaseError as e :
0 commit comments