Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
0d9c0b2
feat: use the propagation inject framework for OpenTelemetry publishes
feywind Nov 18, 2022
4f3daa9
feat: add propagation extraction to subscriber for OpenTelemetry
feywind Nov 18, 2022
80d8b65
feat: work in progress on adding sub-spans
feywind Nov 22, 2022
cbd5992
add more spans
feywind Nov 28, 2022
75acbab
wrap subscriber on() handlers to get better receive process spans
feywind Nov 30, 2022
bb6cf85
update otel core version for tests
feywind Dec 1, 2022
5cddaed
fix: change some span names for doc updates
feywind Dec 8, 2022
d523b1f
fix: move emitter wrapper out one level, to catch user functions prop…
feywind Dec 8, 2022
fbe29a2
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Dec 14, 2022
197a214
fix: don't send anything besides what's actually needed during publish
feywind Dec 14, 2022
a36cfce
fix: close the publish span at RPC time, not up front
feywind Dec 14, 2022
5c4fef6
fix: delay caching of the trace provider so the user has a chance to …
feywind Dec 14, 2022
b58557d
build: bring OTel versions back to compatible with Node 12
feywind Dec 15, 2022
4b7cf0c
fix: clean up a few more namespace pollution issues in OTel support
feywind Dec 15, 2022
45047c7
tests: manually end the publish span for tests
feywind Dec 15, 2022
3995fd0
build: update package names for recent version updates
feywind Dec 15, 2022
f2f8f57
chore: get versions of OTel that work together and with Node 12
feywind Dec 16, 2022
4a2a79e
chore: linter nit
feywind Dec 16, 2022
bb815d3
chore: another linter nit
feywind Dec 16, 2022
5d60ff3
chore: OTel sample formatting
feywind Dec 16, 2022
f8a5c09
chore: some internal renaming to reflect the function rather than nam…
feywind Dec 20, 2022
d21480d
fix: more work towards the Promise-first publish flow
feywind Dec 21, 2022
fe4947d
tests: remove unnecessary init line
feywind Dec 21, 2022
568add9
fix: add tracing support for updating the topic name in publisher spans
feywind Dec 21, 2022
5243ea9
fix: use the most up to date name for topic, subscription, and iam
feywind Dec 21, 2022
8dd13f8
fix: update telemetry spans before publishing, in case the topic name…
feywind Dec 21, 2022
60c70a8
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Dec 21, 2022
57c1673
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Jan 23, 2023
0a3b9a6
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Apr 26, 2023
bc95037
chore: calm linter qualms
feywind Apr 26, 2023
02b395b
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Apr 26, 2023
a3d66c2
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Apr 26, 2023
a1870ac
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Apr 28, 2023
50c8f74
chore: merge branch 'otel-2' of https://github.com/feywind/nodejs-pub…
feywind Apr 28, 2023
90f9ead
fix: update drain() not to promisify
feywind Apr 28, 2023
4ce3fc4
tests: update unit tests for recent promise changes to publish()
feywind Apr 28, 2023
8e18826
feat: add modAck spans during leasing
feywind May 3, 2023
569d744
docs: add more code comment docs
feywind May 3, 2023
886c0ee
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 3, 2023
8b7e0a9
tests: unit test fixes, also include deadline and initial parameters …
feywind May 3, 2023
4df6be6
chore: merge branch 'otel-2' of https://github.com/feywind/nodejs-pub…
feywind May 3, 2023
83830d6
fix: make sure the subscriber span ends, update sample
feywind May 8, 2023
094f08d
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 8, 2023
a713a2e
tests: update unit test for latest changes
feywind May 9, 2023
58c979a
chore: merge branch 'otel-2' of https://github.com/feywind/nodejs-pub…
feywind May 9, 2023
171c8f9
chore: pull promise-based publish out of OTel change
feywind May 9, 2023
2b4dd6e
chore: merge remote-tracking branch 'feywind/promise-based-publish-me…
feywind May 9, 2023
7b13da5
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind May 12, 2023
f66cfcd
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind May 12, 2023
2e09a3d
chore: merge remote-tracking branch 'remotes/origin/main' into otel-2
feywind Jun 12, 2023
50bd1bf
tests: update otel sample test
feywind Jun 12, 2023
0e7e5da
wip: end all telemetry spans when clear() is called
feywind Jun 14, 2023
a287386
wip: add more unit tests
feywind Jun 14, 2023
68335e5
Merge branch 'legacy-v3' into otel-2
feywind Aug 15, 2023
0f2dc41
fix: include batch size with each published message span
feywind Aug 15, 2023
1ba495a
chore: fix lint
feywind Aug 15, 2023
49b0bc3
fix: separate out the getter and setter classes
feywind Aug 15, 2023
12f400d
chore: rename span related objects in subscriber
feywind Aug 15, 2023
febcd16
chore: rename SpanMaker
feywind Aug 15, 2023
a471875
docs: improved comments and lint fixes
feywind Aug 15, 2023
a37194d
docs: more class/comment updating
feywind Aug 15, 2023
9ec1fdf
fix: missing spans caused by renames; also do more renames
feywind Aug 17, 2023
5f33931
tests: more renaming issues
feywind Aug 18, 2023
f167885
tests: add otel test for FlowControlledPublisher
feywind Aug 18, 2023
feeccf1
tests: add lease manager tests for otel
feywind Aug 18, 2023
b218d5f
tests: add SubscriberSpans unit tests
feywind Aug 21, 2023
ee09b69
fix: simplify logic for HTTP/1.1 REST fallback option (#1809)
gcf-owl-bot[bot] Aug 30, 2023
421c678
build: update Node.js version and base Debian version (#1793)
gcf-owl-bot[bot] Aug 3, 2023
7858cbc
docs: fix node release schedule link (#1794)
gcf-owl-bot[bot] Aug 3, 2023
25eb27a
chore: update release-please post-processing for nodejs apiary (#1805)
gcf-owl-bot[bot] Aug 17, 2023
bfcf523
fix: Make retry policy back off more aggressively for RPCs that retry…
gcf-owl-bot[bot] Aug 24, 2023
dedfdea
fix: set grpc keepalive time|outs by default (#1814)
feywind Sep 5, 2023
ddf8b8a
fix: always fill the topic and sub names when creating from a PubSub …
feywind Sep 7, 2023
edaa213
chore(legacy-v3): release 3.7.4 (#1820)
release-please[bot] Sep 11, 2023
2471c16
Merge branch 'legacy-v3' into otel-2
feywind Sep 13, 2023
d0503d0
chore: merge remote-tracking branch 'remotes/origin/otel-2' into otel-4
feywind Sep 20, 2023
6e4cbb3
Merge branch 'main' into otel-4
feywind Sep 20, 2023
df70922
docs: update copyrights to make header-check happy
feywind Sep 20, 2023
161fb73
chore: remove left-in console.trace
feywind Sep 20, 2023
ad9cfa2
feat: update opentelemetry packages to latest
feywind Sep 20, 2023
4acfbbc
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Sep 20, 2023
34055d1
Merge branch 'main' into otel-4
feywind Sep 21, 2023
1e6887b
chore: merge (correct) remote-tracking branch 'remotes/feywind/otel-2…
feywind Sep 21, 2023
1c00a67
chore: merge branch 'otel-4' of https://github.com/feywind/nodejs-pub…
feywind Sep 21, 2023
6512ace
samples: mostly whitespace, but updated OTel sample
feywind Oct 12, 2023
8649123
Merge branch 'main' into otel-4
feywind Oct 16, 2023
b325621
Merge branch 'main' into otel-4
feywind Nov 3, 2023
61d7ecd
feat: updates for the new design doc: batching, events, separate RPC …
feywind Nov 29, 2023
9ee3066
tests: fix / update tests for batch changes
feywind Nov 29, 2023
94e1e91
feat: change ack/nack/modack to be events
feywind Nov 29, 2023
aac3edd
fix: fixes for previous commits
feywind Nov 29, 2023
0d64d90
fix: move span closing to subscriber, upon (n)ack
feywind Nov 30, 2023
97d6bef
docs: update custom gcp attributes
feywind Nov 30, 2023
75dc17c
Merge branch 'main' into otel-4
feywind Nov 30, 2023
6c0b08c
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Nov 30, 2023
d4cb0e8
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 30, 2023
3171a20
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Nov 30, 2023
5b9a95f
docs: update subscriber comments
feywind Nov 30, 2023
c54efc6
tests: add unit tests for shutdown events
feywind Nov 30, 2023
fb42fa4
fix: missed commits from previous
feywind Nov 30, 2023
d70c94b
fix: update span attributes for ordering key
feywind Dec 4, 2023
1a33c99
fix: update gcp.pubsub to gcp_pubsub
feywind Dec 5, 2023
579d2c9
feat: add back in receive response spans
feywind Dec 5, 2023
7e00b10
docs: fix inadequate comments for deadline
feywind Dec 5, 2023
e70516b
feat: add ack/nack/modack events in processing
feywind Dec 5, 2023
f3b4070
fix: publisher -> publish scheduler
feywind Dec 5, 2023
be5fa9c
Merge pull request #4 from feywind/otel-4-links
feywind Jan 31, 2024
434ece2
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Jan 31, 2024
9e6baf8
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4…
feywind Feb 27, 2024
f0909bc
chore: fix intermediate samples build exclusion
feywind Feb 27, 2024
09319ee
feat: update otel span names and attributes to latest spec
feywind Mar 13, 2024
bdfa0d6
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4…
feywind Mar 13, 2024
d4a1041
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Mar 13, 2024
1a64d5d
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Mar 13, 2024
cd1843f
chore: remove extraneous import
feywind Mar 13, 2024
85d34b7
feat: add publish start/end events
feywind Mar 14, 2024
adf3be3
docs: comment updates about modack spans
feywind Mar 14, 2024
700db86
tests: add a bunch of unit tests for new otel stuff
feywind Mar 21, 2024
55b67b0
fix: subId might be undefined
feywind Mar 21, 2024
6009a1f
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Mar 21, 2024
9bbe060
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Mar 21, 2024
d5f1c5d
fix: revert incorrect attribute change
feywind Mar 22, 2024
9e12418
docs: clarify some comments
feywind Mar 22, 2024
cd1856c
tests: update the test for the last commit
feywind Mar 22, 2024
000fd12
feat: otel updates for latest spec doc
feywind Mar 22, 2024
d0a7ebe
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Mar 22, 2024
4c384bc
fix: change processing span to use ack/nack instead of callback time
feywind Mar 25, 2024
52a640c
Merge branch 'main' into otel-4
feywind Apr 4, 2024
1b19c73
Merge pull request #6 from feywind/otel-process-end
feywind Apr 4, 2024
8695174
docs: fix copyright ranges on renamed/updated files
feywind Apr 4, 2024
5700754
chore: OTel changed how semantic attribute names are specified
feywind Apr 4, 2024
26f0f51
tests: update otel sample tests for latest changes
feywind Apr 4, 2024
c09fb06
samples: update JS otel sample from TS
feywind Apr 4, 2024
39418d7
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Apr 4, 2024
479b085
samples: update otel tracing sample with the correct tags and some ot…
feywind May 1, 2024
16aba6c
samples: split otel samples into listen/publish
feywind Jul 12, 2024
067f695
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Jul 12, 2024
f4b4014
chore: merge branch 'otel-4' into otel-4-samples
feywind Jul 12, 2024
34f35a1
tests: fix resource name for otel
feywind Jul 12, 2024
ede295a
build: remove defunct typing
feywind Jul 12, 2024
c89d29c
Merge pull request #7 from feywind/otel-4-samples
feywind Jul 12, 2024
4f218eb
feat: add support for globally enabling (and disabling) otel tracing
feywind Jul 12, 2024
3b07e63
chore: merge remote-tracking branch 'remotes/origin/main' into otel-4
feywind Jul 15, 2024
9995c99
feat: add bidi links between RPC and message spans, and filter by isS…
feywind Jul 17, 2024
68e4293
feat: track code.function
feywind Jul 17, 2024
95e131e
Merge pull request #8 from feywind/otel-4-enable-flag
feywind Jul 26, 2024
9c04f8b
docs: update comment based on CR
feywind Jul 26, 2024
175526e
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Jul 26, 2024
b66fa7e
tests: publishSpan might be undefined if tracing isn't enabled
feywind Jul 26, 2024
2f2585b
Merge pull request #9 from feywind/otel-4-sampler
feywind Jul 26, 2024
6c5c97e
chore: merge remote-tracking branch 'remotes/feywind/otel-4' into ote…
feywind Jul 26, 2024
b3e7524
chore: small merge issue
feywind Jul 26, 2024
9292e2f
feat: track code.function
feywind Jul 26, 2024
d436f2c
fix: update spans for ack/modack to match newest spec
feywind Jul 26, 2024
8974fb0
fix: update ack/modack spans to match latest spec (draft)
feywind Jul 30, 2024
3a4cf90
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jul 30, 2024
0513cd2
samples: add the otel enable flag to new otel samples
feywind Aug 7, 2024
f195bf5
Merge pull request #12 from feywind/otel-4-samples-enable
feywind Aug 7, 2024
3ea2fc4
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 7, 2024
c0db4e7
Merge branch 'main' into otel-4
feywind Aug 23, 2024
83b6e41
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 23, 2024
4283276
docs: last minute review, mostly adding private/internal doc tags
feywind Aug 23, 2024
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
2 changes: 1 addition & 1 deletion src/publisher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class Publisher {
);

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

Expand Down
12 changes: 12 additions & 0 deletions src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {CallOptions} from 'google-gax';
import {Transform} from 'stream';
import {google} from '../protos/protos';
import {SchemaServiceClient} from './v1';
import * as tracing from './telemetry-tracing';

/**
* Project ID placeholder.
Expand Down Expand Up @@ -88,6 +89,12 @@ export interface ClientConfig extends gax.GrpcClientOptions {
servicePath?: string;
port?: string | number;
sslCreds?: gax.grpc.ChannelCredentials;

/**
* Enables OpenTelemetry tracing (newer, more full implementation). This
* defaults to false/undefined
*/
enableOpenTelemetryTracing?: boolean;
}

export interface PageOptions {
Expand Down Expand Up @@ -316,6 +323,11 @@ export class PubSub {
},
options
);

if (this.options.enableOpenTelemetryTracing) {
tracing.setGloballyEnabled(true);
}

/**
* @name PubSub#isEmulator
* @type {boolean}
Expand Down
83 changes: 67 additions & 16 deletions src/telemetry-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function getTracer(): Tracer {
*/
export enum OpenTelemetryLevel {
/**
* None: OTel support is not enabled because we found no trace provider.
* None: OTel support is not enabled because we found no trace provider, or
* the user has not enabled it.
*/
None = 0,

Expand All @@ -75,6 +76,20 @@ export enum OpenTelemetryLevel {
Modern = 2,
}

// True if user code elsewhere wants to enable OpenTelemetry support.
let globallyEnabled = false;

/**
* Manually set the OpenTelemetry enabledness.
*
* @param enabled The enabled flag to use, to override any automated methods.
* @private
* @internal
*/
export function setGloballyEnabled(enabled: boolean) {
globallyEnabled = enabled;
}

/**
* Tries to divine what sort of OpenTelemetry we're supporting. See the enum
* for the meaning of the values, and other notes.
Expand All @@ -87,16 +102,16 @@ export enum OpenTelemetryLevel {
export function isEnabled(
publishSettings?: PublishOptions
): OpenTelemetryLevel {
// If there's no trace provider attached, do nothing in any case.
const traceProvider = trace.getTracerProvider();
if (!traceProvider) {
// If we're not enabled, skip everything.
if (!globallyEnabled) {
return OpenTelemetryLevel.None;
}

if (publishSettings?.enableOpenTelemetryTracing) {
return OpenTelemetryLevel.Legacy;
}

// Enable modern support.
return OpenTelemetryLevel.Modern;
}

Expand Down Expand Up @@ -342,7 +357,14 @@ export class PubsubSpans {
return spanAttributes;
}

static createPublisherSpan(message: PubsubMessage, topicName: string): Span {
static createPublisherSpan(
message: PubsubMessage,
topicName: string
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

const topicInfo = getTopicInfo(topicName);
const span: Span = getTracer().startSpan(`${topicName} create`, {
kind: SpanKind.PRODUCER,
Expand Down Expand Up @@ -373,7 +395,11 @@ export class PubsubSpans {
message: PubsubMessage,
subName: string,
parent: Context | undefined
): Span {
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

const subInfo = getSubscriptionInfo(subName);
const name = `${subInfo.subId ?? subName} subscribe`;
const attributes = this.createAttributes(subInfo, message);
Expand Down Expand Up @@ -404,6 +430,10 @@ export class PubsubSpans {
parentSpan?: Span,
attributes?: SpanAttributes
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

const parent = message?.parentSpan ?? parentSpan;
if (parent) {
return getTracer().startSpan(
Expand All @@ -430,7 +460,11 @@ export class PubsubSpans {
static createPublishRpcSpan(
messages: MessageWithAttributes[],
topicName: string
): Span {
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

const spanAttributes = PubsubSpans.createAttributes(
getTopicInfo(topicName)
);
Expand Down Expand Up @@ -463,7 +497,11 @@ export class PubsubSpans {
static createReceiveResponseRpcSpan(
messageSpans: (Span | undefined)[],
subName: string
): Span {
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

const spanAttributes = PubsubSpans.createAttributes(
getSubscriptionInfo(subName)
);
Expand Down Expand Up @@ -654,6 +692,10 @@ export function injectSpan(
message: MessageWithAttributes,
enabled: OpenTelemetryLevel
): void {
if (!globallyEnabled) {
return;
}

if (!message.attributes) {
message.attributes = {};
}
Expand Down Expand Up @@ -721,6 +763,10 @@ export function extractSpan(
subName: string,
enabled: OpenTelemetryLevel
): Span | undefined {
if (!globallyEnabled) {
return undefined;
}

if (message.parentSpan) {
return message.parentSpan;
}
Expand Down Expand Up @@ -770,13 +816,18 @@ export const legacyExports = {
attributes?: SpanAttributes,
parent?: SpanContext
): Span {
return getTracer().startSpan(
spanName,
{
kind,
attributes,
},
parent ? trace.setSpanContext(context.active(), parent) : undefined
);
if (!globallyEnabled) {
// This isn't great, but it's the fact of the situation.
return undefined as unknown as Span;
} else {
return getTracer().startSpan(
spanName,
{
kind,
attributes,
},
parent ? trace.setSpanContext(context.active(), parent) : undefined
);
}
},
};
3 changes: 3 additions & 0 deletions test/publisher/flow-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ describe('Flow control publisher', () => {

afterEach(() => {
sandbox.restore();
tracing.setGloballyEnabled(false);
});

it('should create a flow span if a parent exists', async () => {
tracing.setGloballyEnabled(true);

const fcp = new fp.FlowControlledPublisher(publisher);
const message = {
data: Buffer.from('foo'),
Expand Down
5 changes: 5 additions & 0 deletions test/publisher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('Publisher', () => {

afterEach(() => {
sandbox.restore();
tracing.setGloballyEnabled(false);
});

describe('initialization', () => {
Expand Down Expand Up @@ -193,6 +194,8 @@ describe('Publisher', () => {
});

it('export created spans', async () => {
tracing.setGloballyEnabled(true);

// Setup trace exporting
tracingPublisher = new Publisher(topic);
const msg = {data: buffer} as p.PubsubMessage;
Expand Down Expand Up @@ -374,6 +377,8 @@ describe('Publisher', () => {
});

it('should issue a warning if OpenTelemetry span context key is set', () => {
tracing.setGloballyEnabled(true);

const warnSpy = sinon.spy(console, 'warn');
const attributes = {
[tracing.legacyAttributeName]: 'foobar',
Expand Down
12 changes: 12 additions & 0 deletions test/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {google} from '../protos/protos';
import * as pubsubTypes from '../src/pubsub';
import {Snapshot} from '../src/snapshot';
import * as subby from '../src/subscription';
import * as tracing from '../src/telemetry-tracing';
import {Topic} from '../src/topic';
import * as util from '../src/util';
import {Schema, SchemaTypes, ISchema, SchemaViews} from '../src/schema';
Expand Down Expand Up @@ -303,6 +304,17 @@ describe('PubSub', () => {
assert.strictEqual(pubsub.isOpen, true);
});

it('should enable OpenTelemetry if requested', () => {
const options: pubsubTypes.ClientConfig = {
enableOpenTelemetryTracing: true,
};
const pubsub = new PubSub(options);
assert.strictEqual(
tracing.isEnabled(),
tracing.OpenTelemetryLevel.Modern
);
});

it('should not be in the opened state after close()', async () => {
await pubsub.close?.();
assert.strictEqual(pubsub.isOpen, false);
Expand Down
5 changes: 5 additions & 0 deletions test/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ describe('Subscriber', () => {
afterEach(() => {
sandbox.restore();
subscriber.close();
tracing.setGloballyEnabled(false);
});

describe('initialization', () => {
Expand Down Expand Up @@ -901,6 +902,8 @@ describe('Subscriber', () => {
});

it('exports a span once it is created', () => {
tracing.setGloballyEnabled(true);

subscription = new FakeSubscription() as {} as Subscription;
subscriber = new Subscriber(subscription, enableTracing);
message = new Message(subscriber, RECEIVED_MESSAGE);
Expand Down Expand Up @@ -960,6 +963,8 @@ describe('Subscriber', () => {
});

it('exports a span even when a span context is not present on message', () => {
tracing.setGloballyEnabled(true);

subscriber = new Subscriber(subscription, enableTracing);
subscriber.open();

Expand Down
8 changes: 8 additions & 0 deletions test/telemetry-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import {PubsubMessage} from '../src/publisher';
describe('OpenTelemetryTracer', () => {
beforeEach(() => {
exporter.reset();
otel.setGloballyEnabled(true);
});
afterEach(() => {
exporter.reset();
otel.setGloballyEnabled(false);
});

describe('project parser', () => {
Expand Down Expand Up @@ -120,6 +122,7 @@ describe('OpenTelemetryTracer', () => {
message,
'projects/test/topics/topicfoo'
);
assert.ok(span);

otel.injectSpan(span, message, otel.OpenTelemetryLevel.Legacy);

Expand Down Expand Up @@ -148,6 +151,7 @@ describe('OpenTelemetryTracer', () => {
message,
'projects/test/topics/topicfoo'
);
assert.ok(span);

const warnSpy = sinon.spy(console, 'warn');
try {
Expand Down Expand Up @@ -268,6 +272,7 @@ describe('OpenTelemetryTracer', () => {
tests.message,
tests.topicInfo.topicName!
);
assert.ok(span);
span.end();

const spans = exporter.getFinishedSpans();
Expand All @@ -291,6 +296,7 @@ describe('OpenTelemetryTracer', () => {
tests.message,
tests.topicInfo.topicName!
);
assert.ok(span);
otel.PubsubSpans.updatePublisherTopicName(
span,
'projects/foo/topics/other'
Expand All @@ -315,11 +321,13 @@ describe('OpenTelemetryTracer', () => {
tests.message,
tests.topicInfo.topicName!
);
assert.ok(parentSpan);
const span = otel.PubsubSpans.createReceiveSpan(
tests.message,
tests.subInfo.subName!,
otel.spanContextToContext(parentSpan.spanContext())
);
assert.ok(span);
span.end();
parentSpan.end();

Expand Down
⌂ 换网址