@ms-cloudpack/telemetry 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AppInsights/AppInsightsTelemetryClient.d.ts +4 -4
- package/lib/AppInsights/AppInsightsTelemetryClient.d.ts.map +1 -1
- package/lib/AppInsights/AppInsightsTelemetryClient.js +13 -16
- package/lib/AppInsights/AppInsightsTelemetryClient.js.map +1 -1
- package/lib/AppInsights/getAppInsightsConfig.d.ts +2 -2
- package/lib/AppInsights/getAppInsightsConfig.d.ts.map +1 -1
- package/lib/AppInsights/getAppInsightsConfig.js +16 -32
- package/lib/AppInsights/getAppInsightsConfig.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { TelemetryOptions } from '../types/TelemetryOptions.js';
|
|
3
|
-
import type { TelemetryClient } from '../types/TelemetryClient.js';
|
|
1
|
+
import { type Span, type Tracer } from '@opentelemetry/api';
|
|
4
2
|
import { PerformanceRecorder } from '../PerformanceRecorder.js';
|
|
3
|
+
import type { TelemetryClient } from '../types/TelemetryClient.js';
|
|
4
|
+
import type { TelemetryOptions } from '../types/TelemetryOptions.js';
|
|
5
5
|
export declare class AppInsightsTelemetryClient implements TelemetryClient {
|
|
6
6
|
private readonly _performance;
|
|
7
7
|
private readonly _rootSpan;
|
|
8
|
-
private readonly appInsightsClient;
|
|
9
8
|
private readonly sharedSpanAttributes;
|
|
9
|
+
private readonly _traceProvider;
|
|
10
10
|
constructor(options: TelemetryOptions);
|
|
11
11
|
get performance(): PerformanceRecorder;
|
|
12
12
|
get rootSpan(): Span;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppInsightsTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AppInsightsTelemetryClient.d.ts","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIrE,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8B;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;gBAExC,OAAO,EAAE,gBAAgB;IAoBrC,IAAW,WAAW,IAAI,mBAAmB,CAE5C;IAED,IAAW,QAAQ,IAAI,IAAI,CAE1B;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIxD;;OAEG;IACU,QAAQ;IAMrB;;;OAGG;IACI,SAAS,IAAI,MAAM;CAG3B"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getAppInsightsConfig } from './getAppInsightsConfig.js';
|
|
4
|
-
import { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';
|
|
1
|
+
import { shutdownAzureMonitor, useAzureMonitor } from '@azure/monitor-opentelemetry';
|
|
2
|
+
import { trace } from '@opentelemetry/api';
|
|
5
3
|
import { PerformanceRecorder } from '../PerformanceRecorder.js';
|
|
4
|
+
import { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';
|
|
5
|
+
import { getAppInsightsConfig } from './getAppInsightsConfig.js';
|
|
6
6
|
export class AppInsightsTelemetryClient {
|
|
7
7
|
constructor(options) {
|
|
8
8
|
this.sharedSpanAttributes = {};
|
|
9
9
|
const config = getAppInsightsConfig(options);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// Set up azure monitor (aka application insights)
|
|
11
|
+
useAzureMonitor(config);
|
|
12
|
+
this._traceProvider = trace.getTracerProvider().getDelegate();
|
|
12
13
|
// Set shared attributes
|
|
13
14
|
this.setSharedSpanAttribute('version', options.productVersion);
|
|
14
15
|
// Set SpanEnrichingProcessor to add shared attributes to all spans
|
|
15
|
-
|
|
16
|
-
nodeTraceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));
|
|
16
|
+
this._traceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));
|
|
17
17
|
// Create root span
|
|
18
|
-
this._rootSpan = this.
|
|
19
|
-
.getTraceHandler()
|
|
20
|
-
.getTracer()
|
|
21
|
-
.startSpan(options.rootSpanName || 'root');
|
|
18
|
+
this._rootSpan = this.getTracer().startSpan(options.rootSpanName || 'root');
|
|
22
19
|
this._performance = new PerformanceRecorder(this._rootSpan);
|
|
23
20
|
}
|
|
24
21
|
get performance() {
|
|
@@ -39,16 +36,16 @@ export class AppInsightsTelemetryClient {
|
|
|
39
36
|
* Flushes all telemetry and shuts down the telemetry client.
|
|
40
37
|
*/
|
|
41
38
|
async shutdown() {
|
|
42
|
-
this.
|
|
43
|
-
await this.
|
|
44
|
-
|
|
39
|
+
this.rootSpan.end();
|
|
40
|
+
await this._traceProvider.forceFlush();
|
|
41
|
+
shutdownAzureMonitor();
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
44
|
* Gets the OpenTelemetry tracer.
|
|
48
45
|
* @returns the OpenTelemetry tracer
|
|
49
46
|
*/
|
|
50
47
|
getTracer() {
|
|
51
|
-
return
|
|
48
|
+
return trace.getTracer('cloudpack-tracer');
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
//# sourceMappingURL=AppInsightsTelemetryClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppInsightsTelemetryClient.js","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AppInsightsTelemetryClient.js","sourceRoot":"","sources":["../../src/AppInsights/AppInsightsTelemetryClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,KAAK,EAAoD,MAAM,oBAAoB,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,OAAO,0BAA0B;IAMrC,YAAY,OAAyB;QAHpB,yBAAoB,GAA2B,EAAE,CAAC;QAIjE,MAAM,MAAM,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE7C,kDAAkD;QAClD,eAAe,CAAC,MAAM,CAAC,CAAC;QAExB,IAAI,CAAC,cAAc,GAAI,KAAK,CAAC,iBAAiB,EAA0B,CAAC,WAAW,EAAwB,CAAC;QAE7G,wBAAwB;QACxB,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QAE/D,mEAAmE;QACnE,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,sBAAsB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAElG,mBAAmB;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC;QAE5E,IAAI,CAAC,YAAY,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,sBAAsB,CAAC,GAAW,EAAE,KAAa;QACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACpB,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QACvC,oBAAoB,EAAE,CAAC;IACzB,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,KAAK,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import { shutdownAzureMonitor, useAzureMonitor } from '@azure/monitor-opentelemetry';\nimport { trace, type ProxyTracerProvider, type Span, type Tracer } from '@opentelemetry/api';\nimport type { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\nimport { PerformanceRecorder } from '../PerformanceRecorder.js';\nimport type { TelemetryClient } from '../types/TelemetryClient.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\nimport { SpanEnrichingProcessor } from './SpanEnrichingProcessor.js';\nimport { getAppInsightsConfig } from './getAppInsightsConfig.js';\n\nexport class AppInsightsTelemetryClient implements TelemetryClient {\n private readonly _performance: PerformanceRecorder;\n private readonly _rootSpan: Span;\n private readonly sharedSpanAttributes: Record<string, string> = {};\n private readonly _traceProvider: NodeTracerProvider;\n\n constructor(options: TelemetryOptions) {\n const config = getAppInsightsConfig(options);\n\n // Set up azure monitor (aka application insights)\n useAzureMonitor(config);\n\n this._traceProvider = (trace.getTracerProvider() as ProxyTracerProvider).getDelegate() as NodeTracerProvider;\n\n // Set shared attributes\n this.setSharedSpanAttribute('version', options.productVersion);\n\n // Set SpanEnrichingProcessor to add shared attributes to all spans\n this._traceProvider.addSpanProcessor(new SpanEnrichingProcessor(() => this.sharedSpanAttributes));\n\n // Create root span\n this._rootSpan = this.getTracer().startSpan(options.rootSpanName || 'root');\n\n this._performance = new PerformanceRecorder(this._rootSpan);\n }\n\n public get performance(): PerformanceRecorder {\n return this._performance;\n }\n\n public get rootSpan(): Span {\n return this._rootSpan;\n }\n\n /**\n * Sets a shared attribute that will be added to all spans.\n * @param key - key of the attribute\n * @param value - value of the attribute\n */\n public setSharedSpanAttribute(key: string, value: string) {\n this.sharedSpanAttributes[key] = value;\n }\n\n /**\n * Flushes all telemetry and shuts down the telemetry client.\n */\n public async shutdown() {\n this.rootSpan.end();\n await this._traceProvider.forceFlush();\n shutdownAzureMonitor();\n }\n\n /**\n * Gets the OpenTelemetry tracer.\n * @returns the OpenTelemetry tracer\n */\n public getTracer(): Tracer {\n return trace.getTracer('cloudpack-tracer');\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
|
|
2
2
|
import type { TelemetryOptions } from '../types/TelemetryOptions.js';
|
|
3
|
-
export declare function getAppInsightsConfig(options: TelemetryOptions):
|
|
3
|
+
export declare function getAppInsightsConfig(options: TelemetryOptions): AzureMonitorOpenTelemetryOptions;
|
|
4
4
|
//# sourceMappingURL=getAppInsightsConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAppInsightsConfig.d.ts","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getAppInsightsConfig.d.ts","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAGrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AASrE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,oCAuB7D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Resources from '@opentelemetry/resources';
|
|
2
2
|
import SemanticConventions from '@opentelemetry/semantic-conventions';
|
|
3
|
-
import { ApplicationInsightsConfig } from 'applicationinsights';
|
|
4
3
|
import { createHash } from 'crypto';
|
|
5
4
|
import { getComputerName } from './getComputerName.js';
|
|
6
5
|
const { Resource } = Resources;
|
|
@@ -9,40 +8,25 @@ function sha256(input) {
|
|
|
9
8
|
return createHash('sha256').update(input).digest('hex');
|
|
10
9
|
}
|
|
11
10
|
export function getAppInsightsConfig(options) {
|
|
12
|
-
const config =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
connectionString: `InstrumentationKey=${options.instrumentationKey}`,
|
|
16
|
-
};
|
|
17
|
-
config.enableAutoCollectExceptions = false;
|
|
18
|
-
config.enableAutoCollectHeartbeat = false;
|
|
19
|
-
config.enableAutoCollectPerformance = false;
|
|
20
|
-
config.enableAutoCollectStandardMetrics = false;
|
|
21
|
-
config.instrumentations = {
|
|
22
|
-
http: {
|
|
23
|
-
enabled: false,
|
|
24
|
-
},
|
|
25
|
-
azureSdk: {
|
|
26
|
-
enabled: false,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
config.logInstrumentations = {
|
|
30
|
-
bunyan: {
|
|
31
|
-
enabled: false,
|
|
32
|
-
},
|
|
33
|
-
console: {
|
|
34
|
-
enabled: false,
|
|
11
|
+
const config = {
|
|
12
|
+
azureMonitorExporterOptions: {
|
|
13
|
+
connectionString: 'InstrumentationKey=d512a3ac-e644-47b8-895a-4a9a25778aaf;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com',
|
|
35
14
|
},
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
instrumentationOptions: {
|
|
16
|
+
http: {
|
|
17
|
+
enabled: false,
|
|
18
|
+
},
|
|
19
|
+
azureSdk: {
|
|
20
|
+
enabled: false,
|
|
21
|
+
},
|
|
38
22
|
},
|
|
23
|
+
resource: new Resource({
|
|
24
|
+
// Use a hash of the computer name to avoid PII
|
|
25
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),
|
|
26
|
+
[SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,
|
|
27
|
+
[SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,
|
|
28
|
+
}),
|
|
39
29
|
};
|
|
40
|
-
config.resource = new Resource({
|
|
41
|
-
// Use a hash of the computer name to avoid PII
|
|
42
|
-
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),
|
|
43
|
-
[SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,
|
|
44
|
-
[SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,
|
|
45
|
-
});
|
|
46
30
|
return config;
|
|
47
31
|
}
|
|
48
32
|
//# sourceMappingURL=getAppInsightsConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAppInsightsConfig.js","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,0BAA0B,CAAC;AACjD,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"getAppInsightsConfig.js","sourceRoot":"","sources":["../../src/AppInsights/getAppInsightsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,0BAA0B,CAAC;AACjD,OAAO,mBAAmB,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;AAC/B,MAAM,EAAE,0BAA0B,EAAE,GAAG,mBAAmB,CAAC;AAE3D,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,MAAM,GAAqC;QAC/C,2BAA2B,EAAE;YAC3B,gBAAgB,EACd,6HAA6H;SAChI;QACD,sBAAsB,EAAE;YACtB,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;aACf;YACD,QAAQ,EAAE;gBACR,OAAO,EAAE,KAAK;aACf;SACF;QACD,QAAQ,EAAE,IAAI,QAAQ,CAAC;YACrB,+CAA+C;YAC/C,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;YAC3E,CAAC,0BAA0B,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,WAAW;YAC9D,CAAC,0BAA0B,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,gBAAgB;SACzE,CAAC;KACH,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import Resources from '@opentelemetry/resources';\nimport SemanticConventions from '@opentelemetry/semantic-conventions';\nimport type { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';\nimport { createHash } from 'crypto';\nimport { getComputerName } from './getComputerName.js';\nimport type { TelemetryOptions } from '../types/TelemetryOptions.js';\n\nconst { Resource } = Resources;\nconst { SemanticResourceAttributes } = SemanticConventions;\n\nfunction sha256(input: string) {\n return createHash('sha256').update(input).digest('hex');\n}\n\nexport function getAppInsightsConfig(options: TelemetryOptions) {\n const config: AzureMonitorOpenTelemetryOptions = {\n azureMonitorExporterOptions: {\n connectionString:\n 'InstrumentationKey=d512a3ac-e644-47b8-895a-4a9a25778aaf;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com',\n },\n instrumentationOptions: {\n http: {\n enabled: false,\n },\n azureSdk: {\n enabled: false,\n },\n },\n resource: new Resource({\n // Use a hash of the computer name to avoid PII\n [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: sha256(getComputerName()),\n [SemanticResourceAttributes.SERVICE_NAME]: options.serviceName,\n [SemanticResourceAttributes.SERVICE_NAMESPACE]: options.serviceNamespace,\n }),\n };\n\n return config;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/telemetry",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Helpers for logging tasks to the console.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@opentelemetry
|
|
17
|
-
"@opentelemetry/
|
|
18
|
-
"@opentelemetry/
|
|
19
|
-
"@opentelemetry/sdk-trace-
|
|
20
|
-
"@opentelemetry/
|
|
21
|
-
"
|
|
16
|
+
"@azure/monitor-opentelemetry": "^1.0.0",
|
|
17
|
+
"@opentelemetry/api": "^1.6.0",
|
|
18
|
+
"@opentelemetry/resources": "^1.17.0",
|
|
19
|
+
"@opentelemetry/sdk-trace-base": "^1.17.0",
|
|
20
|
+
"@opentelemetry/sdk-trace-node": "^1.17.0",
|
|
21
|
+
"@opentelemetry/semantic-conventions": "^1.17.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@ms-cloudpack/eslint-plugin-internal": "*",
|