Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(detectors): add alibaba cloud detector #590

Merged
merged 14 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [2020] OpenTelemetry Authors
Copyright [2021] OpenTelemetry Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@
"nock": "12.0.3",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "10.0.0",
"sinon": "11.1.2",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.2"
},
"dependencies": {
"@opentelemetry/core": "^0.24.0",
"@opentelemetry/resources": "^0.24.0",
"@opentelemetry/semantic-conventions": "^0.24.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,26 @@ class AlibabaCloudEcsDetector implements Detector {
private async _fetchString(options: http.RequestOptions): Promise<string> {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
req.abort();
reject(new Error('ECS metadata api request timed out.'));
req.destroy(new Error('ECS metadata api request timed out.'));
}, 1000);
legendecas marked this conversation as resolved.
Show resolved Hide resolved

const req = http.request(options, res => {
clearTimeout(timeoutId);
const { statusCode } = res;
if (statusCode && statusCode >= 200 && statusCode < 300) {
return reject(
new Error('Failed to load page, status code: ' + statusCode)
legendecas marked this conversation as resolved.
Show resolved Hide resolved
);
}

res.setEncoding('utf8');
let rawData = '';
res.on('data', chunk => (rawData += chunk));
legendecas marked this conversation as resolved.
Show resolved Hide resolved
res.on('error', err => {
reject(err);
});
res.on('end', () => {
if (statusCode && statusCode >= 200 && statusCode < 300) {
try {
resolve(rawData);
} catch (e) {
reject(e);
}
} else {
reject(
new Error('Failed to load page, status code: ' + statusCode)
);
}
resolve(rawData);
});
});
req.on('error', err => {
Expand Down