Skip to content

Commit 74ac115

Browse files
committed
refactor(instrumentation-kafkajs): remove bind and rename patch methods for transaction methods
1 parent be4db11 commit 74ac115

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

packages/instrumentation-kafkajs/src/instrumentation.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
289289
instrumentation._wrap(
290290
newProducer,
291291
'sendBatch',
292-
instrumentation._getProducerSendBatchPatch()
292+
instrumentation._getSendBatchPatch()
293293
);
294294

295295
if (isWrapped(newProducer.send)) {
@@ -298,7 +298,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
298298
instrumentation._wrap(
299299
newProducer,
300300
'send',
301-
instrumentation._getProducerSendPatch()
301+
instrumentation._getSendPatch()
302302
);
303303

304304
if (isWrapped(newProducer.transaction)) {
@@ -530,16 +530,15 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
530530

531531
transactionPromise
532532
.then((transaction: kafkaJs.Transaction) => {
533-
const originalSend = transaction.send.bind(transaction);
533+
const originalSend = transaction.send;
534534
transaction.send = function send(
535535
this: kafkaJs.Transaction,
536536
...args
537537
) {
538538
return context.with(
539539
trace.setSpan(context.active(), transactionSpan),
540540
() => {
541-
const patched =
542-
instrumentation._getProducerSendPatch()(originalSend);
541+
const patched = instrumentation._getSendPatch()(originalSend);
543542
return patched.apply(this, args).catch(err => {
544543
transactionSpan.setStatus({
545544
code: SpanStatusCode.ERROR,
@@ -552,7 +551,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
552551
);
553552
};
554553

555-
const originalSendBatch = transaction.sendBatch.bind(transaction);
554+
const originalSendBatch = transaction.sendBatch;
556555
transaction.sendBatch = function sendBatch(
557556
this: kafkaJs.Transaction,
558557
...args
@@ -561,9 +560,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
561560
trace.setSpan(context.active(), transactionSpan),
562561
() => {
563562
const patched =
564-
instrumentation._getProducerSendBatchPatch()(
565-
originalSendBatch
566-
);
563+
instrumentation._getSendBatchPatch()(originalSendBatch);
567564
return patched.apply(this, args).catch(err => {
568565
transactionSpan.setStatus({
569566
code: SpanStatusCode.ERROR,
@@ -576,7 +573,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
576573
);
577574
};
578575

579-
const originalCommit = transaction.commit.bind(transaction);
576+
const originalCommit = transaction.commit;
580577
transaction.commit = function commit(
581578
this: kafkaJs.Transaction,
582579
...args
@@ -589,7 +586,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
589586
);
590587
};
591588

592-
const originalAbort = transaction.abort.bind(transaction);
589+
const originalAbort = transaction.abort;
593590
transaction.abort = function abort(
594591
this: kafkaJs.Transaction,
595592
...args
@@ -616,7 +613,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
616613
};
617614
}
618615

619-
private _getProducerSendBatchPatch() {
616+
private _getSendBatchPatch() {
620617
const instrumentation = this;
621618
return (
622619
original: Producer['sendBatch'] | kafkaJs.Transaction['sendBatch']
@@ -665,7 +662,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
665662
};
666663
}
667664

668-
private _getProducerSendPatch() {
665+
private _getSendPatch() {
669666
const instrumentation = this;
670667
return (original: Producer['send'] | kafkaJs.Transaction['send']) => {
671668
return function send(

0 commit comments

Comments
 (0)