Skip to content

Commit bf73ff5

Browse files
committed
- Incorporate review comments
1 parent 0290b81 commit bf73ff5

File tree

8 files changed

+151
-170
lines changed

8 files changed

+151
-170
lines changed

plugins/node/opentelemetry-instrumentation-oracledb/.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
},
1313
rules: {
1414
"header/header": ["error", "block", [{
15-
pattern: /\* Copyright The OpenTelemetry Authors(?:, [^,\r\n]*)?[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the "License"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* {6}https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an "AS IS" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\.[\r\n]+ \*[\r\n]+ \* Copyright \(c\) 2024, Oracle and\/or its affiliates\.[\r\n]+ \*/gm,
15+
pattern: /\* Copyright The OpenTelemetry Authors(?:, [^,\r\n]*)?[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the "License"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* {6}https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an "AS IS" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\.[\r\n]+ \*[\r\n]+ \* Copyright \(c\) 2025, Oracle and\/or its affiliates\.[\r\n]+ \*/gm,
1616
template: `
1717
* Copyright The OpenTelemetry Authors
1818
*
@@ -28,7 +28,7 @@ module.exports = {
2828
* See the License for the specific language governing permissions and
2929
* limitations under the License.
3030
*
31-
* Copyright (c) 2024, Oracle and/or its affiliates.
31+
* Copyright (c) 2025, Oracle and/or its affiliates.
3232
* `
3333
}]]
3434
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
oracledb:
22
# a sample from supported versions
3-
- versions: "6.7.0"
3+
- versions: ">=6.7.0 <7"
44
commands: npm run test

plugins/node/opentelemetry-instrumentation-oracledb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-oracledb
1717

1818
## Supported Versions
1919

20-
- [`oracledb`](https://www.npmjs.com/package/oracledb) versions `>=6.7.0`
20+
- [`oracledb`](https://www.npmjs.com/package/oracledb) versions `>=6.7.0 <7`
2121

2222
## Usage
2323

plugins/node/opentelemetry-instrumentation-oracledb/src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*
16-
* Copyright (c) 2024, Oracle and/or its affiliates.
16+
* Copyright (c) 2025, Oracle and/or its affiliates.
1717
* */
1818

1919
// Oracle specific attributes not covered by semantic conventions
@@ -31,6 +31,8 @@ export enum AttributeNames {
3131
// Contains span names produced by instrumentation
3232
// It lists the RPC names (suffix with _MSG like EXECUTE_MSG) and
3333
// exported oracledb functions (like EXECUTE).
34+
// These constants need to be in sync with what is generated by the
35+
// 'oracledb' module.
3436
export enum SpanNames {
3537
CONNECT = 'oracledb.getConnection',
3638
POOL_CONNECT = 'oracledb.Pool.getConnection',

plugins/node/opentelemetry-instrumentation-oracledb/src/instrumentation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ export class OracleInstrumentation extends InstrumentationBase {
3434
protected init() {
3535
const moduleOracleDB = new InstrumentationNodeModuleDefinition(
3636
'oracledb',
37-
['>= 6.7 < 9.*'],
37+
['>= 6.7 < 7'],
3838
(moduleExports: typeof oracleDBTypes) => {
3939
const newmoduleExports: any = moduleExports;
4040
const config = this.getConfig();
41-
const obj = new utils.OracleTelemetryTraceHandler(this.tracer, config);
41+
const obj = new utils.OracleTelemetryTraceHandler(
42+
() => this.tracer,
43+
config
44+
);
4245
obj.enable();
4346

4447
// Register the instance with oracledb.

plugins/node/opentelemetry-instrumentation-oracledb/src/internal-types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export interface InstrumentationContext {
2626
span: api.Span;
2727
}
2828

29-
// Captures the entire span data
29+
// Captures the entire span data.
30+
// This corresponds to js object filled by the 'oracledb' module
31+
// See: https://github.com/oracle/node-oracledb/blob/main/lib/traceHandler.js
3032
export interface TraceSpanData {
3133
operation: string; // RPC or exported function name.
3234
error?: oracledbTypes.DBError;
@@ -35,6 +37,12 @@ export interface TraceSpanData {
3537
additionalConfig?: any; // custom key/values associated with a function.
3638
fn: Function; // Replaced with bind function associating the active context.
3739
args?: any[]; // input arguments passed to the exported function.
40+
41+
/**
42+
* This value is filled by instrumented module inside 'onEnterFn',
43+
* 'onBeginRoundTrip' hook functions, which is passed back by oracledb module
44+
* in 'onExitFn' and 'onEndRoundTrip' hook functions respectively.
45+
*/
3846
userContext: InstrumentationContext;
3947
}
4048

plugins/node/opentelemetry-instrumentation-oracledb/src/utils.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ const newmoduleExports: any = oracledbTypes;
5757
*/
5858
export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
5959
.TraceHandlerBase {
60-
private _tracer: Tracer;
60+
private _getTracer: () => Tracer;
6161
private _instrumentConfig: OracleInstrumentationConfig;
6262

63-
constructor(tracer: Tracer, config: OracleInstrumentationConfig) {
63+
constructor(getTracer: () => Tracer, config: OracleInstrumentationConfig) {
6464
super();
65-
this._tracer = tracer;
65+
this._getTracer = getTracer;
6666
this._instrumentConfig = config;
6767
}
6868

@@ -190,6 +190,16 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
190190
}
191191
}
192192

193+
// Updates the spanName with suffix, serviceName seperated by delimiter, space
194+
// Ex: 'oracledb.Pool.getConnection freepdb'
195+
// This function is called when connectLevelConfig has serviceName populated.
196+
private _updateSpanName(traceContext: TraceSpanData) {
197+
const dbName = traceContext.connectLevelConfig?.serviceName ?? '';
198+
traceContext.userContext.span.updateName(
199+
`${traceContext.operation}${dbName ? ` ${dbName}` : ''}`
200+
);
201+
}
202+
193203
// Updates the span with final traceContext atributes
194204
// which are updated after the exported function call.
195205
// roundTrip flag will skip dumping bind values for
@@ -220,9 +230,10 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
220230
);
221231
}
222232
if (traceContext.error) {
233+
span.recordException(traceContext.error);
223234
span.setStatus({
224235
code: SpanStatusCode.ERROR,
225-
message: traceContext.error?.message,
236+
message: traceContext.error.message,
226237
});
227238
}
228239
}
@@ -244,7 +255,7 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
244255
: {};
245256

246257
traceContext.userContext = {
247-
span: this._tracer.startSpan(spanName, {
258+
span: this._getTracer().startSpan(spanName, {
248259
kind: SpanKind.CLIENT,
249260
attributes: spanAttributes,
250261
}),
@@ -269,11 +280,7 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
269280
// This method is invoked after exported function from oracledb module
270281
// completes.
271282
onExitFn(traceContext: TraceSpanData) {
272-
if (
273-
this._shouldSkipInstrumentation() ||
274-
!traceContext.userContext ||
275-
!traceContext.userContext.span
276-
) {
283+
if (!traceContext.userContext?.span) {
277284
return;
278285
}
279286
this._updateFinalSpanAttributes(traceContext);
@@ -287,6 +294,7 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
287294
default:
288295
break;
289296
}
297+
this._updateSpanName(traceContext);
290298
traceContext.userContext.span.end();
291299
}
292300

@@ -299,7 +307,7 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
299307
const spanName = traceContext.operation;
300308
const spanAttrs = {};
301309
traceContext.userContext = {
302-
span: this._tracer.startSpan(spanName, {
310+
span: this._getTracer().startSpan(spanName, {
303311
kind: SpanKind.CLIENT,
304312
attributes: spanAttrs,
305313
}),
@@ -309,17 +317,14 @@ export class OracleTelemetryTraceHandler extends newmoduleExports.traceHandler
309317
// This method is invoked after a round trip call to DB is done
310318
// from the oracledb module as part of sql execution.
311319
onEndRoundTrip(traceContext: TraceSpanData) {
312-
if (
313-
this._shouldSkipInstrumentation() ||
314-
!traceContext.userContext ||
315-
!traceContext.userContext.span
316-
) {
320+
if (!traceContext.userContext?.span) {
317321
return;
318322
}
319323

320324
// Set if addtional connection and call parameters
321325
// are available
322326
this._updateFinalSpanAttributes(traceContext, true);
327+
this._updateSpanName(traceContext);
323328
traceContext.userContext.span.end();
324329
}
325330
}

0 commit comments

Comments
 (0)