first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,6 @@
import Contracts = require("../Declarations/Contracts");
import Context = require("../Library/Context");
/**
* A telemetry processor that handles Azure specific variables.
*/
export declare function azureRoleEnvironmentTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, context: Context): void;
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A telemetry processor that handles Azure specific variables.
*/
function azureRoleEnvironmentTelemetryProcessor(envelope, context) {
if (process.env.WEBSITE_SITE_NAME) {
envelope.tags[context.keys.cloudRole] = process.env.WEBSITE_SITE_NAME;
}
}
exports.azureRoleEnvironmentTelemetryProcessor = azureRoleEnvironmentTelemetryProcessor;
//# sourceMappingURL=AzureRoleEnvironmentTelemetryInitializer.js.map
@@ -0,0 +1 @@
{"version":3,"file":"AzureRoleEnvironmentTelemetryInitializer.js","sourceRoot":"","sources":["../../TelemetryProcessors/AzureRoleEnvironmentTelemetryInitializer.ts"],"names":[],"mappings":";;AAGA;;GAEG;AACH,gDAAuD,QAAqC,EAAE,OAAgB;IAC1G,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAC1E,CAAC;AACL,CAAC;AAJD,wFAIC","sourcesContent":["import Contracts = require(\"../Declarations/Contracts\");\r\nimport Context = require(\"../Library/Context\");\r\n\r\n/**\r\n * A telemetry processor that handles Azure specific variables.\r\n */\r\nexport function azureRoleEnvironmentTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, context: Context): void {\r\n if (process.env.WEBSITE_SITE_NAME) { // Azure Web apps and Functions\r\n envelope.tags[context.keys.cloudRole] = process.env.WEBSITE_SITE_NAME;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,3 @@
import Contracts = require("../Declarations/Contracts");
import QuickPulseStateManager = require("../Library/QuickPulseStateManager");
export declare function performanceMetricsTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, client?: QuickPulseStateManager): boolean;
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var AutoCollectPerformance = require("../AutoCollection/Performance");
var TelemetryType = require("../Declarations/Contracts");
function performanceMetricsTelemetryProcessor(envelope, client) {
// If live metrics is enabled, forward all telemetry there
if (client) {
client.addDocument(envelope);
}
// Increment rate counters (for standard metrics and live metrics)
switch (envelope.data.baseType) {
case TelemetryType.TelemetryTypeString.Exception:
AutoCollectPerformance.countException();
break;
case TelemetryType.TelemetryTypeString.Request:
var requestData = envelope.data.baseData;
AutoCollectPerformance.countRequest(requestData.duration, requestData.success);
break;
case TelemetryType.TelemetryTypeString.Dependency:
var remoteDependencyData = envelope.data.baseData;
AutoCollectPerformance.countDependency(remoteDependencyData.duration, remoteDependencyData.success);
break;
}
return true;
}
exports.performanceMetricsTelemetryProcessor = performanceMetricsTelemetryProcessor;
//# sourceMappingURL=PerformanceMetricsTelemetryProcessor.js.map
@@ -0,0 +1 @@
{"version":3,"file":"PerformanceMetricsTelemetryProcessor.js","sourceRoot":"","sources":["../../TelemetryProcessors/PerformanceMetricsTelemetryProcessor.ts"],"names":[],"mappings":";;AAGA,sEAAyE;AACzE,yDAA2D;AAE3D,8CAAqD,QAAqC,EAAE,MAA+B;IACvH,0DAA0D;IAC1D,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,kEAAkE;IAClE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC7B,KAAK,aAAa,CAAC,mBAAmB,CAAC,SAAS;YAC5C,sBAAsB,CAAC,cAAc,EAAE,CAAC;YACxC,KAAK,CAAC;QACV,KAAK,aAAa,CAAC,mBAAmB,CAAC,OAAO;YAC1C,IAAM,WAAW,GAA2B,QAAQ,CAAC,IAAY,CAAC,QAAQ,CAAC;YAC3E,sBAAsB,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;YAC/E,KAAK,CAAC;QACV,KAAK,aAAa,CAAC,mBAAmB,CAAC,UAAU;YAC7C,IAAM,oBAAoB,GAAoC,QAAQ,CAAC,IAAY,CAAC,QAAQ,CAAC;YAC7F,sBAAsB,CAAC,eAAe,CAAC,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;YACpG,KAAK,CAAC;IACd,CAAC;IACD,MAAM,CAAC,IAAI,CAAC;AAChB,CAAC;AArBD,oFAqBC","sourcesContent":["import Contracts = require(\"../Declarations/Contracts\");\r\nimport Logging = require(\"../Library/Logging\");\r\nimport QuickPulseStateManager = require(\"../Library/QuickPulseStateManager\")\r\nimport AutoCollectPerformance = require(\"../AutoCollection/Performance\");\r\nimport * as TelemetryType from \"../Declarations/Contracts\";\r\n\r\nexport function performanceMetricsTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, client?: QuickPulseStateManager): boolean {\r\n // If live metrics is enabled, forward all telemetry there\r\n if (client) {\r\n client.addDocument(envelope);\r\n }\r\n\r\n // Increment rate counters (for standard metrics and live metrics)\r\n switch (envelope.data.baseType) {\r\n case TelemetryType.TelemetryTypeString.Exception:\r\n AutoCollectPerformance.countException();\r\n break;\r\n case TelemetryType.TelemetryTypeString.Request:\r\n const requestData: Contracts.RequestData = (envelope.data as any).baseData;\r\n AutoCollectPerformance.countRequest(requestData.duration, requestData.success);\r\n break;\r\n case TelemetryType.TelemetryTypeString.Dependency:\r\n const remoteDependencyData: Contracts.RemoteDependencyData = (envelope.data as any).baseData;\r\n AutoCollectPerformance.countDependency(remoteDependencyData.duration, remoteDependencyData.success);\r\n break;\r\n }\r\n return true;\r\n}\r\n"]}
@@ -0,0 +1,10 @@
import Contracts = require("../Declarations/Contracts");
import { CorrelationContext } from "../AutoCollection/CorrelationContextManager";
/**
* A telemetry processor that handles sampling.
*/
export declare function samplingTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, contextObjects: {
correlationContext: CorrelationContext;
}): boolean;
/** Ported from AI .NET SDK */
export declare function getSamplingHashCode(input: string): number;
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Contracts = require("../Declarations/Contracts");
/**
* A telemetry processor that handles sampling.
*/
function samplingTelemetryProcessor(envelope, contextObjects) {
var samplingPercentage = envelope.sampleRate; // Set for us in Client.getEnvelope
var isSampledIn = false;
if (samplingPercentage === null || samplingPercentage === undefined || samplingPercentage >= 100) {
return true;
}
else if (envelope.data && Contracts.TelemetryType.Metric === Contracts.baseTypeToTelemetryType(envelope.data.baseType)) {
// Exclude MetricData telemetry from sampling
return true;
}
else if (contextObjects.correlationContext && contextObjects.correlationContext.operation) {
// If we're using dependency correlation, sampling should retain all telemetry from a given request
isSampledIn = getSamplingHashCode(contextObjects.correlationContext.operation.id) < samplingPercentage;
}
else {
// If we're not using dependency correlation, sampling should use a random distribution on each item
isSampledIn = (Math.random() * 100) < samplingPercentage;
}
return isSampledIn;
}
exports.samplingTelemetryProcessor = samplingTelemetryProcessor;
/** Ported from AI .NET SDK */
function getSamplingHashCode(input) {
var csharpMin = -2147483648;
var csharpMax = 2147483647;
var hash = 5381;
if (!input) {
return 0;
}
while (input.length < 8) {
input = input + input;
}
for (var i = 0; i < input.length; i++) {
// JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)
hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i) | 0);
}
hash = hash <= csharpMin ? csharpMax : Math.abs(hash);
return (hash / csharpMax) * 100;
}
exports.getSamplingHashCode = getSamplingHashCode;
//# sourceMappingURL=SamplingTelemetryProcessor.js.map
@@ -0,0 +1 @@
{"version":3,"file":"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AI,CAAC;IAEhB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,CAAC,CAAC;IACb,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,uGAAuG;QACvG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,GAAG,IAAI,IAAI,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC;AACpC,CAAC;AApBD,kDAoBC","sourcesContent":["import Contracts = require(\"../Declarations/Contracts\");\r\nimport { CorrelationContext } from \"../AutoCollection/CorrelationContextManager\";\r\n\r\n/**\r\n * A telemetry processor that handles sampling.\r\n */\r\nexport function samplingTelemetryProcessor(envelope: Contracts.EnvelopeTelemetry, contextObjects: { correlationContext: CorrelationContext }): boolean {\r\n var samplingPercentage = envelope.sampleRate; // Set for us in Client.getEnvelope\r\n var isSampledIn = false;\r\n\r\n if (samplingPercentage === null || samplingPercentage === undefined || samplingPercentage >= 100) {\r\n return true;\r\n } else if (envelope.data && Contracts.TelemetryType.Metric === Contracts.baseTypeToTelemetryType(envelope.data.baseType as Contracts.TelemetryTypeValues)) {\r\n // Exclude MetricData telemetry from sampling\r\n return true;\r\n } else if (contextObjects.correlationContext && contextObjects.correlationContext.operation) {\r\n // If we're using dependency correlation, sampling should retain all telemetry from a given request\r\n isSampledIn = getSamplingHashCode(contextObjects.correlationContext.operation.id) < samplingPercentage;\r\n } else {\r\n // If we're not using dependency correlation, sampling should use a random distribution on each item\r\n isSampledIn = (Math.random() * 100) < samplingPercentage;\r\n }\r\n\r\n return isSampledIn;\r\n}\r\n\r\n/** Ported from AI .NET SDK */\r\nexport function getSamplingHashCode(input: string): number {\r\n var csharpMin = -2147483648;\r\n var csharpMax = 2147483647;\r\n var hash = 5381;\r\n\r\n if (!input) {\r\n return 0;\r\n }\r\n\r\n while (input.length < 8) {\r\n input = input + input;\r\n }\r\n\r\n for (var i = 0; i < input.length; i++) {\r\n // JS doesn't respond to integer overflow by wrapping around. Simulate it with bitwise operators ( | 0)\r\n hash = ((((hash << 5) + hash) | 0) + input.charCodeAt(i) | 0);\r\n }\r\n\r\n hash = hash <= csharpMin ? csharpMax : Math.abs(hash);\r\n return (hash / csharpMax) * 100;\r\n}"]}
+3
View File
@@ -0,0 +1,3 @@
export * from "./AzureRoleEnvironmentTelemetryInitializer";
export * from "./SamplingTelemetryProcessor";
export * from "./PerformanceMetricsTelemetryProcessor";
+9
View File
@@ -0,0 +1,9 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./AzureRoleEnvironmentTelemetryInitializer"));
__export(require("./SamplingTelemetryProcessor"));
__export(require("./PerformanceMetricsTelemetryProcessor"));
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../TelemetryProcessors/index.ts"],"names":[],"mappings":";;;;;AAAA,gEAA2D;AAC3D,kDAA6C;AAC7C,4DAAuD","sourcesContent":["export * from \"./AzureRoleEnvironmentTelemetryInitializer\";\r\nexport * from \"./SamplingTelemetryProcessor\";\r\nexport * from \"./PerformanceMetricsTelemetryProcessor\";\r\n"]}