Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions handwritten/pubsub/src/publisher/message-queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {logs as baseLogs, LoggingFunction} from '../logs';
*/
export const logs = {
publishBatch: baseLogs.pubsub.sublog('publish-batch') as LoggingFunction,
publishHedged: baseLogs.pubsub.sublog('publish-hedged') as LoggingFunction,
};

/**
Expand Down
8 changes: 8 additions & 0 deletions handwritten/pubsub/src/telemetry-tracing.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*!
* Copyright 2020-2024 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -676,6 +676,14 @@
PubsubEvents.addEvent('publish end', message);
}

static publishStartHedged(message: MessageWithAttributes) {
PubsubEvents.addEvent('publish start (hedged)', message);
}

static publishEndHedged(message: MessageWithAttributes) {
PubsubEvents.addEvent('publish end (hedged)', message);
}

static ackStart(message: MessageWithAttributes) {
PubsubEvents.addEvent('ack start', message);
}
Expand Down
30 changes: 30 additions & 0 deletions handwritten/pubsub/test/telemetry-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,34 @@ describe('OpenTelemetryTracer', () => {
);
});
});

describe('PubsubEvents', () => {
it('adds publish start (hedged) and publish end (hedged) events to parentSpan', () => {
const message: PubsubMessage = {};
const topicName = 'projects/test/topics/topicfoo';
const span = otel.PubsubSpans.createPublisherSpan(
message,
topicName,
'test',
);
assert.ok(span);
message.parentSpan = span;

otel.PubsubEvents.publishStart(message);
otel.PubsubEvents.publishStartHedged(message);
otel.PubsubEvents.publishEndHedged(message);
span.end();

const spans = exporter.getFinishedSpans();
assert.strictEqual(spans.length, 1);
const finishedSpan = spans[0];
assert.ok(finishedSpan);
const eventNames = finishedSpan.events.map(e => e.name);
assert.deepStrictEqual(eventNames, [
'publish start',
'publish start (hedged)',
'publish end (hedged)',
]);
});
});
});
Loading