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

Commit d0337fa

Browse files
authored
fix: fix log messages and ignore falsey env vars (#724)
PR-URL: #724
1 parent e5a4d76 commit d0337fa

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,22 @@ type NormalizedConfig = TraceWriterConfig&PluginLoaderConfig&TopLevelConfig;
6767
*/
6868
function initConfig(projectConfig: Forceable<Config>):
6969
Forceable<NormalizedConfig> {
70+
// `|| undefined` prevents environmental variables that are empty strings
71+
// from overriding values provided in the config object passed to start().
7072
const envConfig = {
7173
logLevel: Number(process.env.GCLOUD_TRACE_LOGLEVEL) || undefined,
72-
projectId: process.env.GCLOUD_PROJECT,
74+
projectId: process.env.GCLOUD_PROJECT || undefined,
7375
serviceContext: {
74-
service: process.env.GAE_SERVICE || process.env.GAE_MODULE_NAME,
75-
version: process.env.GAE_VERSION || process.env.GAE_MODULE_VERSION,
76-
minorVersion: process.env.GAE_MINOR_VERSION
76+
service:
77+
process.env.GAE_SERVICE || process.env.GAE_MODULE_NAME || undefined,
78+
version: process.env.GAE_VERSION || process.env.GAE_MODULE_VERSION ||
79+
undefined,
80+
minorVersion: process.env.GAE_MINOR_VERSION || undefined
7781
}
7882
};
7983

8084
let envSetConfig: Config = {};
81-
if (process.env.hasOwnProperty('GCLOUD_TRACE_CONFIG')) {
85+
if (!!process.env.GCLOUD_TRACE_CONFIG) {
8286
envSetConfig =
8387
require(path.resolve(process.env.GCLOUD_TRACE_CONFIG!)) as Config;
8488
}

src/trace-api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export class TraceAgent implements TraceAgentInterface {
135135
}
136136

137137
return this.namespace!.runAndReturn(() => {
138+
this.logger!.info(`TraceApi#runInRootSpan: [${
139+
this.pluginName}] Created root span [${options.name}]`);
138140
// Attempt to read incoming trace context.
139141
let incomingTraceContext: IncomingTraceContext = {};
140142
if (isString(options.traceContext) && !this.config!.ignoreContextHeader) {
@@ -205,7 +207,7 @@ export class TraceAgent implements TraceAgentInterface {
205207
// with continuously growing number of child spans. The second case
206208
// seems to have some value, but isn't representable. The user probably
207209
// needs a custom outer span that encompasses the entirety of work.
208-
this.logger!.warn(`TraceApi#createChildspan: [${
210+
this.logger!.warn(`TraceApi#createChildSpan: [${
209211
this.pluginName}] Creating phantom child span [${
210212
options.name}] because root span [${
211213
rootSpan.span.name}] was already closed.`);
@@ -219,14 +221,16 @@ export class TraceAgent implements TraceAgentInterface {
219221
options.name, /* Span name */
220222
rootSpan.span.spanId, /* Parent's span ID */
221223
skipFrames); /* # of frames to skip in stack trace */
224+
this.logger!.info(`TraceApi#createChildSpan: [${
225+
this.pluginName}] Created child span [${options.name}]`);
222226
return childContext;
223227
} else if (rootSpan.type === SpanDataType.UNTRACED) {
224228
// Context wasn't lost, but there's no root span, indicating that this
225229
// request should not be traced.
226230
return UNTRACED_SPAN;
227231
} else {
228232
// Context was lost.
229-
this.logger!.warn(`TraceApi#createChildspan: [${
233+
this.logger!.warn(`TraceApi#createChildSpan: [${
230234
this.pluginName}] Creating phantom child span [${
231235
options.name}] because there is no root span.`);
232236
return UNCORRELATED_SPAN;

src/trace-writer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class TraceWriter extends common.Service {
321321
// Privatize and clear the buffer.
322322
const buffer = this.buffer;
323323
this.buffer = [];
324-
this.logger.debug('TraceWriter#flushBufffer: Flushing traces', buffer);
324+
this.logger.debug('TraceWriter#flushBuffer: Flushing traces', buffer);
325325
this.publish(`{"traces":[${buffer.join()}]}`);
326326
}
327327

@@ -334,7 +334,7 @@ export class TraceWriter extends common.Service {
334334
const uri = `https://cloudtrace.googleapis.com/v1/projects/${
335335
this.config.projectId}/traces`;
336336
const options = {method: 'PATCH', uri, body: json, headers};
337-
this.logger.debug('TraceWriter#publish: Publishing to ' + uri);
337+
this.logger.info('TraceWriter#publish: Publishing to ' + uri);
338338
this.request(options, (err, body?, response?) => {
339339
const statusCode = (response && response.statusCode) || 'unknown';
340340
if (err) {

0 commit comments

Comments
 (0)