From ab118df51acd7faadbdaafed289913af8e73607c Mon Sep 17 00:00:00 2001 From: Vlad Shilov Date: Fri, 26 Jun 2026 18:26:52 +0200 Subject: [PATCH 1/2] deps(pubsub): bump @opentelemetry/core to ^2.0.0 --- handwritten/pubsub/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handwritten/pubsub/package.json b/handwritten/pubsub/package.json index 875998dd31a6..d040624984f0 100644 --- a/handwritten/pubsub/package.json +++ b/handwritten/pubsub/package.json @@ -55,7 +55,7 @@ "@google-cloud/projectify": "^5.0.0", "@google-cloud/promisify": "^5.0.0", "@opentelemetry/api": "~1.9.0", - "@opentelemetry/core": "^1.30.1", + "@opentelemetry/core": "^2.0.0", "@opentelemetry/semantic-conventions": "~1.39.0", "arrify": "^2.0.0", "extend": "^3.0.2", From 0f76b41c9afe2bc3bfd49ab2b67a45a022fdb651 Mon Sep 17 00:00:00 2001 From: Vlad Shilov Date: Fri, 26 Jun 2026 19:03:45 +0200 Subject: [PATCH 2/2] deps(pubsub): bump @opentelemetry/sdk-trace-base to ^2.0.0 and adapt tests Bumps the @opentelemetry/sdk-trace-base devDependency to ^2.0.0 so the test tree no longer pulls in @opentelemetry/core@1.x alongside the core@2.x bump, removing the duplicate-core install flagged in review. Adapts the tests for the sdk-trace-base v2 breaking changes: - BasicTracerProvider takes spanProcessors via constructor; register() removed (use trace.setGlobalTracerProvider). - ReadableSpan.parentSpanId -> parentSpanContext?.spanId. - The publish RPC span back-link must be created while the parent span is still open (addLink on an ended span is a no-op in v2); reorder the test to match the real publish flow. --- handwritten/pubsub/package.json | 2 +- handwritten/pubsub/test/subscriber.ts | 5 ++++- handwritten/pubsub/test/telemetry-tracing.ts | 9 +++++++-- handwritten/pubsub/test/tracing.ts | 10 +++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/handwritten/pubsub/package.json b/handwritten/pubsub/package.json index d040624984f0..72b48abd5d8c 100644 --- a/handwritten/pubsub/package.json +++ b/handwritten/pubsub/package.json @@ -70,7 +70,7 @@ }, "devDependencies": { "@grpc/proto-loader": "^0.8.0", - "@opentelemetry/sdk-trace-base": "^1.17.0", + "@opentelemetry/sdk-trace-base": "^2.0.0", "@types/duplexify": "^3.6.4", "@types/extend": "^3.0.4", "@types/lodash.snakecase": "^4.1.9", diff --git a/handwritten/pubsub/test/subscriber.ts b/handwritten/pubsub/test/subscriber.ts index d74cd76c005f..9597c3498e79 100644 --- a/handwritten/pubsub/test/subscriber.ts +++ b/handwritten/pubsub/test/subscriber.ts @@ -1200,7 +1200,10 @@ describe('Subscriber', () => { assert.strictEqual(spans[0].events.length, 2); const firstSpan = spans.pop(); assert.ok(firstSpan); - assert.strictEqual(firstSpan.parentSpanId, parentSpanContext.spanId); + assert.strictEqual( + firstSpan.parentSpanContext?.spanId, + parentSpanContext.spanId, + ); assert.strictEqual( firstSpan.name, `${subId} subscribe`, diff --git a/handwritten/pubsub/test/telemetry-tracing.ts b/handwritten/pubsub/test/telemetry-tracing.ts index 4ef42f105575..acc9c57906f0 100644 --- a/handwritten/pubsub/test/telemetry-tracing.ts +++ b/handwritten/pubsub/test/telemetry-tracing.ts @@ -361,7 +361,7 @@ describe('OpenTelemetryTracer', () => { 'receive', ); assert.strictEqual(childReadSpan.kind, SpanKind.CONSUMER); - assert.ok(childReadSpan.parentSpanId); + assert.ok(childReadSpan.parentSpanContext?.spanId); }); it('creates publish RPC spans', () => { @@ -373,14 +373,19 @@ describe('OpenTelemetryTracer', () => { 'test', ) as trace.Span; message.parentSpan = span; - span.end(); + // The publish RPC span adds a back-link onto the parent span, so it must + // be created while the parent is still open. This mirrors the real + // publish flow (Queue._publish), where parent spans are ended only after + // the RPC span is created. In @opentelemetry/sdk-trace-base v2, + // `addLink()` on an already-ended span is a no-op. const publishSpan = otel.PubsubSpans.createPublishRpcSpan( [message], topicName, 'test', ); + span.end(); publishSpan?.end(); const spans = exporter.getFinishedSpans(); const publishReadSpan = spans.pop(); diff --git a/handwritten/pubsub/test/tracing.ts b/handwritten/pubsub/test/tracing.ts index 7689253ad437..0c9d02ce4049 100644 --- a/handwritten/pubsub/test/tracing.ts +++ b/handwritten/pubsub/test/tracing.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import {trace} from '@opentelemetry/api'; import { BasicTracerProvider, InMemorySpanExporter, @@ -36,6 +37,9 @@ import { * its defined beforehand. */ export const exporter: InMemorySpanExporter = new InMemorySpanExporter(); -export const provider: BasicTracerProvider = new BasicTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); -provider.register(); +export const provider: BasicTracerProvider = new BasicTracerProvider({ + spanProcessors: [new SimpleSpanProcessor(exporter)], +}); +// `BasicTracerProvider.register()` was removed in @opentelemetry/sdk-trace-base +// v2; register the provider as the global one via the API instead. +trace.setGlobalTracerProvider(provider);