Skip to content

Commit aafa3e0

Browse files
astuyvehghotra
andauthored
feat: Move log line to public metric method (#280)
* feat: Move log line to public metric method * Update src/metrics/listener.ts Co-authored-by: Harvinder Ghotra <[email protected]> * fix: lint Co-authored-by: Harvinder Ghotra <[email protected]>
1 parent 15eb8b8 commit aafa3e0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/metrics/listener.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class MetricsListener {
5656

5757
constructor(private kmsClient: KMSService, private config: MetricsConfig) {
5858
this.apiKey = this.getAPIKey(config);
59+
this.config = config;
5960
}
6061

6162
public async onStartInvocation(_: any) {
@@ -143,6 +144,11 @@ export class MetricsListener {
143144

144145
const dist = new Distribution(name, [{ timestamp: metricTime, value }], ...tags);
145146

147+
if (!this.apiKey) {
148+
const errorMessage = "api key not configured, see https://dtdg.co/sls-node-metrics";
149+
logError(errorMessage);
150+
return;
151+
}
146152
if (this.currentProcessor !== undefined) {
147153
// tslint:disable-next-line: no-floating-promises
148154
this.currentProcessor.then((processor) => {
@@ -179,13 +185,6 @@ export class MetricsListener {
179185
logError("couldn't decrypt kms api key", error as Error);
180186
}
181187
}
182-
} else {
183-
const errorMessage = "api key not configured, see https://dtdg.co/sls-node-metrics";
184-
if (config.logForwarding || this.isAgentRunning) {
185-
logDebug(errorMessage);
186-
} else {
187-
logError(errorMessage);
188-
}
189188
}
190189
return "";
191190
}

0 commit comments

Comments
 (0)