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: add the ability to set the views via the SDK constructor #3124

Merged
merged 24 commits into from
Aug 17, 2022

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Jul 28, 2022

Which problem is this PR solving?

Recently the ability to define views has been moved to the constructor of the MeterProvider when you are using the node-sdk you aren't not able to pass views anymore. This PR attempts to resolve this problem.

Fixes #3125 (issue)

Short description of the changes

Add the views: Views[]-parameter to the configuration type

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

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Used yalc to verify it works

Checklist:

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

@weyert
Copy link
Contributor Author

weyert commented Jul 28, 2022

Does anyone have a good idea how I can access the views of the meter provider to ensure they got passed in?

@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #3124 (2931a15) into main (6807def) will decrease coverage by 0.02%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##             main    #3124      +/-   ##
==========================================
- Coverage   93.21%   93.18%   -0.03%     
==========================================
  Files         196      196              
  Lines        6414     6431      +17     
  Branches     1350     1359       +9     
==========================================
+ Hits         5979     5993      +14     
- Misses        435      438       +3     
Impacted Files Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 91.02% <87.50%> (-2.42%) ⬇️

@dyladan
Copy link
Member

dyladan commented Jul 29, 2022

Does anyone have a good idea how I can access the views of the meter provider to ensure they got passed in?

You can access private properties using obj["_somePrivateProperty"] syntax. I believe the views are in provider["_sharedState"].viewRegistry["_registeredViews"]. You can also do provider["_sharedState"].viewRegistry.findViews(instrument, meter) if you have access to the instrument.

@weyert
Copy link
Contributor Author

weyert commented Jul 31, 2022

Does anyone have a good idea how I can access the views of the meter provider to ensure they got passed in?

You can access private properties using obj["_somePrivateProperty"] syntax. I believe the views are in provider["_sharedState"].viewRegistry["_registeredViews"]. You can also do provider["_sharedState"].viewRegistry.findViews(instrument, meter) if you have access to the instrument.

Thank you for the tip. I have added the unit test :)

@weyert weyert marked this pull request as ready for review July 31, 2022 14:35
@weyert weyert requested a review from a team July 31, 2022 14:35
@legendecas
Copy link
Member

legendecas commented Jul 31, 2022

Sorry for the delay, this is purely a suggestion: You can also test with the resulting metric streams with a MetricReader, like adding a renaming view and checking that the metric instrument is being renamed when exported, without accessing the internal states of the meter provider.

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated dts files are erasing the types of private properties. So linked packages accessing the private properties will not get the type information.

@weyert
Copy link
Contributor Author

weyert commented Jul 31, 2022

Sorry for the delay, this is purely a suggestion: You can also test with the resulting metric streams with a MetricReader, like adding a renaming view and checking that the metric instrument is being renamed when exported, without accessing the internal states of the meter provider.

I will give it shot :) If I understand you correctly you want me to test with like the in memory exporter?

@legendecas
Copy link
Member

If I understand you correctly you want me to test with like the in memory exporter?

Yeah, or more cleanly testing it with InMemoryExporter will be great. This is where InMemoryExporter is best suited :)

@dyladan
Copy link
Member

dyladan commented Aug 3, 2022

@weyert what is the plan here? To update the tests to use the in memory exporter?

@dyladan
Copy link
Member

dyladan commented Aug 3, 2022

If this is not ready for review please mark as draft, otherwise just comment and I will review it.

@weyert
Copy link
Contributor Author

weyert commented Aug 4, 2022

@weyert what is the plan here? To update the tests to use the in memory exporter?

Yes, that's the plan. I hope to sort it out before the end of the weekend. Only I am unable to switch the PR to draft

@pichlermarc pichlermarc marked this pull request as draft August 4, 2022 11:42
@pichlermarc
Copy link
Member

@weyert thanks for adding this and taking the time to switch over the tests. 🚀
I marked the PR as draft now, you should be able to mark it as ready at any point 🙂

@weyert
Copy link
Contributor Author

weyert commented Aug 4, 2022

@pichlermarc I have updated the test, let me know, if this test with in memory exporter makes sense for you. If so, feel free to change the status of the PR to Ready for review :)

@pichlermarc
Copy link
Member

Looking good, thanks for adapting the tests. 🙂
I think this should be ready once the linting errors are addressed (there are a few unused imports and missing semicolons). 🙂

@weyert weyert marked this pull request as ready for review August 5, 2022 11:01
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with a few minor comments. 🙂
Sorry for the churn. 🙁

experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
experimental/packages/opentelemetry-sdk-node/src/sdk.ts Outdated Show resolved Hide resolved
Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending conflict resolution

@dyladan
Copy link
Member

dyladan commented Aug 16, 2022

Want to make sure @legendecas is happy since he had comments but this can be merged IMO

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@legendecas legendecas merged commit 43f4e5a into open-telemetry:main Aug 17, 2022
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.

Unable to define views for metrics when using node-sdk
6 participants