Skip to content

Commit ec39a25

Browse files
committed
lint:fix
1 parent e6c5dba commit ec39a25

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

detectors/node/opentelemetry-resource-detector-azure/src/detectors/AzureVmDetector.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,46 +65,58 @@ class AzureVmResourceDetector implements ResourceDetector {
6565
Metadata: 'True',
6666
},
6767
};
68-
const metadataP: Promise<AzureVmMetadata> = new Promise((resolve, reject) => {
69-
const timeoutId = setTimeout(() => {
70-
req.destroy();
71-
reject(new Error('Azure metadata service request timed out.'));
72-
}, 1000);
68+
const metadataP: Promise<AzureVmMetadata> = new Promise(
69+
(resolve, reject) => {
70+
const timeoutId = setTimeout(() => {
71+
req.destroy();
72+
reject(new Error('Azure metadata service request timed out.'));
73+
}, 1000);
7374

74-
const req = http.request(options, res => {
75-
clearTimeout(timeoutId);
76-
const { statusCode } = res;
77-
res.setEncoding('utf8');
78-
let rawData = '';
79-
res.on('data', chunk => (rawData += chunk));
80-
res.on('end', () => {
81-
if (statusCode && statusCode >= 200 && statusCode < 300) {
82-
try {
83-
resolve(JSON.parse(rawData));
84-
} catch (error) {
85-
reject(error);
75+
const req = http.request(options, res => {
76+
clearTimeout(timeoutId);
77+
const { statusCode } = res;
78+
res.setEncoding('utf8');
79+
let rawData = '';
80+
res.on('data', chunk => (rawData += chunk));
81+
res.on('end', () => {
82+
if (statusCode && statusCode >= 200 && statusCode < 300) {
83+
try {
84+
resolve(JSON.parse(rawData));
85+
} catch (error) {
86+
reject(error);
87+
}
88+
} else {
89+
reject(
90+
new Error('Failed to load page, status code: ' + statusCode)
91+
);
8692
}
87-
} else {
88-
reject(
89-
new Error('Failed to load page, status code: ' + statusCode)
90-
);
91-
}
93+
});
9294
});
93-
});
94-
req.on('error', err => {
95-
clearTimeout(timeoutId);
96-
reject(err);
97-
});
98-
req.end();
99-
});
95+
req.on('error', err => {
96+
clearTimeout(timeoutId);
97+
reject(err);
98+
});
99+
req.end();
100+
}
101+
);
100102

101103
const attributes = {
102-
[AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadataP.then(metadata => metadata['vmScaleSetName']),
104+
[AZURE_VM_SCALE_SET_NAME_ATTRIBUTE]: metadataP.then(
105+
metadata => metadata['vmScaleSetName']
106+
),
103107
[AZURE_VM_SKU_ATTRIBUTE]: metadataP.then(metadata => metadata['sku']),
104-
[SEMRESATTRS_CLOUD_PLATFORM]: metadataP.then(() => CLOUDPLATFORMVALUES_AZURE_VM),
105-
[SEMRESATTRS_CLOUD_PROVIDER]: metadataP.then(() => CLOUDPROVIDERVALUES_AZURE),
106-
[SEMRESATTRS_CLOUD_REGION]: metadataP.then(metadata => metadata['location']),
107-
[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadataP.then(metadata => metadata['resourceId']),
108+
[SEMRESATTRS_CLOUD_PLATFORM]: metadataP.then(
109+
() => CLOUDPLATFORMVALUES_AZURE_VM
110+
),
111+
[SEMRESATTRS_CLOUD_PROVIDER]: metadataP.then(
112+
() => CLOUDPROVIDERVALUES_AZURE
113+
),
114+
[SEMRESATTRS_CLOUD_REGION]: metadataP.then(
115+
metadata => metadata['location']
116+
),
117+
[CLOUD_RESOURCE_ID_RESOURCE_ATTRIBUTE]: metadataP.then(
118+
metadata => metadata['resourceId']
119+
),
108120
[SEMRESATTRS_HOST_ID]: metadataP.then(metadata => metadata['vmId']),
109121
[SEMRESATTRS_HOST_NAME]: metadataP.then(metadata => metadata['name']),
110122
[SEMRESATTRS_HOST_TYPE]: metadataP.then(metadata => metadata['vmSize']),

0 commit comments

Comments
 (0)