Skip to content

Commit 791bc20

Browse files
committed
Add connection.clientInfo and connection.dbOp
1 parent f8d482c commit 791bc20

File tree

6 files changed

+320
-34
lines changed

6 files changed

+320
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
**This release is under development**
66

7+
- Added end-to-end tracing attributes
8+
[`connection.clientInfo`](https://oracle.github.io/node-oracledb/doc/api.html#propconnclientinfo)
9+
and [`connection.dbOp`](https://oracle.github.io/node-oracledb/doc/api.html#propconndbop).
10+
711
- Fixed a [regression](https://github.com/oracle/node-oracledb/issues/1152) when
812
binding dates with alternative JavaScript frameworks.
913

doc/api.md

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,14 @@ For installation information, see the [Node-oracledb Installation Instructions][
138138
- 4.1.1 [`action`](#propconnaction)
139139
- 4.1.2 [`callTimeout`](#propconncalltimeout)
140140
- 4.1.3 [`clientId`](#propconnclientid)
141-
- 4.1.4 [`currentSchema`](#propconncurrentschema)
142-
- 4.1.5 [`module`](#propconnmodule)
143-
- 4.1.6 [`oracleServerVersion`](#propconnoracleserverversion)
144-
- 4.1.7 [`oracleServerVersionString`](#propconnoracleserverversionstring)
145-
- 4.1.8 [`stmtCacheSize`](#propconnstmtcachesize)
146-
- 4.1.9 [`tag`](#propconntag)
141+
- 4.1.4 [`clientInfo`](#propconnclientinfo)
142+
- 4.1.5 [`currentSchema`](#propconncurrentschema)
143+
- 4.1.6 [`dbOp`](#propconndbop)
144+
- 4.1.7 [`module`](#propconnmodule)
145+
- 4.1.8 [`oracleServerVersion`](#propconnoracleserverversion)
146+
- 4.1.9 [`oracleServerVersionString`](#propconnoracleserverversionstring)
147+
- 4.1.10 [`stmtCacheSize`](#propconnstmtcachesize)
148+
- 4.1.11 [`tag`](#propconntag)
147149
- 4.2 [Connection Methods](#connectionmethods)
148150
- 4.2.1 [`break()`](#break)
149151
- 4.2.2 [`changePassword()`](#changepassword)
@@ -2442,11 +2444,25 @@ The [client identifier][10] for end-to-end application tracing, use
24422444
with mid-tier authentication, and with [Virtual Private
24432445
Databases][11].
24442446

2445-
This is a write-only property. Displaying a Connection object will
2446-
show a value of `null` for this attribute. See
2447-
[End-to-end Tracing, Mid-tier Authentication, and Auditing](#endtoend).
2447+
This is a write-only property. Displaying `Connection.clientId` will show a
2448+
value of `null`. See [End-to-end Tracing, Mid-tier Authentication, and
2449+
Auditing](#endtoend).
2450+
2451+
#### <a name="propconnclientinfo"></a> 4.1.4 `connection.clientInfo`
2452+
2453+
```
2454+
writeonly String clientInfo
2455+
```
2456+
2457+
The client information for end-to-end application tracing.
2458+
2459+
This is a write-only property. Displaying `Connection.clientInfo` will show a
2460+
value of `null`. See [End-to-end Tracing, Mid-tier Authentication, and
2461+
Auditing](#endtoend).
24482462

2449-
#### <a name="propconncurrentschema"></a> 4.1.4 `connection.currentSchema`
2463+
This property was added in node-oracledb 4.1.
2464+
2465+
#### <a name="propconncurrentschema"></a> 4.1.5 `connection.currentSchema`
24502466

24512467
```
24522468
String currentSchema
@@ -2468,19 +2484,33 @@ CURRENT_SCHEMA`][137].
24682484

24692485
This property was added in node-oracledb 4.0.
24702486

2471-
#### <a name="propconnmodule"></a> 4.1.5 `connection.module`
2487+
#### <a name="propconndbop"></a> 4.1.6 `connection.dbOp`
2488+
2489+
```
2490+
writeonly String dbOp
2491+
```
2492+
2493+
The database operation information for end-to-end application tracing.
2494+
2495+
This is a write-only property. Displaying `Connection.dbOp` will show a value
2496+
of `null`. See [End-to-end Tracing, Mid-tier Authentication, and
2497+
Auditing](#endtoend).
2498+
2499+
This property was added in node-oracledb 4.1. It is available with Oracle 12c.
2500+
2501+
#### <a name="propconnmodule"></a> 4.1.7 `connection.module`
24722502

24732503
```
24742504
writeonly String module
24752505
```
24762506

24772507
The [module][9] attribute for end-to-end application tracing.
24782508

2479-
This is a write-only property. Displaying a Connection object will
2480-
show a value of `null` for this attribute. See
2481-
[End-to-end Tracing, Mid-tier Authentication, and Auditing](#endtoend).
2509+
This is a write-only property. Displaying `Connection.module` will show a value
2510+
of `null`. See [End-to-end Tracing, Mid-tier Authentication, and
2511+
Auditing](#endtoend).
24822512

2483-
#### <a name="propconnoracleserverversion"></a> 4.1.6 `connection.oracleServerVersion`
2513+
#### <a name="propconnoracleserverversion"></a> 4.1.8 `connection.oracleServerVersion`
24842514

24852515
```
24862516
readonly Number oracleServerVersion
@@ -2496,7 +2526,7 @@ instead of 1803000000.
24962526

24972527
This property was added in node-oracledb 1.3.
24982528

2499-
#### <a name="propconnoracleserverversionstring"></a> 4.1.7 `connection.oracleServerVersionString`
2529+
#### <a name="propconnoracleserverversionstring"></a> 4.1.9 `connection.oracleServerVersionString`
25002530

25012531
```
25022532
readonly String oracleServerVersionString
@@ -2511,7 +2541,7 @@ release such as "18.0.0.0.0" instead of "18.3.0.0.0".
25112541

25122542
This property was added in node-oracledb 2.2.
25132543

2514-
#### <a name="propconnstmtcachesize"></a> 4.1.8 `connection.stmtCacheSize`
2544+
#### <a name="propconnstmtcachesize"></a> 4.1.10 `connection.stmtCacheSize`
25152545

25162546
```
25172547
readonly Number stmtCacheSize
@@ -2522,7 +2552,7 @@ The number of statements to be cached in the
25222552
the `stmtCacheSize` property in effect in the *Pool* object when the
25232553
connection is created in the pool.
25242554

2525-
#### <a name="propconntag"></a> 4.1.9 `connection.tag`
2555+
#### <a name="propconntag"></a> 4.1.11 `connection.tag`
25262556

25272557
```
25282558
String tag
@@ -12690,10 +12720,10 @@ In node-oracledb this will always show AL32UTF8.
1269012720

1269112721
## <a name="endtoend"></a> 28. End-to-end Tracing, Mid-tier Authentication, and Auditing
1269212722

12693-
The Connection properties [action](#propconnaction),
12694-
[module](#propconnmodule), and [clientId](#propconnclientid) set
12695-
metadata for [end-to-end tracing][70]. The values can be tracked in
12696-
database views, shown in audit trails, and seen in tools such as
12723+
The Connection properties [action](#propconnaction), [module](#propconnmodule),
12724+
[clientId](#propconnclientid), [clientInfo](#propconnclientinfo) and
12725+
[dbOp](#propconndbop) set metadata for [end-to-end tracing][70]. The values can
12726+
be tracked in database views, shown in audit trails, and seen in tools such as
1269712727
Enterprise Manager.
1269812728

1269912729
The `clientId` property can also be used by applications that do their
@@ -12722,28 +12752,38 @@ const connection = await oracledb.getConnection(
1272212752
);
1272312753

1272412754
connection.clientId = "Chris";
12755+
connection.clientInfo = "My demo application";
1272512756
connection.module = "End-to-end example";
1272612757
connection.action = "Query departments";
12758+
connection.dbOp = "Billing"
1272712759

1272812760
const result = await connection.execute(`SELECT . . .`);
1272912761
```
1273012762

1273112763
While the connection is open the attribute values can be seen, for example with SQL*Plus:
1273212764

1273312765
```
12734-
SQL> SELECT username, client_identifier, action, module FROM v$session WHERE username = 'HR';
12766+
SQL> SELECT username, client_identifier, client_info, action, module FROM v$session WHERE username = 'HR';
12767+
12768+
USERNAME CLIENT_IDENTIFIER CLIENT_INFO ACTION MODULE
12769+
---------- -------------------- ---------------------- -------------------- --------------------
12770+
HR Chris My demo application Query departments End-to-end example
1273512771

12736-
USERNAME CLIENT_IDENTIFIER ACTION MODULE
12737-
---------- -------------------- -------------------- --------------------
12738-
HR Chris Query departments End-to-end example
12772+
SQL> SELECT dbop_name FROM v$sql_monitor;
12773+
DBOP_NAME
12774+
------------------------------
12775+
Billing
12776+
. . .
1273912777
```
1274012778

12741-
The values can also be manually set by calling
12742-
[`DBMS_APPLICATION_INFO`][71] procedures or
12743-
[`DBMS_SESSION.SET_IDENTIFIER`][72], however these cause explicit
12744-
[round-trips](#roundtrips), reducing scalability.
12779+
Other ways to access metadata include querying `V$SQLAREA` and `sys_context()`,
12780+
for example `SELECT SYS_CONTEXT('userenv', 'client_info') FROM dual`.
12781+
12782+
Metadata values can also be manually set by calling
12783+
[`DBMS_APPLICATION_INFO`][71] procedures or [`DBMS_SESSION.SET_IDENTIFIER`][72],
12784+
however these cause explicit [round-trips](#roundtrips), reducing scalability.
1274512785

12746-
In general, applications should be consistent about how, and when,
12786+
Applications should be consistent about how, and when,
1274712787
they set the end-to-end tracing attributes so that current values are
1274812788
recorded by the database.
1274912789

@@ -12786,8 +12826,8 @@ SQL> SELECT UNIQUE sid, client_driver
1278612826

1278712827
SID CLIENT_DRIVER
1278812828
---------- ------------------------------
12789-
16 node-oracledb : 2.2.0
12790-
33 node-oracledb : 2.2.0
12829+
16 node-oracledb : 4.1.0
12830+
33 node-oracledb : 4.1.0
1279112831
```
1279212832

1279312833
Note if [`oracledb.connectionClass`](#propdbconclass) is set for a

src/njsConnection.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ static NJS_PROCESS_ARGS_METHOD(njsConnection_subscribeProcessArgs);
8181
static NJS_NAPI_GETTER(njsConnection_getAction);
8282
static NJS_NAPI_GETTER(njsConnection_getCallTimeout);
8383
static NJS_NAPI_GETTER(njsConnection_getClientId);
84+
static NJS_NAPI_GETTER(njsConnection_getClientInfo);
8485
static NJS_NAPI_GETTER(njsConnection_getCurrentSchema);
86+
static NJS_NAPI_GETTER(njsConnection_getDbOp);
8587
static NJS_NAPI_GETTER(njsConnection_getModule);
8688
static NJS_NAPI_GETTER(njsConnection_getOracleServerVersion);
8789
static NJS_NAPI_GETTER(njsConnection_getOracleServerVersionString);
@@ -92,7 +94,9 @@ static NJS_NAPI_GETTER(njsConnection_getTag);
9294
static NJS_NAPI_SETTER(njsConnection_setAction);
9395
static NJS_NAPI_SETTER(njsConnection_setCallTimeout);
9496
static NJS_NAPI_SETTER(njsConnection_setClientId);
97+
static NJS_NAPI_SETTER(njsConnection_setClientInfo);
9598
static NJS_NAPI_SETTER(njsConnection_setCurrentSchema);
99+
static NJS_NAPI_SETTER(njsConnection_setDbOp);
96100
static NJS_NAPI_SETTER(njsConnection_setModule);
97101
static NJS_NAPI_SETTER(njsConnection_setTag);
98102

@@ -137,8 +141,12 @@ static const napi_property_descriptor njsClassProperties[] = {
137141
njsConnection_setCallTimeout, NULL, napi_default, NULL },
138142
{ "clientId", NULL, NULL, njsConnection_getClientId,
139143
njsConnection_setClientId, NULL, napi_default, NULL },
144+
{ "clientInfo", NULL, NULL, njsConnection_getClientInfo,
145+
njsConnection_setClientInfo, NULL, napi_default, NULL },
140146
{ "currentSchema", NULL, NULL, njsConnection_getCurrentSchema,
141147
njsConnection_setCurrentSchema, NULL, napi_default, NULL },
148+
{ "dbOp", NULL, NULL, njsConnection_getDbOp, njsConnection_setDbOp, NULL,
149+
napi_default, NULL },
142150
{ "module", NULL, NULL, njsConnection_getModule, njsConnection_setModule,
143151
NULL, napi_default, NULL },
144152
{ "oracleServerVersion", NULL, NULL, njsConnection_getOracleServerVersion,
@@ -1171,6 +1179,17 @@ static napi_value njsConnection_getClientId(napi_env env,
11711179
}
11721180

11731181

1182+
//-----------------------------------------------------------------------------
1183+
// njsConnection_getClientInfo()
1184+
// Get accessor of "clientInfo" property.
1185+
//-----------------------------------------------------------------------------
1186+
static napi_value njsConnection_getClientInfo(napi_env env,
1187+
napi_callback_info info)
1188+
{
1189+
return njsUtils_getNull(env);
1190+
}
1191+
1192+
11741193
//-----------------------------------------------------------------------------
11751194
// njsConnection_getCurrentSchema()
11761195
// Get accessor of "currentSchema" property.
@@ -1270,6 +1289,17 @@ static bool njsConnection_getDbObjectClassProcessArgs(njsBaton *baton,
12701289
}
12711290

12721291

1292+
//-----------------------------------------------------------------------------
1293+
// njsConnection_getDbOp()
1294+
// Get accessor of "dbOp" property.
1295+
//-----------------------------------------------------------------------------
1296+
static napi_value njsConnection_getDbOp(napi_env env,
1297+
napi_callback_info info)
1298+
{
1299+
return njsUtils_getNull(env);
1300+
}
1301+
1302+
12731303
//-----------------------------------------------------------------------------
12741304
// njsConnection_getExecuteManyOutBinds()
12751305
// Get the out binds as an array of objects/arrays.
@@ -2571,6 +2601,18 @@ static napi_value njsConnection_setClientId(napi_env env,
25712601
}
25722602

25732603

2604+
//-----------------------------------------------------------------------------
2605+
// njsConnection_setClientInfo()
2606+
// Set accessor of "clientInfo" property.
2607+
//-----------------------------------------------------------------------------
2608+
static napi_value njsConnection_setClientInfo(napi_env env,
2609+
napi_callback_info info)
2610+
{
2611+
return njsConnection_setTextAttribute(env, info, "clientInfo",
2612+
dpiConn_setClientInfo);
2613+
}
2614+
2615+
25742616
//-----------------------------------------------------------------------------
25752617
// njsConnection_setCurrentSchema()
25762618
// Set accessor of "clientId" property.
@@ -2583,6 +2625,17 @@ static napi_value njsConnection_setCurrentSchema(napi_env env,
25832625
}
25842626

25852627

2628+
//-----------------------------------------------------------------------------
2629+
// njsConnection_setDbOp()
2630+
// Set accessor of "dbOp" property.
2631+
//-----------------------------------------------------------------------------
2632+
static napi_value njsConnection_setDbOp(napi_env env,
2633+
napi_callback_info info)
2634+
{
2635+
return njsConnection_setTextAttribute(env, info, "dbOp", dpiConn_setDbOp);
2636+
}
2637+
2638+
25862639
//-----------------------------------------------------------------------------
25872640
// njsConnection_setModule()
25882641
// Set accessor of "module" property.

0 commit comments

Comments
 (0)