Skip to content

Commit 00e0787

Browse files
committed
chore(instrumentation-kafkajs): enable test coverage reporting
1 parent 45047b4 commit 00e0787

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

plugins/node/instrumentation-kafkajs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "build/src/index.d.ts",
77
"repository": "open-telemetry/opentelemetry-js-contrib",
88
"scripts": {
9-
"test": "mocha --require @opentelemetry/contrib-test-utils 'test/**/*.test.ts'",
9+
"test": "nyc mocha --require @opentelemetry/contrib-test-utils 'test/**/*.test.ts'",
1010
"tdd": "npm run test -- --watch-extensions ts --watch",
1111
"clean": "rimraf build/*",
1212
"lint": "eslint . --ext .ts",

plugins/node/instrumentation-kafkajs/src/instrumentation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ interface ConsumerSpanOptions {
8484
topic: string;
8585
message: KafkaMessage | undefined;
8686
operationType: string;
87-
attributes?: Attributes;
87+
attributes: Attributes;
8888
ctx?: Context | undefined;
8989
link?: Link;
9090
}
@@ -583,9 +583,9 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
583583
return result;
584584
})
585585
.catch(reason => {
586-
let errorMessage: string;
587-
let errorType = ERROR_TYPE_VALUE_OTHER;
588-
if (typeof reason === 'string') {
586+
let errorMessage: string | undefined;
587+
let errorType: string = ERROR_TYPE_VALUE_OTHER;
588+
if (typeof reason === 'string' || reason === undefined) {
589589
errorMessage = reason;
590590
} else if (
591591
typeof reason === 'object' &&
@@ -597,7 +597,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
597597
pendingMetrics.forEach(m => m(errorType));
598598

599599
spans.forEach(span => {
600-
if (errorType) span.setAttribute(ATTR_ERROR_TYPE, errorType);
600+
span.setAttribute(ATTR_ERROR_TYPE, errorType);
601601
span.setStatus({
602602
code: SpanStatusCode.ERROR,
603603
message: errorMessage,
@@ -617,7 +617,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
617617
operationType,
618618
ctx,
619619
link,
620-
attributes = {},
620+
attributes,
621621
}: ConsumerSpanOptions) {
622622
const operationName =
623623
operationType === MESSAGING_OPERATION_TYPE_VALUE_RECEIVE
@@ -641,7 +641,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
641641
? String(message.key)
642642
: undefined,
643643
[ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]:
644-
message?.key && message?.value === null ? true : undefined,
644+
message?.key && message.value === null ? true : undefined,
645645
[ATTR_MESSAGING_KAFKA_OFFSET]: message?.offset,
646646
},
647647
links: link ? [link] : [],

0 commit comments

Comments
 (0)