Skip to content

Commit

Permalink
Adding context to custom metrics sent for Statsbeat (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg authored Oct 21, 2021
1 parent 66bdc31 commit 2584172
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions AutoCollection/Statsbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Statsbeat {

private _networkStatsbeatCollection: Array<Network.NetworkStatsbeat>;
private _sender: Sender;
private _context: Context;
private _handle: NodeJS.Timer | null;
private _longHandle: NodeJS.Timer | null;
private _isEnabled: boolean;
Expand All @@ -42,11 +43,12 @@ class Statsbeat {
private _feature: number = Constants.StatsbeatFeature.NONE;
private _instrumentation: number = Constants.StatsbeatInstrumentation.NONE;

constructor(config: Config) {
constructor(config: Config, context?: Context) {
this._isInitialized = false;
this._statbeatMetrics = [];
this._networkStatsbeatCollection = [];
this._config = config;
this._context = context || new Context();
this._statsbeatConfig = new Config(Statsbeat.CONNECTION_STRING);
this._sender = new Sender(this._statsbeatConfig);
}
Expand Down Expand Up @@ -270,7 +272,7 @@ class Statsbeat {
value: this._statbeatMetrics[i].value,
properties: this._statbeatMetrics[i].properties
};
let envelope = EnvelopeFactory.createEnvelope(statsbeat, Contracts.TelemetryType.Metric, null, null, this._statsbeatConfig);
let envelope = EnvelopeFactory.createEnvelope(statsbeat, Contracts.TelemetryType.Metric, null, this._context, this._statsbeatConfig);
envelope.name = Constants.StatsbeatTelemetryName;
envelopes.push(envelope);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/TelemetryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TelemetryClient {
this.commonProperties = {};
this.authorizationHandler = null;
if (!process.env["APPLICATION_INSIGHTS_NO_STATSBEAT"]) {
this._statsbeat = new Statsbeat(this.config);
this._statsbeat = new Statsbeat(this.config, this.context);
this._statsbeat.enable(true);
}
var sender = new Sender(this.config, this.getAuthorizationHandler, null, null, this._statsbeat);
Expand Down

0 comments on commit 2584172

Please sign in to comment.