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

fix(sdk-node): use resource interface instead of concrete class #3803

Merged
merged 2 commits into from
May 15, 2023

Conversation

blumamir
Copy link
Member

@blumamir blumamir commented May 15, 2023

Which problem is this PR solving?

contrib repo currently fails to build because of issue with @opentelemetry/resource-detector-instana: (sorry that was not correct, I needed to update the branch, but the fix is relevant regardless).

test/InstanaAgentDetectorIntegrationTest.test.ts:62:7 - error TS2322: Type 'import("/Users/amirblum/repos/opentelemetry-js-contrib/node_modules/@opentelemetry/resources/build/src/Resource").Resource' is not assignable to type 'import("/Users/amirblum/repos/opentelemetry-js-contrib/node_modules/@opentelemetry/sdk-node/node_modules/@opentelemetry/resources/build/src/Resource").Resource'.
  Types have separate declarations of a private property '_syncAttributes'.

62       resource: globalResource,
         ~~~~~~~~

test/InstanaAgentDetectorIntegrationTest.test.ts:101:7 - error TS2322: Type 'import("/Users/amirblum/repos/opentelemetry-js-contrib/node_modules/@opentelemetry/resources/build/src/Resource").Resource' is not assignable to type 'import("/Users/amirblum/repos/opentelemetry-js-contrib/node_modules/@opentelemetry/sdk-node/node_modules/@opentelemetry/resources/build/src/Resource").Resource'.

101       resource: globalResource,
          ~~~~~~~~

We had this issue in the past. components should use interfaces and not concrete classes, as using concrete classes causes typescript to error when the classes have private properties when 2 different versions are used.

Since @opentelemetry/sdk-node has a dependency on "@opentelemetry/resources": "1.13.0", if it uses the Resource class which has private property _syncAttributes, then everyone using this component with a resource must use the exact same version as well, which is not good.

The class NodeSDK already uses IResource and not Resource in other places here and here, so this only aligns the constructor to use it as well

Short description of the changes

Use the IResource interface instead of the concrete class Resource.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Since class Resource implements IResource it shouldn't be a breaking change for any user to my understanding, but would appreciate other eyes on that.

How Has This Been Tested?

It only changes typescript and I tested it compiles successfully.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@blumamir blumamir requested a review from a team May 15, 2023 14:54
@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Merging #3803 (bc64d28) into main (758c7af) will decrease coverage by 0.02%.
The diff coverage is n/a.

❗ Current head bc64d28 differs from pull request most recent head d24e24b. Consider uploading reports for the commit d24e24b to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3803      +/-   ##
==========================================
- Coverage   93.23%   93.22%   -0.02%     
==========================================
  Files         293      293              
  Lines        8889     8889              
  Branches     1825     1825              
==========================================
- Hits         8288     8287       -1     
- Misses        601      602       +1     

see 1 file with indirect coverage changes

@pichlermarc pichlermarc merged commit 2531263 into open-telemetry:main May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants