Skip to content

Commit

Permalink
Add snippet injection Statsbeat signal (#950)
Browse files Browse the repository at this point in the history
* add snippet injection stats

* resolve comments

* addremovesnippetstats
  • Loading branch information
Karlie-777 authored May 4, 2022
1 parent 200bbe6 commit c74ae99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AutoCollection/WebSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import zlib = require("zlib");
import Logging = require("../Library/Logging");
import TelemetryClient = require("../Library/TelemetryClient");
import snippetInjectionHelper = require("../Library/SnippetInjectionHelper");
import Statsbeat = require("./Statsbeat");
import Constants = require("../Declarations/Constants");
import ConnectionStringParser = require("../Library/ConnectionStringParser");

class WebSnippet {
Expand All @@ -17,6 +19,7 @@ class WebSnippet {
private _isEnabled: boolean;
private _isInitialized: boolean;
private _isIkeyValid: boolean = true;
private _statsbeat: Statsbeat;


constructor(client: TelemetryClient) {
Expand All @@ -38,6 +41,8 @@ class WebSnippet {

//TODO: quick fix for bundle error, remove this when npm is published
WebSnippet._snippet = snippetInjectionHelper.webSnippet.replace("INSTRUMENTATION_KEY", defaultIkey);
this._statsbeat = client.getStatsbeat();


//TODO: replace the path with npm package exports
//NOTE: should use the following part when npm is enabled
Expand All @@ -63,7 +68,14 @@ class WebSnippet {
WebSnippet._snippet = snippetInjectionHelper.webSnippet.replace("INSTRUMENTATION_KEY", iKey);
}
if (this._isEnabled && !this._isInitialized && this._isIkeyValid) {
if (this._statsbeat) {
this._statsbeat.addFeature(Constants.StatsbeatFeature.WEB_SNIPPET);
}
this._initialize();
} else if (!this._isEnabled) {
if (this._statsbeat) {
this._statsbeat.removeFeature(Constants.StatsbeatFeature.WEB_SNIPPET);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Declarations/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export enum StatsbeatFeature {
NONE = 0,
DISK_RETRY = 1,
AAD_HANDLING = 2,
WEB_SNIPPET = 4,
}

export enum StatsbeatInstrumentation {
Expand Down

0 comments on commit c74ae99

Please sign in to comment.