Repository: microsoft/ApplicationInsights-node.js
Pull request #554 (2019-10-09 16:28:50)

feat: Allow to specify severityLevel when tracking Exception

msftclas: [![CLA assistant check](https://cla.opensource.microsoft.com/pull/badge/not_signed)](https://cla.opensource.microsoft.com/microsoft/ApplicationInsights-node.js?pullRequest=554) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/ApplicationInsights-node.js?pullRequest=554) before we can accept your contribution.<br/><br/>:x: Socolin [sign now](https://cla.opensource.microsoft.com/microsoft/ApplicationInsights-node.js?pullRequest=554)<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla.opensource.microsoft.com/check/microsoft/ApplicationInsights-node.js?pullRequest=554) it.</sub>
Socolin: I've updated my commit

Patch:
diff --git a/Declarations/Contracts/TelemetryTypes/ExceptionTelemetry.ts b/Declarations/Contracts/TelemetryTypes/ExceptionTelemetry.ts
index ac58141..c721f83 100644
--- a/Declarations/Contracts/TelemetryTypes/ExceptionTelemetry.ts
+++ b/Declarations/Contracts/TelemetryTypes/ExceptionTelemetry.ts
@@ -1,4 +1,5 @@
 import { Telemetry }  from "./Telemetry";
+import Contracts = require("../");
 
 /**
  * Telemetry about the exception thrown by the application
@@ -14,4 +15,8 @@ export interface ExceptionTelemetry extends Telemetry
      * Metrics associated with this exception, displayed in Metrics Explorer on the portal. Defaults to empty
      */
     measurements?: { [key: string]: number; };
+    /**
+     * Exception severity level
+     */
+    severity?: Contracts.SeverityLevel;
 }
\ No newline at end of file
diff --git a/Library/EnvelopeFactory.ts b/Library/EnvelopeFactory.ts
index 46172c5..04f8358 100644
--- a/Library/EnvelopeFactory.ts
+++ b/Library/EnvelopeFactory.ts
@@ -149,7 +149,11 @@ class EnvelopeFactory {
     private static createExceptionData(telemetry: Contracts.ExceptionTelemetry): Contracts.Data<Contracts.ExceptionData> {
         var exception = new Contracts.ExceptionData();
         exception.properties = telemetry.properties;
-        exception.severityLevel = Contracts.SeverityLevel.Error;
+        if (!isNaN(telemetry.severity)) {
+            exception.severityLevel = telemetry.severity;
+        } else {
+            exception.severityLevel = Contracts.SeverityLevel.Error;
+        }
         exception.measurements = telemetry.measurements;
         exception.exceptions = [];
 


Test patch:
diff --git a/Tests/Library/EnvelopeFactoryTests.ts b/Tests/Library/EnvelopeFactoryTests.ts
index 6bfa182..b0c9932 100644
--- a/Tests/Library/EnvelopeFactoryTests.ts
+++ b/Tests/Library/EnvelopeFactoryTests.ts
@@ -90,5 +90,25 @@ describe("Library/EnvelopeFactory", () => {
 
             assert.deepEqual(actual, expected);
         });
+
+        it("fills 'severityLevel' with Error when not specified", () => {
+            var envelope = EnvelopeFactory.createEnvelope(<Contracts.ExceptionTelemetry>{ exception: simpleError }, Contracts.TelemetryType.Exception);
+            var exceptionData = <Contracts.Data<Contracts.ExceptionData>>envelope.data;
+
+            var actual = exceptionData.baseData.severityLevel;
+            var expected = Contracts.SeverityLevel.Error;
+
+            assert.deepEqual(actual, expected);
+        });
+
+        it("fills 'severityLevel' with the given value when specified", () => {
+            var envelope = EnvelopeFactory.createEnvelope(<Contracts.ExceptionTelemetry>{ exception: simpleError, severity: Contracts.SeverityLevel.Warning }, Contracts.TelemetryType.Exception);
+            var exceptionData = <Contracts.Data<Contracts.ExceptionData>>envelope.data;
+
+            var actual = exceptionData.baseData.severityLevel;
+            var expected = Contracts.SeverityLevel.Warning;
+
+            assert.deepEqual(actual, expected);
+        });
     });
 });