Skip to content

Commit

Permalink
Statsbeat only send feature metrics when available (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg authored Oct 21, 2021
1 parent 2584172 commit 06e25bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions AutoCollection/Statsbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ class Statsbeat {
"rpId": this._resourceIdentifier,
}, commonProperties);
this._statbeatMetrics.push({ name: Constants.StatsbeatCounter.ATTACH, value: 1, properties: attachProperties });
let featureProperties = Object.assign({ "feature": this._feature, "type": Constants.StatsbeatFeatureType.Feature }, commonProperties);
let instrumentationProperties = Object.assign({ "feature": this._instrumentation, "type": Constants.StatsbeatFeatureType.Instrumentation }, commonProperties);
this._statbeatMetrics.push({ name: Constants.StatsbeatCounter.FEATURE, value: 1, properties: instrumentationProperties });
this._statbeatMetrics.push({ name: Constants.StatsbeatCounter.FEATURE, value: 1, properties: featureProperties });
if (this._instrumentation != Constants.StatsbeatInstrumentation.NONE) {// Only send if there are some instrumentations enabled
let instrumentationProperties = Object.assign({ "feature": this._instrumentation, "type": Constants.StatsbeatFeatureType.Instrumentation }, commonProperties);
this._statbeatMetrics.push({ name: Constants.StatsbeatCounter.FEATURE, value: 1, properties: instrumentationProperties });
}
if (this._feature != Constants.StatsbeatFeature.NONE) {// Only send if there are some features enabled
let featureProperties = Object.assign({ "feature": this._feature, "type": Constants.StatsbeatFeatureType.Feature }, commonProperties);
this._statbeatMetrics.push({ name: Constants.StatsbeatCounter.FEATURE, value: 1, properties: featureProperties });
}
await this._sendStatsbeats();
});
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AutoCollection/Statsbeat.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("AutoCollection/Statsbeat", () => {
statsBeat.addFeature(Constants.StatsbeatFeature.DISK_RETRY);
const spy = sandbox.spy(statsBeat["_sender"], "send");
setImmediate(() => {
let envelope = spy.args[0][0][2];
let envelope = spy.args[0][0][1];
let baseData: Contracts.MetricData = envelope.data.baseData;
assert.equal(baseData.metrics[0].name, "Feature");
assert.equal(baseData.metrics[0].value, 1);
Expand Down

0 comments on commit 06e25bf

Please sign in to comment.