Skip to content

Commit 12e94df

Browse files
committed
chore!: remove legacy otel support
1 parent c47aa5a commit 12e94df

File tree

8 files changed

+52
-192
lines changed

8 files changed

+52
-192
lines changed

src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,3 @@ if (process.env.DEBUG_GRPC) {
184184
}
185185
import * as protos from '../protos/protos';
186186
export {protos};
187-
188-
// Deprecated; please see the updated OpenTelemetry sample
189-
// for an example of how to use telemetry in this library.
190-
import {legacyExports} from './telemetry-tracing';
191-
export {legacyExports as openTelemetry};

src/publisher/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export class Publisher {
336336
* @param {PubsubMessage} message The message to create a span for
337337
*/
338338
getParentSpan(message: PubsubMessage, caller: string): Span | undefined {
339-
const enabled = tracing.isEnabled(this.settings);
339+
const enabled = tracing.isEnabled();
340340
if (!enabled) {
341341
return undefined;
342342
}
@@ -353,7 +353,7 @@ export class Publisher {
353353

354354
// If the span's context is valid we should inject the propagation trace context.
355355
if (span && isSpanContextValid(span.spanContext())) {
356-
tracing.injectSpan(span, message, enabled);
356+
tracing.injectSpan(span, message);
357357
}
358358

359359
return span;

src/subscriber.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,6 @@ export interface SubscriberOptions {
578578
flowControl?: FlowControlOptions;
579579
useLegacyFlowControl?: boolean;
580580
streamingOptions?: MessageStreamOptions;
581-
582-
/** @deprecated Unset this and instantiate a tracer; support will be
583-
* enabled automatically. */
584-
enableOpenTelemetryTracing?: boolean;
585581
}
586582

587583
const minAckDeadlineForExactlyOnceDelivery = Duration.from({seconds: 60});
@@ -604,7 +600,6 @@ export class Subscriber extends EventEmitter {
604600
private _acks!: AckQueue;
605601
private _histogram: Histogram;
606602
private _inventory!: LeaseManager;
607-
private _useLegacyOpenTelemetry: boolean;
608603
private _latencies: Histogram;
609604
private _modAcks!: ModAckQueue;
610605
private _name!: string;
@@ -622,7 +617,6 @@ export class Subscriber extends EventEmitter {
622617
this.maxBytes = defaultOptions.subscription.maxOutstandingBytes;
623618
this.useLegacyFlowControl = false;
624619
this.isOpen = false;
625-
this._useLegacyOpenTelemetry = false;
626620
this._histogram = new Histogram({min: 10, max: 600});
627621
this._latencies = new Histogram();
628622
this._subscription = subscription;
@@ -966,8 +960,6 @@ export class Subscriber extends EventEmitter {
966960
setOptions(options: SubscriberOptions): void {
967961
this._options = options;
968962

969-
this._useLegacyOpenTelemetry = options.enableOpenTelemetryTracing || false;
970-
971963
// The user-set ackDeadline value basically pegs the extension time.
972964
// We'll emulate it by overwriting min/max.
973965
const passedAckDeadline = options.ackDeadline;
@@ -1015,11 +1007,9 @@ export class Subscriber extends EventEmitter {
10151007
* @private
10161008
*/
10171009
private createParentSpan(message: Message): void {
1018-
const enabled = tracing.isEnabled({
1019-
enableOpenTelemetryTracing: this._useLegacyOpenTelemetry,
1020-
});
1010+
const enabled = tracing.isEnabled();
10211011
if (enabled) {
1022-
tracing.extractSpan(message, this.name, enabled);
1012+
tracing.extractSpan(message, this.name);
10231013
}
10241014
}
10251015

src/telemetry-tracing.ts

Lines changed: 6 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
Link,
2929
} from '@opentelemetry/api';
3030
import {Attributes, PubsubMessage} from './publisher/pubsub-message';
31-
import {PublishOptions} from './publisher/index';
3231
import {Duration} from './temporal';
3332

3433
export {Span};
@@ -65,13 +64,6 @@ export enum OpenTelemetryLevel {
6564
*/
6665
None = 0,
6766

68-
/**
69-
* Legacy: We found a trace provider, but the user also specified the old
70-
* manual enable flag; this will trigger the legacy attribute being included.
71-
* The modern propagation attribute will _also_ be included.
72-
*/
73-
Legacy = 1,
74-
7567
/**
7668
* Modern: We will only inject/extract the modern propagation attribute.
7769
*/
@@ -96,26 +88,11 @@ export function setGloballyEnabled(enabled: boolean) {
9688
* Tries to divine what sort of OpenTelemetry we're supporting. See the enum
9789
* for the meaning of the values, and other notes.
9890
*
99-
* Legacy OTel is no longer officially supported, but we don't want to
100-
* break anyone at a non-major.
101-
*
10291
* @private
10392
* @internal
10493
*/
105-
export function isEnabled(
106-
publishSettings?: PublishOptions,
107-
): OpenTelemetryLevel {
108-
// If we're not enabled, skip everything.
109-
if (!globallyEnabled) {
110-
return OpenTelemetryLevel.None;
111-
}
112-
113-
if (publishSettings?.enableOpenTelemetryTracing) {
114-
return OpenTelemetryLevel.Legacy;
115-
}
116-
117-
// Enable modern support.
118-
return OpenTelemetryLevel.Modern;
94+
export function isEnabled(): OpenTelemetryLevel {
95+
return globallyEnabled ? OpenTelemetryLevel.Modern : OpenTelemetryLevel.None;
11996
}
12097

12198
/**
@@ -242,14 +219,6 @@ export function spanContextToContext(
242219
*/
243220
export const modernAttributeName = 'googclient_traceparent';
244221

245-
/**
246-
* The old legacy attribute name.
247-
*
248-
* @private
249-
* @internal
250-
*/
251-
export const legacyAttributeName = 'googclient_OpenTelemetrySpanContext';
252-
253222
export interface AttributeParams {
254223
// Fully qualified.
255224
topicName?: string;
@@ -762,11 +731,7 @@ export class PubsubEvents {
762731
* @private
763732
* @internal
764733
*/
765-
export function injectSpan(
766-
span: Span,
767-
message: MessageWithAttributes,
768-
enabled: OpenTelemetryLevel,
769-
): void {
734+
export function injectSpan(span: Span, message: MessageWithAttributes): void {
770735
if (!globallyEnabled) {
771736
return;
772737
}
@@ -783,18 +748,6 @@ export function injectSpan(
783748
delete message.attributes[modernAttributeName];
784749
}
785750

786-
// If we're in legacy mode, add that header as well.
787-
if (enabled === OpenTelemetryLevel.Legacy) {
788-
if (message.attributes[legacyAttributeName]) {
789-
console.warn(
790-
`${legacyAttributeName} key set as message attribute, but will be overridden.`,
791-
);
792-
}
793-
message.attributes[legacyAttributeName] = JSON.stringify(
794-
span.spanContext(),
795-
);
796-
}
797-
798751
// Always do propagation injection with the trace context.
799752
const context = trace.setSpanContext(ROOT_CONTEXT, span.spanContext());
800753
propagation.inject(context, message, pubsubSetter);
@@ -820,9 +773,7 @@ export function containsSpanContext(message: MessageWithAttributes): boolean {
820773
}
821774

822775
const keys = Object.getOwnPropertyNames(message.attributes);
823-
return !!keys.find(
824-
n => n === legacyAttributeName || n === modernAttributeName,
825-
);
776+
return !!keys.find(n => n === modernAttributeName);
826777
}
827778

828779
/**
@@ -838,7 +789,6 @@ export function containsSpanContext(message: MessageWithAttributes): boolean {
838789
export function extractSpan(
839790
message: MessageWithAttributes,
840791
subName: string,
841-
enabled: OpenTelemetryLevel,
842792
): Span | undefined {
843793
if (!globallyEnabled) {
844794
return undefined;
@@ -852,26 +802,8 @@ export function extractSpan(
852802

853803
let context: Context | undefined;
854804

855-
if (enabled === OpenTelemetryLevel.Legacy) {
856-
// Only prefer the legacy attributes to no trace context attribute.
857-
if (
858-
keys.includes(legacyAttributeName) &&
859-
!keys.includes(modernAttributeName)
860-
) {
861-
const legacyValue = message.attributes?.[legacyAttributeName];
862-
if (legacyValue) {
863-
const parentSpanContext: SpanContext | undefined = legacyValue
864-
? JSON.parse(legacyValue)
865-
: undefined;
866-
if (parentSpanContext) {
867-
context = spanContextToContext(parentSpanContext);
868-
}
869-
}
870-
}
871-
} else {
872-
if (keys.includes(modernAttributeName)) {
873-
context = propagation.extract(ROOT_CONTEXT, message, pubsubGetter);
874-
}
805+
if (keys.includes(modernAttributeName)) {
806+
context = propagation.extract(ROOT_CONTEXT, message, pubsubGetter);
875807
}
876808

877809
const span = PubsubSpans.createReceiveSpan(
@@ -883,33 +815,3 @@ export function extractSpan(
883815
message.parentSpan = span;
884816
return span;
885817
}
886-
887-
// Since these were exported on the main Pub/Sub index in the previous
888-
// version, we have to export them until the next major.
889-
export const legacyExports = {
890-
/**
891-
* @deprecated
892-
* Use the new telemetry functionality instead; see the updated OpenTelemetry
893-
* sample for an example.
894-
*/
895-
createSpan: function (
896-
spanName: string,
897-
kind: SpanKind,
898-
attributes?: SpanAttributes,
899-
parent?: SpanContext,
900-
): Span {
901-
if (!globallyEnabled) {
902-
// This isn't great, but it's the fact of the situation.
903-
return undefined as unknown as Span;
904-
} else {
905-
return getTracer().startSpan(
906-
spanName,
907-
{
908-
kind,
909-
attributes,
910-
},
911-
parent ? trace.setSpanContext(context.active(), parent) : undefined,
912-
);
913-
}
914-
},
915-
};

test/publisher/index.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,6 @@ describe('Publisher', () => {
375375
done();
376376
});
377377
});
378-
379-
it('should issue a warning if OpenTelemetry span context key is set', () => {
380-
tracing.setGloballyEnabled(true);
381-
382-
const warnSpy = sinon.spy(console, 'warn');
383-
const attributes = {
384-
[tracing.legacyAttributeName]: 'foobar',
385-
};
386-
const fakeMessageWithOTKey = {data, attributes};
387-
const publisherTracing = new Publisher(topic, {
388-
enableOpenTelemetryTracing: true,
389-
});
390-
publisherTracing.publishMessage(fakeMessageWithOTKey, warnSpy);
391-
assert.ok(warnSpy.called);
392-
warnSpy.restore();
393-
});
394378
});
395379
});
396380

test/pubsub.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,34 @@ describe('PubSub', () => {
356356
it('should set isEmulator to false by default', () => {
357357
assert.strictEqual(pubsub.isEmulator, false);
358358
});
359+
360+
describe('tracing', () => {
361+
beforeEach(() => {
362+
tracing.setGloballyEnabled(false);
363+
});
364+
afterEach(() => {
365+
tracing.setGloballyEnabled(false);
366+
});
367+
it('should not enable OTel when tracing is disabled', () => {
368+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
369+
const _pubsub = new PubSub({});
370+
assert.strictEqual(
371+
tracing.isEnabled(),
372+
tracing.OpenTelemetryLevel.None,
373+
);
374+
});
375+
376+
it('should enable OTel when tracing is enabled through constructor', () => {
377+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
378+
const _pubsub = new PubSub({
379+
enableOpenTelemetryTracing: true,
380+
});
381+
assert.strictEqual(
382+
tracing.isEnabled(),
383+
tracing.OpenTelemetryLevel.Modern,
384+
);
385+
});
386+
});
359387
});
360388

361389
describe('createSubscription', () => {

0 commit comments

Comments
 (0)