-
Notifications
You must be signed in to change notification settings - Fork 529
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(detector-alibaba)!: change implementation to DetectorSync interface #2328
feat(detector-alibaba)!: change implementation to DetectorSync interface #2328
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2328 +/- ##
==========================================
- Coverage 90.97% 90.40% -0.57%
==========================================
Files 146 149 +3
Lines 7492 7361 -131
Branches 1502 1527 +25
==========================================
- Hits 6816 6655 -161
- Misses 676 706 +30
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @opentelemetry/resources
version requirement in the package.json
needs to be updated as ^1.10.0.
...pentelemetry-resource-detector-alibaba-cloud/test/fixtures/use-alibaba-cloud-ecs-detector.js
Outdated
Show resolved
Hide resolved
...pentelemetry-resource-detector-alibaba-cloud/test/fixtures/use-alibaba-cloud-ecs-detector.js
Outdated
Show resolved
Hide resolved
[SEMRESATTRS_HOST_TYPE]: instanceType, | ||
[SEMRESATTRS_HOST_NAME]: hostname, | ||
}; | ||
} catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could a diag log be added for the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the rejection is handled at https://github.com/open-telemetry/opentelemetry-js/blob/54b14fbbe33e0cf38115ee8c5c934a4e27786186/packages/opentelemetry-resources/src/Resource.ts#L87-L91. I think we should propagate the error instead of discarding it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
I think a more non-breaking way would be add a new |
…est/fixtures/use-alibaba-cloud-ecs-detector.js Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@legendecas thanks for the suggestion. I'll apply the changes here and bring it up to the JS SIG to get more feedback and, if accepted, apply it also to the other detectors. |
THe diff got big because the implementation moved from the ...Detector.ts to ...DetectorSync.ts file. If it helps, here is the diff between the current Detector.ts file on "main" and the DetectorSync.ts file in this PR: the diff--- /Users/trentm/src/opentelemetry-js-contrib/detectors/node/opentelemetry-resource-detector-alibaba-cloud/src/detectors/AlibabaCloudEcsDetector.ts 2024-04-16 11:49:08
+++ AlibabaCloudEcsDetectorSync.ts 2024-07-29 17:34:07
@@ -15,8 +15,10 @@
*/
import {
- Detector,
+ DetectorSync,
+ IResource,
Resource,
+ ResourceAttributes,
ResourceDetectionConfig,
} from '@opentelemetry/resources';
import {
@@ -38,7 +40,7 @@
* AlibabaCloud ECS and return a {@link Resource} populated with metadata about
* the ECS instance. Returns an empty Resource if detection fails.
*/
-class AlibabaCloudEcsDetector implements Detector {
+class AlibabaCloudEcsDetectorSync implements DetectorSync {
/**
* See https://www.alibabacloud.com/help/doc-detail/67254.htm for
* documentation about the AlibabaCloud instance identity document.
@@ -57,7 +59,14 @@
*
* @param config (unused) The resource detection config
*/
- async detect(_config?: ResourceDetectionConfig): Promise<Resource> {
+ detect(_config?: ResourceDetectionConfig): IResource {
+ return new Resource({}, this._getAttributes());
+ }
+
+ /** Gets identity and host info and returns them as attribs. Empty object if fails */
+ async _getAttributes(
+ _config?: ResourceDetectionConfig
+ ): Promise<ResourceAttributes> {
const {
'owner-account-id': accountId,
'instance-id': instanceId,
@@ -67,7 +76,7 @@
} = await this._fetchIdentity();
const hostname = await this._fetchHost();
- return new Resource({
+ return {
[SEMRESATTRS_CLOUD_PROVIDER]: CLOUDPROVIDERVALUES_ALIBABA_CLOUD,
[SEMRESATTRS_CLOUD_PLATFORM]: CLOUDPLATFORMVALUES_ALIBABA_CLOUD_ECS,
[SEMRESATTRS_CLOUD_ACCOUNT_ID]: accountId,
@@ -76,7 +85,7 @@
[SEMRESATTRS_HOST_ID]: instanceId,
[SEMRESATTRS_HOST_TYPE]: instanceType,
[SEMRESATTRS_HOST_NAME]: hostname,
- });
+ };
}
/**
@@ -144,4 +153,4 @@
}
}
-export const alibabaCloudEcsDetector = new AlibabaCloudEcsDetector();
+export const alibabaCloudEcsDetectorSync = new AlibabaCloudEcsDetectorSync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test file (of the old, unchanged non-Sync detector) be reverted back to its original state?
(I wonder if some of the tests below are passing because of luck.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the async detector is leveraging the new sync detector there's a change in behavior that makes the original tests fail. The difference is the detector's detect
method does not throw anymore.
I guess that's something we do not want. I'll share it in the upcoming SIG to get feedback.
Hi @legendecas in today's JavaScript SIG we discussed this and the other detector PRs. The conclusion was it's okay to do a breaking change for non stable detectors if the owner is okay with it. In this detector you suggested a non breaking change so I've added another detector complying with It's worth mentioning the former detector reused the new one following the pattern existing in the core repo (example). With this approach the detector does not throw but returns an empty resource, tests are changed accordingly. This was also discussed in the SIG and agreed that the change of behavior should not be considered a breaking change. Also since were adding a new detector I'll rename this PR to I think trent's comment points to what is the main change here. |
Thanks for the update! I think I am fine with breaking if we do all the same with other detectors, given that the test might be more complex if we have two variants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the test file name nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Ecs" in the filename was accidentally removed in the shuffling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, my bad
I approved, but I guess we are now considering dropping the |
Thanks @legendecas & @trentm for your feedback. I think dropping the async detector is the best course of action now that we agree on it.
So I'm going to revert the changes to the 1st proposal and refactor the detector from async to sync. |
@@ -14,4 +14,4 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
export * from './detectors'; | |||
export { alibabaCloudEcsDetector } from './detectors'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to reviewer: little step forward to resolve open-telemetry/opentelemetry-js#4186
@@ -84,56 +85,47 @@ describe('alibabaCloudEcsDetector', () => { | |||
}); | |||
|
|||
describe('with unsuccessful request', () => { | |||
it('should throw when receiving error response code', async () => { | |||
const expectedError = new Error('Failed to load page, status code: 404'); | |||
it('should return empty resource when receiving error response code', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to reviewer: the detector does not throw but rather returns a resource with no attribs.
Context
In order to fix #2320 we need to suppress tracing when this detector is doing HTTP requests or using any other instrumented API. IMO this would be easier if we already have the detectors implementing the
DetectorSync
interface moving away from the deprecatedDetector
. This PR is adding a new sync detector that will be used by the SDK and auto-instrumentations package (to be changed in a follow-up PR).Follow-up PRs will be created to:
Short description of the changes
DetectorSync
interfaceTest changes
The new detector's
detect
method becomes synchronous and therefore there is no way to throw an exception in it for an async HTTP error. The refactor makes this detector to return and empty resource if an async error occurs, so the test does not expect an exception anymore but an empty resource.Also this aligns with
@opentelemetry/resources
logic used by the NodeSDK which catches any exception from the detector and returns an empty resource.https://github.com/open-telemetry/opentelemetry-js/blob/54b14fbbe33e0cf38115ee8c5c934a4e27786186/packages/opentelemetry-resources/src/detect-resources.ts#L32