Skip to content

Commit 5087464

Browse files
committed
feat(pubsub): add OpenTelemetry events and logging for hedged publish
1 parent 97232f5 commit 5087464

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎handwritten/pubsub/src/publisher/message-queues.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {logs as baseLogs, LoggingFunction} from '../logs';
3333
*/
3434
export const logs = {
3535
publishBatch: baseLogs.pubsub.sublog('publish-batch') as LoggingFunction,
36+
publishHedged: baseLogs.pubsub.sublog('publish-hedged') as LoggingFunction,
3637
};
3738

3839
/**

‎handwritten/pubsub/src/telemetry-tracing.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,14 @@ export class PubsubEvents {
676676
PubsubEvents.addEvent('publish end', message);
677677
}
678678

679+
static publishStartHedged(message: MessageWithAttributes) {
680+
PubsubEvents.addEvent('publish start (hedged)', message);
681+
}
682+
683+
static publishEndHedged(message: MessageWithAttributes) {
684+
PubsubEvents.addEvent('publish end (hedged)', message);
685+
}
686+
679687
static ackStart(message: MessageWithAttributes) {
680688
PubsubEvents.addEvent('ack start', message);
681689
}

‎handwritten/pubsub/test/telemetry-tracing.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,34 @@ describe('OpenTelemetryTracer', () => {
482482
);
483483
});
484484
});
485+
486+
describe('PubsubEvents', () => {
487+
it('adds publish start (hedged) and publish end (hedged) events to parentSpan', () => {
488+
const message: PubsubMessage = {};
489+
const topicName = 'projects/test/topics/topicfoo';
490+
const span = otel.PubsubSpans.createPublisherSpan(
491+
message,
492+
topicName,
493+
'test',
494+
);
495+
assert.ok(span);
496+
message.parentSpan = span;
497+
498+
otel.PubsubEvents.publishStart(message);
499+
otel.PubsubEvents.publishStartHedged(message);
500+
otel.PubsubEvents.publishEndHedged(message);
501+
span.end();
502+
503+
const spans = exporter.getFinishedSpans();
504+
assert.strictEqual(spans.length, 1);
505+
const finishedSpan = spans[0];
506+
assert.ok(finishedSpan);
507+
const eventNames = finishedSpan.events.map(e => e.name);
508+
assert.deepStrictEqual(eventNames, [
509+
'publish start',
510+
'publish start (hedged)',
511+
'publish end (hedged)',
512+
]);
513+
});
514+
});
485515
});

0 commit comments

Comments
 (0)