@@ -28,7 +28,6 @@ import {
2828 Link ,
2929} from '@opentelemetry/api' ;
3030import { Attributes , PubsubMessage } from './publisher/pubsub-message' ;
31- import { PublishOptions } from './publisher/index' ;
3231import { Duration } from './temporal' ;
3332
3433export { 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 */
243220export 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-
253222export 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 {
838789export 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- } ;
0 commit comments