Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Updated levels of some internal debug logs to error level
Browse files Browse the repository at this point in the history
  • Loading branch information
Serkan ÖZAL committed May 31, 2020
1 parent f4bfb47 commit a0c07fe
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
17 changes: 14 additions & 3 deletions src/Reporter.ts
Expand Up @@ -159,10 +159,21 @@ class Reporter {
this.latestReportingLimitedMinute = Math.floor(Date.now() / 1000);
}
if (response.statusCode !== 200) {
ThundraLogger.getInstance().debug(JSON.stringify(this.reports));
return reject({ status: response.statusCode, data: responseData });
// First, check whether or debug is enabled.
// If not no need to convert reports into JSON string to pass to "debug" function
// because "JSON.stringify" is not cheap operation.
if (ThundraLogger.getInstance().isDebugEnabled()) {
ThundraLogger.getInstance().debug(JSON.stringify(this.reports));
}
return reject({
status: response.statusCode,
data: responseData,
});
}
return resolve({ status: response.statusCode, data: responseData });
return resolve({
status: response.statusCode,
data: responseData,
});
});
};

Expand Down
12 changes: 8 additions & 4 deletions src/ThundraLogger.ts
Expand Up @@ -3,19 +3,23 @@ import ConfigNames from './config/ConfigNames';

class ThundraLogger {
static instance: ThundraLogger;
enabled: boolean;
debugEnabled: boolean;

constructor() {
this.enabled = ConfigProvider.get<boolean>(ConfigNames.THUNDRA_DEBUG_ENABLE);
this.debugEnabled = ConfigProvider.get<boolean>(ConfigNames.THUNDRA_DEBUG_ENABLE);
ThundraLogger.instance = this;
}

static getInstance(): ThundraLogger {
return ThundraLogger.instance ? ThundraLogger.instance : new ThundraLogger();
}

isDebugEnabled(): boolean {
return this.debugEnabled;
}

debug(message: any) {
if (this.enabled) {
if (this.debugEnabled) {
console.log(message);
}
}
Expand All @@ -29,7 +33,7 @@ class ThundraLogger {
}

toggle() {
this.enabled = !this.enabled;
this.debugEnabled = !this.debugEnabled;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ThundraWrapper.ts
Expand Up @@ -374,7 +374,7 @@ class ThundraWrapper {
}
})
.catch((error) => {
ThundraLogger.getInstance().debug(error);
ThundraLogger.getInstance().error(error);
// There is an error on "before-invocation" phase
// So skip Thundra wrapping and call original function directly
const result = this.originalFunction.call(
Expand Down
2 changes: 1 addition & 1 deletion src/opentracing/Span.ts
Expand Up @@ -126,7 +126,7 @@ class ThundraSpan extends Span {
this.tags[key] = keyValuePairs[key];
});
} catch (e) {
ThundraLogger.getInstance().debug(e);
ThundraLogger.getInstance().error(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/opentracing/instrument/Instrumenter.ts
Expand Up @@ -63,7 +63,7 @@ class Instrumenter {
content = content.substring(Module.wrapper[0].length, content.length - Module.wrapper[1].length);
}
} catch (ex) {
ThundraLogger.getInstance().debug(ex);
ThundraLogger.getInstance().error(ex);
}
}
self.origCompile.call(this, content, filename);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/integrations/AWSIntegration.ts
Expand Up @@ -303,7 +303,7 @@ class AWSIntegration implements Integration {
span.setTag(SpanTags.TRACE_LINKS, traceLinks);
}
} catch (error) {
ThundraLogger.getInstance().debug(`Error while injecting trace links, ${error}`);
ThundraLogger.getInstance().error(`Error while injecting trace links, ${error}`);
}
}

Expand Down Expand Up @@ -559,7 +559,7 @@ class AWSIntegration implements Integration {
request.params.ClientContext = Buffer.from(
JSON.stringify({ custom: clientContext })).toString('base64');
} catch (err) {
ThundraLogger.getInstance().debug('Cannot parse lambda client context not a valid JSON');
ThundraLogger.getInstance().error('Cannot parse lambda client context not a valid JSON');
}
} else {
request.params.ClientContext = Buffer.from(JSON.stringify({ custom })).toString('base64');
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/integrations/HttpIntegration.ts
Expand Up @@ -178,7 +178,7 @@ class HttpIntegration implements Integration {
}
span.setTag(HttpTags.BODY, lines[lines.length - 1]);
} catch (error) {
ThundraLogger.getInstance().debug(error);
ThundraLogger.getInstance().error(error);
}
}
}
Expand Down

0 comments on commit a0c07fe

Please sign in to comment.