Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 6793b09

Browse files
hcharleykjin
authored andcommitted
fix: output 'noPluginName' in trace-api log messages where pluginName is undefined (#958)
* Output `'noPluginName'` in trace-api log messages where pluginName is undefined This will change log messages like this from: ``` [JS] @google-cloud/trace-agent DEBUG TraceApi#createChildSpan: [undefined] Created child span [doSomething()] [JS] @google-cloud/trace-agent DEBUG TraceApi#createChildSpan: [undefined] Created child span [doSomething() -> browserStart] ``` To this: ``` [JS] @google-cloud/trace-agent DEBUG TraceApi#createChildSpan: [noPluginName] Created child span [doSomething()] [JS] @google-cloud/trace-agent DEBUG TraceApi#createChildSpan: [noPluginName] Created child span [doSomething() -> browserStart] ``` * debugging: change `noPluginName` to `no-plugin-name` for pluginNameToLog Fixes: https://github.com/googleapis/cloud-trace-nodejs/pull/958/files#r249880750
1 parent 2335934 commit 6793b09

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/trace-api.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class StackdriverTracer implements Tracer {
9292

9393
private enabled = false;
9494
private pluginName: string;
95+
private pluginNameToLog: string;
9596
private logger: Logger|null = null;
9697
private config: StackdriverTracerConfig|null = null;
9798
private policy: TracePolicy|null = null;
@@ -102,6 +103,7 @@ export class StackdriverTracer implements Tracer {
102103
*/
103104
constructor(name: string) {
104105
this.pluginName = name;
106+
this.pluginNameToLog = this.pluginName ? this.pluginName : 'no-plugin-name';
105107
this.disable(); // disable immediately
106108
}
107109

@@ -167,7 +169,7 @@ export class StackdriverTracer implements Tracer {
167169
const rootSpan = cls.get().getContext();
168170
if (rootSpan.type === SpanType.ROOT && !rootSpan.span.endTime) {
169171
this.logger!.warn(`TraceApi#runInRootSpan: [${
170-
this.pluginName}] Cannot create nested root spans.`);
172+
this.pluginNameToLog}] Cannot create nested root spans.`);
171173
return fn(UNCORRELATED_ROOT_SPAN);
172174
}
173175

@@ -271,7 +273,7 @@ export class StackdriverTracer implements Tracer {
271273
// seems to have some value, but isn't representable. The user probably
272274
// needs a custom outer span that encompasses the entirety of work.
273275
this.logger!.warn(`TraceApi#createChildSpan: [${
274-
this.pluginName}] Creating phantom child span [${
276+
this.pluginNameToLog}] Creating phantom child span [${
275277
options.name}] because root span [${
276278
rootSpan.span.name}] was already closed.`);
277279
return UNCORRELATED_CHILD_SPAN;
@@ -281,7 +283,7 @@ export class StackdriverTracer implements Tracer {
281283
// spans suggests a memory leak stemming from context confusion. This
282284
// is likely due to userspace task queues or Promise implementations.
283285
this.logger!.error(`TraceApi#createChildSpan: [${
284-
this.pluginName}] Creating phantom child span [${
286+
this.pluginNameToLog}] Creating phantom child span [${
285287
options.name}] because the trace with root span [${
286288
rootSpan.span.name}] has reached a limit of ${
287289
this.config!
@@ -303,7 +305,7 @@ export class StackdriverTracer implements Tracer {
303305
// checks equality -- this is OK because no automatic tracing plugin
304306
// uses the RootSpanData API directly.
305307
this.logger!.error(`TraceApi#createChildSpan: [${
306-
this.pluginName}] Adding child span [${
308+
this.pluginNameToLog}] Adding child span [${
307309
options.name}] will cause the trace with root span [${
308310
rootSpan.span.name}] to contain more than ${
309311
this.config!
@@ -320,7 +322,7 @@ export class StackdriverTracer implements Tracer {
320322
skipFrames: options.skipFrames ? options.skipFrames + 1 : 1
321323
});
322324
this.logger!.info(`TraceApi#createChildSpan: [${
323-
this.pluginName}] Created child span [${options.name}]`);
325+
this.pluginNameToLog}] Created child span [${options.name}]`);
324326
return childContext;
325327
} else if (rootSpan.type === SpanType.UNTRACED) {
326328
// Context wasn't lost, but there's no root span, indicating that this
@@ -329,7 +331,7 @@ export class StackdriverTracer implements Tracer {
329331
} else {
330332
// Context was lost.
331333
this.logger!.warn(`TraceApi#createChildSpan: [${
332-
this.pluginName}] Creating phantom child span [${
334+
this.pluginNameToLog}] Creating phantom child span [${
333335
options.name}] because there is no root span.`);
334336
return UNCORRELATED_CHILD_SPAN;
335337
}

0 commit comments

Comments
 (0)