Skip to content

Commit

Permalink
fix: output 'noPluginName' in trace-api log messages where pluginNa…
Browse files Browse the repository at this point in the history
…me 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
  • Loading branch information
hcharley authored and kjin committed Jan 23, 2019
1 parent 2335934 commit 6793b09
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/trace-api.ts
Expand Up @@ -92,6 +92,7 @@ export class StackdriverTracer implements Tracer {

private enabled = false;
private pluginName: string;
private pluginNameToLog: string;
private logger: Logger|null = null;
private config: StackdriverTracerConfig|null = null;
private policy: TracePolicy|null = null;
Expand All @@ -102,6 +103,7 @@ export class StackdriverTracer implements Tracer {
*/
constructor(name: string) {
this.pluginName = name;
this.pluginNameToLog = this.pluginName ? this.pluginName : 'no-plugin-name';
this.disable(); // disable immediately
}

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

Expand Down Expand Up @@ -271,7 +273,7 @@ export class StackdriverTracer implements Tracer {
// seems to have some value, but isn't representable. The user probably
// needs a custom outer span that encompasses the entirety of work.
this.logger!.warn(`TraceApi#createChildSpan: [${
this.pluginName}] Creating phantom child span [${
this.pluginNameToLog}] Creating phantom child span [${
options.name}] because root span [${
rootSpan.span.name}] was already closed.`);
return UNCORRELATED_CHILD_SPAN;
Expand All @@ -281,7 +283,7 @@ export class StackdriverTracer implements Tracer {
// spans suggests a memory leak stemming from context confusion. This
// is likely due to userspace task queues or Promise implementations.
this.logger!.error(`TraceApi#createChildSpan: [${
this.pluginName}] Creating phantom child span [${
this.pluginNameToLog}] Creating phantom child span [${
options.name}] because the trace with root span [${
rootSpan.span.name}] has reached a limit of ${
this.config!
Expand All @@ -303,7 +305,7 @@ export class StackdriverTracer implements Tracer {
// checks equality -- this is OK because no automatic tracing plugin
// uses the RootSpanData API directly.
this.logger!.error(`TraceApi#createChildSpan: [${
this.pluginName}] Adding child span [${
this.pluginNameToLog}] Adding child span [${
options.name}] will cause the trace with root span [${
rootSpan.span.name}] to contain more than ${
this.config!
Expand All @@ -320,7 +322,7 @@ export class StackdriverTracer implements Tracer {
skipFrames: options.skipFrames ? options.skipFrames + 1 : 1
});
this.logger!.info(`TraceApi#createChildSpan: [${
this.pluginName}] Created child span [${options.name}]`);
this.pluginNameToLog}] Created child span [${options.name}]`);
return childContext;
} else if (rootSpan.type === SpanType.UNTRACED) {
// Context wasn't lost, but there's no root span, indicating that this
Expand All @@ -329,7 +331,7 @@ export class StackdriverTracer implements Tracer {
} else {
// Context was lost.
this.logger!.warn(`TraceApi#createChildSpan: [${
this.pluginName}] Creating phantom child span [${
this.pluginNameToLog}] Creating phantom child span [${
options.name}] because there is no root span.`);
return UNCORRELATED_CHILD_SPAN;
}
Expand Down

0 comments on commit 6793b09

Please sign in to comment.