applicationinsights
Advanced tools
Comparing version 0.15.18 to 0.15.19
@@ -10,2 +10,3 @@ "use strict"; | ||
var Util = require("./Util"); | ||
var Logging = require("./Logging"); | ||
var Client = (function () { | ||
@@ -24,2 +25,3 @@ /** | ||
this._sequenceNumber = 0; | ||
this._telemetryProcessors = []; | ||
var config = new Config(iKey); | ||
@@ -188,5 +190,23 @@ this.config = config; | ||
var envelope = this.getEnvelope(data, tagOverrides); | ||
this.channel.send(envelope); | ||
var accepted = this.runTelemetryProcessors(envelope); | ||
if (accepted) { | ||
this.channel.send(envelope); | ||
} | ||
}; | ||
/** | ||
* Adds telemetry processor to the collection. Telemetry processors will be called one by one | ||
* before telemetry item is pushed for sending and in the order they were added. | ||
* | ||
* @param telemetryProcessor function, takes Envelope, returns boolean | ||
*/ | ||
Client.prototype.addTelemetryProcessor = function (telemetryProcessor) { | ||
this._telemetryProcessors.push(telemetryProcessor); | ||
}; | ||
/* | ||
* Removes all telemetry processors | ||
*/ | ||
Client.prototype.clearTelemetryProcessors = function () { | ||
this._telemetryProcessors = []; | ||
}; | ||
/** | ||
* Parse an envelope sequence. | ||
@@ -198,4 +218,27 @@ */ | ||
}; | ||
Client.prototype.runTelemetryProcessors = function (envelope) { | ||
var accepted = true; | ||
var telemetryProcessorsCount = this._telemetryProcessors.length; | ||
if (telemetryProcessorsCount === 0) { | ||
return accepted; | ||
} | ||
for (var i = 0; i < telemetryProcessorsCount; ++i) { | ||
try { | ||
var processor = this._telemetryProcessors[i]; | ||
if (processor) { | ||
if (processor.apply(null, [envelope]) === false) { | ||
accepted = false; | ||
break; | ||
} | ||
} | ||
} | ||
catch (error) { | ||
accepted = false; | ||
Logging.warn("One of telemetry processors failed, telemetry item will not be sent.", error, envelope); | ||
} | ||
} | ||
return accepted; | ||
}; | ||
return Client; | ||
}()); | ||
module.exports = Client; |
@@ -38,3 +38,3 @@ ///<reference path="..\Declarations\node\node.d.ts" /> | ||
Context.prototype._loadDeviceContext = function () { | ||
this.tags[this.keys.deviceId] = "node"; | ||
this.tags[this.keys.deviceId] = ""; | ||
this.tags[this.keys.deviceMachineName] = os && os.hostname(); | ||
@@ -41,0 +41,0 @@ this.tags[this.keys.deviceOS] = os && os.type(); |
@@ -5,3 +5,3 @@ { | ||
"bugs": "https://github.com/Microsoft/ApplicationInsights-node.js/issues", | ||
"version": "0.15.18", | ||
"version": "0.15.19", | ||
"description": "Microsoft Application Insights module for Node.JS", | ||
@@ -27,6 +27,10 @@ "repository": { | ||
{ | ||
"name": "scsouthw", | ||
"email": "scsouthw@microsoft.com" | ||
"name": "kszostak", | ||
"email": "kszostak@microsoft.com" | ||
}, | ||
{ | ||
"name": "southwood", | ||
"url": "https://github.com/southwood" | ||
}, | ||
{ | ||
"name": "bogdanbe", | ||
@@ -33,0 +37,0 @@ "email": "bogdanbe@microsoft.com" |
@@ -63,2 +63,32 @@ # Application Insights for Node.js | ||
### Telemetry Processor | ||
```javascript | ||
public addTelemetryProcessor(telemetryProcessor: (envelope: ContractsModule.Contracts.Envelope) => boolean) | ||
``` | ||
Adds a telemetry processor to the collection. Telemetry processors will be called one by one, in the order they were added, before the telemetry item is pushed for sending. | ||
If one of the telemetry processors returns false then the telemetry item will not be sent. | ||
If one of the telemetry processors throws an error then the telemetry item will not be sent. | ||
**Example** | ||
Add the below code before you send any telemetry, it will remove stack trace information from any Exception reported by the SDK. | ||
```javascript | ||
appInsights.client.addTelemetryProcessor((envelope) => { | ||
if (envelope.data.baseType === "Microsoft.ApplicationInsights.ExceptionData") { | ||
var data = envelope.data.baseData; | ||
if (data.exceptions && data.exceptions.length > 0) { | ||
for(var i = 0; i < data.exceptions.length; i++) { | ||
var exception = data.exceptions[i]; | ||
exception.parsedStack = null; | ||
exception.hasFullStack = false; | ||
} | ||
} | ||
} | ||
return true; | ||
}); | ||
``` | ||
[Learn more about the telemetry API](https://azure.microsoft.com/documentation/articles/app-insights-api-custom-events-metrics/). | ||
@@ -65,0 +95,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93346
1927
189