Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fix: flag type when passing data to child process
Browse files Browse the repository at this point in the history
  • Loading branch information
jgellin-sf committed Jan 10, 2020
1 parent 1bd097e commit 0e5204b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
27 changes: 18 additions & 9 deletions packages/telemetry/src/telemetryChildProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ import { TelemetryReporter } from './telemetryReporter';
const args = process.argv.slice(2);
const options = JSON.parse(args[0]);
const reporter = await TelemetryReporter.create(options);
process.on('message', event => {
if (event.eventName) {
reporter.sendTelemetryEvent(event.eventName, event.attributes);
} else if (event.exception) {
reporter.sendTelemetryException(event.exception, event.attributes);
} else if (event.traceMessage) {
reporter.sendTelemetryTrace(event.traceMessage, event.properties);
} else if (event.metricName) {
reporter.sendTelemetryMetric(event.metricName, event.value, event.properties);
process.on('message', telemetry => {
switch (telemetry.type) {
case 'event': {
reporter.sendTelemetryEvent(telemetry.eventName, telemetry.attributes);
break;
}
case 'exception': {
reporter.sendTelemetryException(telemetry.exception, telemetry.attributes);
break;
}
case 'metric': {
reporter.sendTelemetryMetric(telemetry.metricName, telemetry.value, telemetry.properties);
break;
}
case 'trace': {
reporter.sendTelemetryTrace(telemetry.traceMessage, telemetry.properties);
break;
}
}
});
})();
8 changes: 4 additions & 4 deletions packages/telemetry/src/telemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class SpawnedTelemetryReporter extends AsyncCreatable<TelemetryOptions> {
*/
public sendTelemetryEvent(eventName: string, attributes: Attributes = {}): void {
if (this.forkedProcess) {
this.forkedProcess.send({ eventName, attributes });
this.forkedProcess.send({ type: 'event', eventName, attributes });
}
}

Expand All @@ -251,7 +251,7 @@ export class SpawnedTelemetryReporter extends AsyncCreatable<TelemetryOptions> {
*/
public sendTelemetryException(exception: Error, attributes: Attributes = {}): void {
if (this.forkedProcess) {
this.forkedProcess.send({ exception, attributes });
this.forkedProcess.send({ type: 'exception', exception, attributes });
}
}

Expand All @@ -262,7 +262,7 @@ export class SpawnedTelemetryReporter extends AsyncCreatable<TelemetryOptions> {
*/
public sendTelemetryTrace(traceMessage: string, properties?: Properties): void {
if (this.forkedProcess) {
this.forkedProcess.send({ traceMessage, properties });
this.forkedProcess.send({ type: 'trace', traceMessage, properties });
}
}

Expand All @@ -274,7 +274,7 @@ export class SpawnedTelemetryReporter extends AsyncCreatable<TelemetryOptions> {
*/
public sendTelemetryMetric(metricName: string, value: number, properties?: Properties): void {
if (this.forkedProcess) {
this.forkedProcess.send({ metricName, value, properties });
this.forkedProcess.send({ type: 'metric', metricName, value, properties });
}
}

Expand Down

0 comments on commit 0e5204b

Please sign in to comment.