Skip to content

Commit 430851c

Browse files
committed
Add OpenTelemetry support
1 parent 7d65266 commit 430851c

23 files changed

+652
-14
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ node-oracledb `v6.7.0 <https://github.com/oracle/node-oracledb/compare/v6.6.0...
1313
Common Changes
1414
++++++++++++++
1515

16+
#) Added support to enable tracing with the OpenTelemetry
17+
module for Oracle Database being created in the OpenTelemetry project.
18+
1619
#) Added support to connect to Oracle Database using wallets stored in
1720
Azure Key Vault and OCI Vault.
1821

lib/connection.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,15 @@ class Connection extends EventEmitter {
869869
let binds = [];
870870
let options = {};
871871

872+
errors.assert(this._impl, errors.ERR_INVALID_CONNECTION);
873+
872874
// process arguments
873875
if (nodbUtil.isObject(sql) && typeof sql.statement === 'string') {
874876
errors.assertArgCount(arguments, 1, 2);
875877
if (sql.values) {
878+
if (this._impl._callLevelTraceData) {
879+
this._impl._callLevelTraceData.values = sql.values;
880+
}
876881
binds = await this._processExecuteBinds(sql.values);
877882
}
878883
sql = sql.statement;
@@ -883,18 +888,23 @@ class Connection extends EventEmitter {
883888
errors.assertArgCount(arguments, 1, 3);
884889
errors.assertParamValue(typeof sql === 'string', 1);
885890
if (arguments.length >= 2) {
891+
if (this._impl._callLevelTraceData) {
892+
this._impl._callLevelTraceData.values = a2;
893+
}
886894
binds = await this._processExecuteBinds(a2);
887895
}
888896
if (arguments.length == 3) {
889897
options = this._verifyExecOpts(a3, false);
890898
}
891899
}
892900
this._addDefaultsToExecOpts(options);
893-
errors.assert(this._impl, errors.ERR_INVALID_CONNECTION);
894901

895902
// perform actual execute
896903
let result;
897904
try {
905+
if (this._impl._callLevelTraceData) {
906+
this._impl._callLevelTraceData.statement = sql;
907+
}
898908
result = await this._impl.execute(sql, numIters, binds, options, false);
899909
} catch (err) {
900910
if (err.errorNum === 1406)
@@ -1035,6 +1045,63 @@ class Connection extends EventEmitter {
10351045
return this._impl && this._impl.getDbName();
10361046
}
10371047

1048+
//---------------------------------------------------------------------------
1049+
// hostName (READONLY)
1050+
//
1051+
// Property for identifying the hostName of the Oracle Database.
1052+
//---------------------------------------------------------------------------
1053+
get hostName() {
1054+
return this._impl && this._impl.getHostName();
1055+
}
1056+
1057+
//---------------------------------------------------------------------------
1058+
// port (READONLY)
1059+
//
1060+
// Property for identifying the port to which client is connected.
1061+
//---------------------------------------------------------------------------
1062+
get port() {
1063+
return this._impl && this._impl.getPort();
1064+
}
1065+
1066+
//---------------------------------------------------------------------------
1067+
// protocol (READONLY)
1068+
//
1069+
// Property for identifying the protocol used to connect to Oracle Database.
1070+
//---------------------------------------------------------------------------
1071+
get protocol() {
1072+
return this._impl && this._impl.getProtocol();
1073+
}
1074+
1075+
//---------------------------------------------------------------------------
1076+
// connectString (READONLY)
1077+
//
1078+
// User provided connectString to connect to Oracle Database.
1079+
//---------------------------------------------------------------------------
1080+
get connectString() {
1081+
return this._impl && this._impl._connectString;
1082+
}
1083+
1084+
//---------------------------------------------------------------------------
1085+
// user
1086+
//
1087+
// User property provided to connect to Oracle Database.
1088+
//---------------------------------------------------------------------------
1089+
get user() {
1090+
if (this.currentSchema.length) {
1091+
return this.currentSchema;
1092+
}
1093+
return this._impl && this._impl._user;
1094+
}
1095+
1096+
//---------------------------------------------------------------------------
1097+
// connectTraceConfig
1098+
//
1099+
// Property for getting the connection related config.
1100+
//---------------------------------------------------------------------------
1101+
get connectTraceConfig() {
1102+
return this._impl && this._impl._getConnectTraceConfig();
1103+
}
1104+
10381105
//---------------------------------------------------------------------------
10391106
// getDbObjectClass()
10401107
//

lib/impl/aqQueue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
'use strict';
2828

2929
const errors = require('../errors.js');
30+
const BaseImpl = require('./base.js');
3031

31-
class AqQueueImpl {
32+
class AqQueueImpl extends BaseImpl {
3233

3334
//---------------------------------------------------------------------------
3435
// _getConnImpl()

lib/impl/base.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2024, Oracle and/or its affiliates.
2+
3+
//-----------------------------------------------------------------------------
4+
//
5+
// This software is dual-licensed to you under the Universal Permissive License
6+
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7+
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8+
// either license.
9+
//
10+
// If you elect to accept the software under the Apache License, Version 2.0,
11+
// the following applies:
12+
//
13+
// Licensed under the Apache License, Version 2.0 (the "License");
14+
// you may not use this file except in compliance with the License.
15+
// You may obtain a copy of the License at
16+
//
17+
// https://www.apache.org/licenses/LICENSE-2.0
18+
//
19+
// Unless required by applicable law or agreed to in writing, software
20+
// distributed under the License is distributed on an "AS IS" BASIS,
21+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
// See the License for the specific language governing permissions and
23+
// limitations under the License.
24+
//
25+
//-----------------------------------------------------------------------------
26+
27+
'use strict';
28+
29+
class BaseImpl {
30+
31+
//---------------------------------------------------------------------------
32+
// _getConnectTraceConfig()
33+
//
34+
// Retrieves connect trace config from connection object.
35+
//---------------------------------------------------------------------------
36+
_getConnectTraceConfig() {
37+
const connImpl = this._getConnImpl();
38+
if (connImpl) {
39+
return connImpl._getConnectTraceConfig();
40+
}
41+
}
42+
43+
}
44+
45+
module.exports = BaseImpl;

lib/impl/connection.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ class ConnectionImpl {
6969
return this;
7070
}
7171

72+
//---------------------------------------------------------------------------
73+
// _getConnectTraceConfig()
74+
//
75+
// returns the necessary connection config used for debug/trace.
76+
// ---------------------------------------------------------------------------
77+
_getConnectTraceConfig() {
78+
let traceConfig;
79+
80+
if (this._pool) {
81+
traceConfig = this._pool._getConnectTraceConfig();
82+
} else {
83+
traceConfig = {connectString: this._connectString, user: this._user};
84+
}
85+
traceConfig.serviceName = this.getServiceName();
86+
traceConfig.instanceName = this.getInstanceName();
87+
traceConfig.pdbName = this.getDbName();
88+
89+
// Thick mode doesnt have these properties for now.
90+
if (settings.thin) {
91+
traceConfig.hostName = this.getHostName();
92+
traceConfig.port = this.getPort();
93+
traceConfig.protocol = this.getProtocol();
94+
}
95+
return traceConfig;
96+
}
97+
7298
//---------------------------------------------------------------------------
7399
// _getDbObjectType()
74100
//
@@ -589,6 +615,33 @@ class ConnectionImpl {
589615
errors.throwNotImplemented("unsubscribing from events");
590616
}
591617

618+
//---------------------------------------------------------------------------
619+
// getHostName()
620+
//
621+
// Returns the Oracle Database host name associated with the connection.
622+
//---------------------------------------------------------------------------
623+
getHostName() {
624+
errors.throwNotImplemented("getting HostName");
625+
}
626+
627+
//---------------------------------------------------------------------------
628+
// getPort()
629+
//
630+
// Returns the Oracle Database port number associated with the connection.
631+
//---------------------------------------------------------------------------
632+
getPort() {
633+
errors.throwNotImplemented("getting Port");
634+
}
635+
636+
//---------------------------------------------------------------------------
637+
// getProtocol()
638+
//
639+
// Returns the protocol associated with the connection.
640+
//---------------------------------------------------------------------------
641+
getProtocol() {
642+
errors.throwNotImplemented("getting Protocol");
643+
}
644+
592645
}
593646

594647
// export just the class

lib/impl/lob.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828

2929
const ConnectionImpl = require('./connection.js');
3030
const errors = require('../errors.js');
31+
const BaseImpl = require('./base.js');
3132

32-
class LobImpl {
33+
class LobImpl extends BaseImpl {
3334

3435
//---------------------------------------------------------------------------
3536
// _getConnImpl()

lib/impl/pool.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@ class PoolImpl {
174174
errors.throwNotImplemented("getting the pool statement cache size");
175175
}
176176

177+
//---------------------------------------------------------------------------
178+
// _getConnectTraceConfig()
179+
//
180+
// Returns the necessary connection config used by pool for debug/trace.
181+
//---------------------------------------------------------------------------
182+
_getConnectTraceConfig() {
183+
return {
184+
connectString: this._connectString,
185+
user: this._user,
186+
poolMin: this.getPoolMin(),
187+
poolMax: this.getPoolMax(),
188+
poolIncrement: this.getPoolIncrement()
189+
};
190+
}
191+
177192
//---------------------------------------------------------------------------
178193
// getSodaMetaDataCache()
179194
//

lib/impl/resultset.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ const future = require('../future.js');
3434
const types = require('../types.js');
3535
const Lob = require('../lob.js');
3636
const oson = require('./datahandlers/oson.js');
37+
const BaseImpl = require('./base.js');
3738

3839
// define implementation class
39-
class ResultSetImpl {
40+
class ResultSetImpl extends BaseImpl {
4041

4142
//---------------------------------------------------------------------------
4243
// _determineFetchType()

lib/impl/sodaCollection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
'use strict';
2828

2929
const errors = require('../errors.js');
30+
const BaseImpl = require('./base.js');
3031

31-
class SodaCollectionImpl {
32+
class SodaCollectionImpl extends BaseImpl {
3233

3334
//---------------------------------------------------------------------------
3435
// _getConnImpl()

lib/impl/sodaDatabase.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
'use strict';
2828

2929
const errors = require('../errors.js');
30+
const BaseImpl = require('./base.js');
3031

31-
class SodaDatabaseImpl {
32+
class SodaDatabaseImpl extends BaseImpl {
3233

3334
//---------------------------------------------------------------------------
3435
// _getConnImpl()

0 commit comments

Comments
 (0)