Skip to content

Commit 912ed6f

Browse files
authored
[Azure Monitor Exporter] First iteration of Lint error fixes (Azure#27307)
### Packages impacted by this PR @azure/monitor-opentelemetry-exporter ### Issues associated with this PR Azure#17942
1 parent 0b97dbe commit 912ed6f

30 files changed

+548
-560
lines changed

sdk/monitor/monitor-opentelemetry-exporter/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@
102102
"sinon": "^15.0.0",
103103
"ts-node": "^10.0.0",
104104
"typescript": "~5.0.0",
105-
"cross-env": "^7.0.2",
106-
"esm": "^3.2.18"
105+
"cross-env": "^7.0.2"
107106
},
108107
"dependencies": {
109108
"@azure/core-client": "^1.0.0",

sdk/monitor/monitor-opentelemetry-exporter/src/export/base.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ export abstract class AzureMonitorBaseExporter {
2626
*Flag to determine if exporter will generate Statsbeat data
2727
*/
2828
protected trackStatsbeat: boolean = false;
29-
private _isStatsbeatExporter: boolean;
29+
private isStatsbeatExporter: boolean;
3030

3131
/**
3232
* Exporter internal configuration
3333
*/
34-
private readonly _options: AzureMonitorExporterOptions;
34+
private readonly options: AzureMonitorExporterOptions;
3535

3636
/**
3737
* Initializes a new instance of the AzureMonitorBaseExporter class.
3838
* @param AzureMonitorExporterOptions - Exporter configuration.
3939
*/
4040
constructor(options: AzureMonitorExporterOptions = {}, isStatsbeatExporter?: boolean) {
41-
this._options = options;
41+
this.options = options;
4242
this.instrumentationKey = "";
4343
this.endpointUrl = DEFAULT_BREEZE_ENDPOINT;
44-
const connectionString = this._options.connectionString || process.env[ENV_CONNECTION_STRING];
45-
this._isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;
44+
const connectionString = this.options.connectionString || process.env[ENV_CONNECTION_STRING];
45+
this.isStatsbeatExporter = isStatsbeatExporter ? isStatsbeatExporter : false;
4646

4747
if (connectionString) {
4848
const parsedConnectionString = ConnectionStringParser.parse(connectionString);
@@ -63,7 +63,7 @@ export abstract class AzureMonitorBaseExporter {
6363
diag.error(message);
6464
throw new Error(message);
6565
}
66-
this.trackStatsbeat = !this._isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];
66+
this.trackStatsbeat = !this.isStatsbeatExporter && !process.env[ENV_DISABLE_STATSBEAT];
6767

6868
diag.debug("AzureMonitorExporter was successfully setup");
6969
}

sdk/monitor/monitor-opentelemetry-exporter/src/export/log.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,26 @@ export class AzureMonitorLogExporter extends AzureMonitorBaseExporter implements
4141
* @param logs - Logs to export.
4242
* @param resultCallback - Result callback.
4343
*/
44-
public async export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {
44+
public async export(
45+
logs: ReadableLogRecord[],
46+
resultCallback: (result: ExportResult) => void
47+
): Promise<void> {
4548
if (this._isShutdown) {
4649
diag.info("Exporter shut down. Failed to export spans.");
4750
setTimeout(() => resultCallback({ code: ExportResultCode.FAILED }), 0);
4851
return;
4952
}
5053
diag.info(`Exporting ${logs.length} logs(s). Converting to envelopes...`);
5154

52-
let envelopes: Envelope[] = [];
55+
const envelopes: Envelope[] = [];
5356
logs.forEach((log) => {
54-
let envelope = logToEnvelope(log, this.instrumentationKey);
57+
const envelope = logToEnvelope(log, this.instrumentationKey);
5558
if (envelope) {
5659
envelopes.push(envelope);
5760
}
5861
});
5962
// Supress tracing until OpenTelemetry Logs SDK support it
60-
context.with(suppressTracing(context.active()), async () => {
63+
await context.with(suppressTracing(context.active()), async () => {
6164
resultCallback(await this._sender.exportEnvelopes(envelopes));
6265
});
6366
}

sdk/monitor/monitor-opentelemetry-exporter/src/export/metric.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export class AzureMonitorMetricExporter
5959
}
6060
diag.info(`Exporting ${metrics.scopeMetrics.length} metrics(s). Converting to envelopes...`);
6161

62-
let envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);
62+
const envelopes: Envelope[] = resourceMetricsToEnvelope(metrics, this.instrumentationKey);
6363
// Supress tracing until OpenTelemetry Metrics SDK support it
64-
context.with(suppressTracing(context.active()), async () => {
64+
await context.with(suppressTracing(context.active()), async () => {
6565
resultCallback(await this._sender.exportEnvelopes(envelopes));
6666
});
6767
}
@@ -80,8 +80,8 @@ export class AzureMonitorMetricExporter
8080
*/
8181
public selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {
8282
if (
83-
instrumentType == InstrumentType.UP_DOWN_COUNTER ||
84-
instrumentType == InstrumentType.OBSERVABLE_UP_DOWN_COUNTER
83+
instrumentType === InstrumentType.UP_DOWN_COUNTER ||
84+
instrumentType === InstrumentType.OBSERVABLE_UP_DOWN_COUNTER
8585
) {
8686
return AggregationTemporality.CUMULATIVE;
8787
}
@@ -91,7 +91,7 @@ export class AzureMonitorMetricExporter
9191
/**
9292
* Force flush
9393
*/
94-
public async forceFlush() {
94+
public async forceFlush(): Promise<void> {
9595
return Promise.resolve();
9696
}
9797
}

sdk/monitor/monitor-opentelemetry-exporter/src/export/statsbeat/longIntervalStatsbeatMetrics.ts

Lines changed: 72 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -34,116 +34,115 @@ let instance: LongIntervalStatsbeatMetrics | null = null;
3434
* @internal
3535
*/
3636
class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
37-
private _AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;
38-
private _statsCollectionLongInterval: number = 86400000; // 1 day
39-
private _isInitialized: boolean = false;
40-
37+
private AZURE_MONITOR_STATSBEAT_FEATURES = process.env.AZURE_MONITOR_STATSBEAT_FEATURES;
38+
private statsCollectionLongInterval: number = 86400000; // 1 day
4139
// Custom dimensions
42-
private _cikey: string;
43-
private _runtimeVersion: string;
44-
private _language: string;
45-
private _version: string;
46-
private _attach: string = "sdk";
40+
private cikey: string;
41+
private runtimeVersion: string;
42+
private language: string;
43+
private version: string;
44+
private attach: string = "sdk";
4745

48-
private _commonProperties: CommonStatsbeatProperties;
49-
private _attachProperties: AttachStatsbeatProperties;
46+
private commonProperties: CommonStatsbeatProperties;
47+
private attachProperties: AttachStatsbeatProperties;
5048

51-
private _feature: number = 0;
52-
private _instrumentation: number = 0;
49+
private feature: number = 0;
50+
private instrumentation: number = 0;
5351

54-
private _longIntervalStatsbeatMeterProvider: MeterProvider;
55-
private _longIntervalAzureExporter: AzureMonitorStatsbeatExporter;
56-
private _longIntervalMetricReader: PeriodicExportingMetricReader;
57-
private _longIntervalStatsbeatMeter: Meter;
52+
private longIntervalStatsbeatMeterProvider: MeterProvider;
53+
private longIntervalAzureExporter: AzureMonitorStatsbeatExporter;
54+
private longIntervalMetricReader: PeriodicExportingMetricReader;
55+
private longIntervalStatsbeatMeter: Meter;
5856

5957
// Network Attributes
60-
private _connectionString: string;
58+
private connectionString: string;
6159

6260
// Observable Gauges
63-
private _featureStatsbeatGauge: ObservableGauge;
64-
private _attachStatsbeatGauge: ObservableGauge;
61+
private featureStatsbeatGauge: ObservableGauge;
62+
private attachStatsbeatGauge: ObservableGauge;
63+
64+
public isInitialized: boolean = false;
6565

6666
constructor(options: StatsbeatOptions) {
6767
super();
68-
this._connectionString = super._getConnectionString(options.endpointUrl);
68+
this.connectionString = super.getConnectionString(options.endpointUrl);
6969
const exporterConfig: AzureMonitorExporterOptions = {
70-
connectionString: this._connectionString,
70+
connectionString: this.connectionString,
7171
};
7272

73-
if (this._AZURE_MONITOR_STATSBEAT_FEATURES) {
73+
if (this.AZURE_MONITOR_STATSBEAT_FEATURES) {
7474
try {
75-
this._feature = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).feature;
76-
this._instrumentation = JSON.parse(this._AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;
77-
} catch (error) {
75+
this.feature = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).feature;
76+
this.instrumentation = JSON.parse(this.AZURE_MONITOR_STATSBEAT_FEATURES).instrumentation;
77+
} catch (error: any) {
7878
diag.error(
7979
`LongIntervalStatsbeat: Failed to parse features/instrumentations (error ${error})`
8080
);
8181
}
8282
}
8383

84-
this._longIntervalStatsbeatMeterProvider = new MeterProvider();
85-
this._longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
84+
this.longIntervalStatsbeatMeterProvider = new MeterProvider();
85+
this.longIntervalAzureExporter = new AzureMonitorStatsbeatExporter(exporterConfig);
8686

8787
// Export Long Interval Statsbeats every day
8888
const longIntervalMetricReaderOptions: PeriodicExportingMetricReaderOptions = {
89-
exporter: this._longIntervalAzureExporter,
89+
exporter: this.longIntervalAzureExporter,
9090
exportIntervalMillis:
91-
Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this._statsCollectionLongInterval, // 1 day
91+
Number(process.env.LONG_INTERVAL_EXPORT_MILLIS) || this.statsCollectionLongInterval, // 1 day
9292
};
9393

94-
this._longIntervalMetricReader = new PeriodicExportingMetricReader(
94+
this.longIntervalMetricReader = new PeriodicExportingMetricReader(
9595
longIntervalMetricReaderOptions
9696
);
97-
this._longIntervalStatsbeatMeterProvider.addMetricReader(this._longIntervalMetricReader);
98-
this._longIntervalStatsbeatMeter = this._longIntervalStatsbeatMeterProvider.getMeter(
97+
this.longIntervalStatsbeatMeterProvider.addMetricReader(this.longIntervalMetricReader);
98+
this.longIntervalStatsbeatMeter = this.longIntervalStatsbeatMeterProvider.getMeter(
9999
"Azure Monitor Long Interval Statsbeat"
100100
);
101101

102102
// Assign Common Properties
103-
this._runtimeVersion = process.version;
104-
this._language = STATSBEAT_LANGUAGE;
105-
this._version = ai.packageVersion;
106-
this._cikey = options.instrumentationKey;
103+
this.runtimeVersion = process.version;
104+
this.language = STATSBEAT_LANGUAGE;
105+
this.version = ai.packageVersion;
106+
this.cikey = options.instrumentationKey;
107107

108-
this._featureStatsbeatGauge = this._longIntervalStatsbeatMeter.createObservableGauge(
108+
this.featureStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(
109109
StatsbeatCounter.FEATURE
110110
);
111-
this._attachStatsbeatGauge = this._longIntervalStatsbeatMeter.createObservableGauge(
111+
this.attachStatsbeatGauge = this.longIntervalStatsbeatMeter.createObservableGauge(
112112
StatsbeatCounter.ATTACH
113113
);
114114

115-
this._commonProperties = {
116-
os: super._os,
117-
rp: super._resourceProvider,
118-
cikey: this._cikey,
119-
runtimeVersion: this._runtimeVersion,
120-
language: this._language,
121-
version: this._version,
122-
attach: this._attach,
115+
this.commonProperties = {
116+
os: super.os,
117+
rp: super.resourceProvider,
118+
cikey: this.cikey,
119+
runtimeVersion: this.runtimeVersion,
120+
language: this.language,
121+
version: this.version,
122+
attach: this.attach,
123123
};
124124

125-
this._attachProperties = {
126-
rpId: super._resourceIdentifier,
125+
this.attachProperties = {
126+
rpId: super.resourceIdentifier,
127127
};
128128

129-
this._isInitialized = true;
130-
this._initialize();
129+
this.isInitialized = true;
130+
this.initialize();
131131
}
132132

133-
private async _initialize() {
133+
private async initialize() {
134134
try {
135-
await this._getResourceProvider();
135+
await this.getResourceProvider();
136136

137137
// Add long interval observable callbacks
138-
this._attachStatsbeatGauge.addCallback(this._attachCallback.bind(this));
139-
this._longIntervalStatsbeatMeter.addBatchObservableCallback(
140-
this._featureCallback.bind(this),
141-
[this._featureStatsbeatGauge]
142-
);
138+
this.attachStatsbeatGauge.addCallback(this.attachCallback.bind(this));
139+
this.longIntervalStatsbeatMeter.addBatchObservableCallback(this.featureCallback.bind(this), [
140+
this.featureStatsbeatGauge,
141+
]);
143142

144143
// Export Feature/Attach Statsbeat once upon app initialization
145-
this._longIntervalAzureExporter.export(
146-
(await this._longIntervalMetricReader.collect()).resourceMetrics,
144+
this.longIntervalAzureExporter.export(
145+
(await this.longIntervalMetricReader.collect()).resourceMetrics,
147146
(result: ExportResult) => {
148147
if (result.code !== ExportResultCode.SUCCESS) {
149148
diag.error(`LongIntervalStatsbeat: metrics export failed (error ${result.error})`);
@@ -155,38 +154,34 @@ class LongIntervalStatsbeatMetrics extends StatsbeatMetrics {
155154
}
156155
}
157156

158-
private _featureCallback(observableResult: BatchObservableResult) {
157+
private featureCallback(observableResult: BatchObservableResult) {
159158
let attributes;
160-
if (this._instrumentation) {
159+
if (this.instrumentation) {
161160
attributes = {
162-
...this._commonProperties,
163-
feature: this._instrumentation,
161+
...this.commonProperties,
162+
feature: this.instrumentation,
164163
type: StatsbeatFeatureType.INSTRUMENTATION,
165164
};
166-
observableResult.observe(this._featureStatsbeatGauge, 1, { ...attributes });
165+
observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });
167166
}
168167

169-
if (this._feature) {
168+
if (this.feature) {
170169
attributes = {
171-
...this._commonProperties,
172-
feature: this._feature,
170+
...this.commonProperties,
171+
feature: this.feature,
173172
type: StatsbeatFeatureType.FEATURE,
174173
};
175-
observableResult.observe(this._featureStatsbeatGauge, 1, { ...attributes });
174+
observableResult.observe(this.featureStatsbeatGauge, 1, { ...attributes });
176175
}
177176
}
178177

179-
private _attachCallback(observableResult: ObservableResult) {
180-
let attributes = { ...this._commonProperties, ...this._attachProperties };
178+
private attachCallback(observableResult: ObservableResult) {
179+
const attributes = { ...this.commonProperties, ...this.attachProperties };
181180
observableResult.observe(1, attributes);
182181
}
183182

184-
public isInitialized() {
185-
return this._isInitialized;
186-
}
187-
188-
public shutdown() {
189-
this._longIntervalStatsbeatMeterProvider.shutdown();
183+
public shutdown(): Promise<void> {
184+
return this.longIntervalStatsbeatMeterProvider.shutdown();
190185
}
191186
}
192187

0 commit comments

Comments
 (0)