@azure/monitor-opentelemetry-exporter 1.0.0-beta.7 → 1.0.0-beta.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.
Files changed (42) hide show
  1. package/README.md +47 -9
  2. package/dist/index.js +656 -261
  3. package/dist-esm/src/config.js +1 -14
  4. package/dist-esm/src/config.js.map +1 -1
  5. package/dist-esm/src/export/base.js +174 -0
  6. package/dist-esm/src/export/base.js.map +1 -0
  7. package/dist-esm/src/export/metric.js +64 -0
  8. package/dist-esm/src/export/metric.js.map +1 -0
  9. package/dist-esm/src/export/trace.js +25 -146
  10. package/dist-esm/src/export/trace.js.map +1 -1
  11. package/dist-esm/src/generated/applicationInsightsClient.js +36 -3
  12. package/dist-esm/src/generated/applicationInsightsClient.js.map +1 -1
  13. package/dist-esm/src/generated/index.js +0 -1
  14. package/dist-esm/src/generated/index.js.map +1 -1
  15. package/dist-esm/src/generated/models/index.js +35 -0
  16. package/dist-esm/src/generated/models/index.js.map +1 -1
  17. package/dist-esm/src/index.js +3 -0
  18. package/dist-esm/src/index.js.map +1 -1
  19. package/dist-esm/src/platform/nodejs/httpSender.js +5 -8
  20. package/dist-esm/src/platform/nodejs/httpSender.js.map +1 -1
  21. package/dist-esm/src/platform/nodejs/persist/fileAccessControl.js.map +1 -1
  22. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js +2 -1
  23. package/dist-esm/src/platform/nodejs/persist/fileSystemHelpers.js.map +1 -1
  24. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js +10 -5
  25. package/dist-esm/src/platform/nodejs/persist/fileSystemPersist.js.map +1 -1
  26. package/dist-esm/src/sampling.js +81 -0
  27. package/dist-esm/src/sampling.js.map +1 -0
  28. package/dist-esm/src/utils/breezeUtils.js +3 -1
  29. package/dist-esm/src/utils/breezeUtils.js.map +1 -1
  30. package/dist-esm/src/utils/constants/applicationinsights.js +2 -1
  31. package/dist-esm/src/utils/constants/applicationinsights.js.map +1 -1
  32. package/dist-esm/src/utils/metricUtils.js +67 -0
  33. package/dist-esm/src/utils/metricUtils.js.map +1 -0
  34. package/dist-esm/src/utils/resourceUtils.js +35 -0
  35. package/dist-esm/src/utils/resourceUtils.js.map +1 -0
  36. package/dist-esm/src/utils/spanUtils.js +123 -44
  37. package/dist-esm/src/utils/spanUtils.js.map +1 -1
  38. package/package.json +20 -19
  39. package/types/monitor-opentelemetry-exporter.d.ts +181 -13
  40. package/CHANGELOG.md +0 -51
  41. package/dist-esm/src/generated/applicationInsightsClientContext.js +0 -34
  42. package/dist-esm/src/generated/applicationInsightsClientContext.js.map +0 -1
@@ -1,12 +1,102 @@
1
+ import { AggregationTemporality } from '@opentelemetry/sdk-metrics';
2
+ import { Attributes } from '@opentelemetry/api';
3
+ import { Context } from '@opentelemetry/api';
4
+ import * as coreClient from '@azure/core-client';
1
5
  import { ExportResult } from '@opentelemetry/core';
6
+ import { InstrumentType } from '@opentelemetry/sdk-metrics';
7
+ import { Link } from '@opentelemetry/api';
8
+ import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
2
9
  import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
10
+ import { ResourceMetrics } from '@opentelemetry/sdk-metrics';
11
+ import { Sampler } from '@opentelemetry/sdk-trace-base';
12
+ import { SamplingResult } from '@opentelemetry/sdk-trace-base';
3
13
  import { SpanExporter } from '@opentelemetry/sdk-trace-base';
4
- import { TokenCredential } from '@azure/core-http';
14
+ import { SpanKind } from '@opentelemetry/api';
15
+ import { TokenCredential } from '@azure/core-auth';
16
+
17
+ /** Optional parameters. */
18
+ export declare interface ApplicationInsightsClientOptionalParams extends coreClient.ServiceClientOptions {
19
+ /** Breeze endpoint: https://dc.services.visualstudio.com */
20
+ host?: string;
21
+ /** Overrides client endpoint. */
22
+ endpoint?: string;
23
+ }
24
+
25
+ /**
26
+ * ApplicationInsightsSampler is responsible for the following:
27
+ * Implements same trace id hashing algorithm so that traces are sampled the same across multiple nodes
28
+ * Adds item count to span attribute if span is sampled (needed for ingestion service)
29
+ * @param samplingRatio - 0 to 1 value.
30
+ */
31
+ export declare class ApplicationInsightsSampler implements Sampler {
32
+ private readonly _sampleRate;
33
+ private readonly _samplingRatio;
34
+ constructor(samplingRatio?: number);
35
+ /**
36
+ * Checks whether span needs to be created and tracked.
37
+ *
38
+ * @param context Parent Context which may contain a span.
39
+ * @param traceId of the span to be created. It can be different from the
40
+ * traceId in the {@link SpanContext}. Typically in situations when the
41
+ * span to be created starts a new trace.
42
+ * @param spanName of the span to be created.
43
+ * @param spanKind of the span to be created.
44
+ * @param attributes Initial set of SpanAttributes for the Span being constructed.
45
+ * @param links Collection of links that will be associated with the Span to
46
+ * be created. Typically useful for batch operations.
47
+ * @returns a {@link SamplingResult}.
48
+ */
49
+ shouldSample(context: Context, traceId: string, spanName: string, spanKind: SpanKind, attributes: Attributes, links: Link[]): SamplingResult;
50
+ /**
51
+ * Return Sampler description
52
+ */
53
+ toString(): string;
54
+ private _getSamplingHashCode;
55
+ }
56
+
57
+ /**
58
+ * Azure Monitor OpenTelemetry Trace Exporter.
59
+ */
60
+ export declare abstract class AzureMonitorBaseExporter {
61
+ /**
62
+ * Instrumentation key to be used for exported envelopes
63
+ */
64
+ protected _instrumentationKey: string;
65
+ private readonly _persister;
66
+ private readonly _sender;
67
+ private _numConsecutiveRedirects;
68
+ private _retryTimer;
69
+ private _endpointUrl;
70
+ private _batchSendRetryIntervalMs;
71
+ /**
72
+ * Exporter internal configuration
73
+ */
74
+ private readonly _options;
75
+ /**
76
+ * Initializes a new instance of the AzureMonitorBaseExporter class.
77
+ * @param AzureMonitorExporterOptions - Exporter configuration.
78
+ */
79
+ constructor(options?: AzureMonitorExporterOptions);
80
+ /**
81
+ * Persist envelopes to disk
82
+ */
83
+ private _persist;
84
+ /**
85
+ * Shutdown exporter
86
+ */
87
+ protected _shutdown(): Promise<void>;
88
+ /**
89
+ * Export envelopes
90
+ */
91
+ protected _exportEnvelopes(envelopes: TelemetryItem[]): Promise<ExportResult>;
92
+ private _sendFirstPersistedFile;
93
+ private _isNetworkError;
94
+ }
5
95
 
6
96
  /**
7
97
  * Provides configuration options for AzureMonitorTraceExporter.
8
98
  */
9
- export declare interface AzureExporterConfig {
99
+ export declare interface AzureMonitorExporterOptions extends ApplicationInsightsClientOptionalParams {
10
100
  /**
11
101
  * Azure Monitor Connection String, if not provided the exporter will try to use environment variable APPLICATIONINSIGHTS_CONNECTION_STRING
12
102
  * Ex: "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://dc.services.visualstudio.com"
@@ -20,24 +110,66 @@ export declare interface AzureExporterConfig {
20
110
  * Azure Active Directory Credential
21
111
  */
22
112
  aadTokenCredential?: TokenCredential;
113
+ /**
114
+ * Directory to store retriable telemetry when it fails to export.
115
+ */
116
+ storageDirectory?: string;
117
+ /**
118
+ * Disable offline storage when telemetry cannot be exported.
119
+ */
120
+ disableOfflineStorage?: boolean;
121
+ }
122
+
123
+ /**
124
+ * Azure Monitor OpenTelemetry Metric Exporter.
125
+ */
126
+ export declare class AzureMonitorMetricExporter extends AzureMonitorBaseExporter implements PushMetricExporter {
127
+ /**
128
+ * Flag to determine if Exporter is shutdown.
129
+ */
130
+ private _isShutdown;
131
+ /**
132
+ * Aggregation temporality.
133
+ */
134
+ private _aggregationTemporality;
135
+ /**
136
+ * Initializes a new instance of the AzureMonitorMetricExporter class.
137
+ * @param AzureExporterConfig - Exporter configuration.
138
+ */
139
+ constructor(options?: AzureMonitorExporterOptions);
140
+ /**
141
+ * Export OpenTelemetry resource metrics.
142
+ * @param metrics - Resource metrics to export.
143
+ * @param resultCallback - Result callback.
144
+ */
145
+ export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): Promise<void>;
146
+ /**
147
+ * Shutdown AzureMonitorMetricExporter.
148
+ */
149
+ shutdown(): Promise<void>;
150
+ /**
151
+ * Select aggregation temporality
152
+ */
153
+ selectAggregationTemporality(_instrumentType: InstrumentType): AggregationTemporality;
154
+ /**
155
+ * Force flush
156
+ */
157
+ forceFlush(): Promise<void>;
23
158
  }
24
159
 
25
160
  /**
26
161
  * Azure Monitor OpenTelemetry Trace Exporter.
27
162
  */
28
- export declare class AzureMonitorTraceExporter implements SpanExporter {
29
- private readonly _persister;
30
- private readonly _sender;
31
- private _numConsecutiveRedirects;
32
- private _retryTimer;
33
- private readonly _options;
163
+ export declare class AzureMonitorTraceExporter extends AzureMonitorBaseExporter implements SpanExporter {
164
+ /**
165
+ * Flag to determine if Exporter is shutdown.
166
+ */
167
+ private _isShutdown;
34
168
  /**
35
169
  * Initializes a new instance of the AzureMonitorTraceExporter class.
36
170
  * @param AzureExporterConfig - Exporter configuration.
37
171
  */
38
- constructor(options?: AzureExporterConfig);
39
- private _persist;
40
- private exportEnvelopes;
172
+ constructor(options?: AzureMonitorExporterOptions);
41
173
  /**
42
174
  * Export OpenTelemetry spans.
43
175
  * @param spans - Spans to export.
@@ -48,8 +180,22 @@ export declare class AzureMonitorTraceExporter implements SpanExporter {
48
180
  * Shutdown AzureMonitorTraceExporter.
49
181
  */
50
182
  shutdown(): Promise<void>;
51
- private _sendFirstPersistedFile;
52
- private _isNetworkError;
183
+ }
184
+
185
+ /** Data struct to contain only C section with custom fields. */
186
+ export declare interface MonitorBase {
187
+ /** Name of item (B section) if any. If telemetry data is derived straight from this, this should be null. */
188
+ baseType?: string;
189
+ /** The data payload for the telemetry request */
190
+ baseData?: MonitorDomain;
191
+ }
192
+
193
+ /** The abstract common base of all domains. */
194
+ export declare interface MonitorDomain {
195
+ /** Describes unknown properties. The value of an unknown property can be of "any" type. */
196
+ [property: string]: any;
197
+ /** Schema version */
198
+ version: number;
53
199
  }
54
200
 
55
201
  /**
@@ -62,4 +208,26 @@ export declare enum ServiceApiVersion {
62
208
  V2 = "2020-09-15_Preview"
63
209
  }
64
210
 
211
+ /** System variables for a telemetry item. */
212
+ export declare interface TelemetryItem {
213
+ /** Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1. */
214
+ version?: number;
215
+ /** Type name of telemetry data item. */
216
+ name: string;
217
+ /** Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z. */
218
+ time: Date;
219
+ /** Sampling rate used in application. This telemetry item represents 100 / sampleRate actual telemetry items. */
220
+ sampleRate?: number;
221
+ /** Sequence field used to track absolute order of uploaded events. */
222
+ sequence?: string;
223
+ /** The instrumentation key of the Application Insights resource. */
224
+ instrumentationKey?: string;
225
+ /** Key/value collection of context properties. See ContextTagKeys for information on available properties. */
226
+ tags?: {
227
+ [propertyName: string]: string;
228
+ };
229
+ /** Telemetry data item. */
230
+ data?: MonitorBase;
231
+ }
232
+
65
233
  export { }
package/CHANGELOG.md DELETED
@@ -1,51 +0,0 @@
1
- # Release History
2
-
3
- ## 1.0.0-beta.7 (2022-04-05)
4
-
5
- ### Features Added
6
-
7
- - Added authentication support using @azure/identity TokenCredential.
8
- - Added file access control in Windows for retriable telemetry.
9
-
10
- ## 1.0.0-beta.6 (2022-02-08)
11
-
12
- ### Other Changes
13
-
14
- - Updated OpenTelemtry dependencies to their latest available versions.
15
-
16
- ## 1.0.0-beta.5 (2021-10-05)
17
-
18
- ### Bugs Fixed
19
-
20
- - Fixed issue with SDK version field not being populated correctly.
21
-
22
- ### Other Changes
23
-
24
- - Updated mapping for Azure Monitor according to latest specs.
25
-
26
- ## 1.0.0-beta.4 (2021-07-07)
27
-
28
- - Updating OpenTelemetry API to 1.0.0
29
- - Adding support for temporary and permanent redirect
30
- - Adding cleanup process for older temp files
31
-
32
- ## 1.0.0-beta.3 (2021-02-10)
33
-
34
- - Rename package to `@azure/monitor-opentelemetry-exporter`
35
- - Added serviceApiVersion config
36
- - Open Telemetry dependency updates
37
-
38
- ## 1.0.0-beta.2 (2021-01-20)
39
-
40
- - Ship the correct type declaration file
41
-
42
- ## 1.0.0-beta.1 (2021-01-13)
43
-
44
- - OT Exporter retry when there are network issues
45
- - OpenTelemetry Exporter using Resources API to get service properties
46
- - Rename package to `@azure/opentelemetry-exporter-azure-monitor`
47
- - [BREAKING] Deprecate all configuration options except for `connectionString`
48
- - [BREAKING] Removed support for `TelemetryProcessor`
49
- - (internal) Migrate to autorest generated HttpClient and Envelope Interfaces
50
- - Migrate to Azure SDK for JS repository
51
- - Adds support for Event Hubs Distributed Tracing [#10575](https://github.com/Azure/azure-sdk-for-js/pull/10575)
@@ -1,34 +0,0 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- *
5
- * Code generated by Microsoft (R) AutoRest Code Generator.
6
- * Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
- */
8
- import * as coreClient from "@azure/core-client";
9
- export class ApplicationInsightsClientContext extends coreClient.ServiceClient {
10
- /**
11
- * Initializes a new instance of the ApplicationInsightsClientContext class.
12
- * @param options The parameter options
13
- */
14
- constructor(options) {
15
- // Initializing default values for options
16
- if (!options) {
17
- options = {};
18
- }
19
- const defaults = {
20
- requestContentType: "application/json; charset=utf-8"
21
- };
22
- const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.7`;
23
- const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
24
- ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
25
- : `${packageDetails}`;
26
- const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
27
- userAgentPrefix
28
- }, baseUri: options.endpoint || "{Host}/v2.1" });
29
- super(optionsWithDefaults);
30
- // Assigning values to Constant parameters
31
- this.host = options.host || "https://dc.services.visualstudio.com";
32
- }
33
- }
34
- //# sourceMappingURL=applicationInsightsClientContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applicationInsightsClientContext.js","sourceRoot":"","sources":["../../../src/generated/applicationInsightsClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,gCAAiC,SAAQ,UAAU,CAAC,aAAa;IAG5E;;;OAGG;IACH,YAAY,OAAiD;QAC3D,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAA4C;YACxD,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,sDAAsD,CAAC;QAC9E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,aAAa,GAC3C,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAE3B,0CAA0C;QAC1C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,sCAAsC,CAAC;IACrE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { ApplicationInsightsClientOptionalParams } from \"./models\";\n\nexport class ApplicationInsightsClientContext extends coreClient.ServiceClient {\n host: string;\n\n /**\n * Initializes a new instance of the ApplicationInsightsClientContext class.\n * @param options The parameter options\n */\n constructor(options?: ApplicationInsightsClientOptionalParams) {\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: ApplicationInsightsClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-monitor-opentelemetry-exporter/1.0.0-beta.7`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{Host}/v2.1\"\n };\n super(optionsWithDefaults);\n\n // Assigning values to Constant parameters\n this.host = options.host || \"https://dc.services.visualstudio.com\";\n }\n}\n"]}