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

Construction by dependency injection / excessive reliance on static singletons #206

Closed
jacostro opened this issue Sep 17, 2019 · 1 comment · Fixed by #267
Closed

Construction by dependency injection / excessive reliance on static singletons #206

jacostro opened this issue Sep 17, 2019 · 1 comment · Fixed by #267

Comments

@jacostro
Copy link

Hello,
I'm currently trying to switch my project which was based on OpenCensus to OpenTelemetry. This is an exercise in frustration, because apparently there is no way to make my existing tests work - thanks to improved protection of classes, constructors and methods by internal keyword. I'm not able to find a way to initialize stats component in isolation - it seems that the only way is to use static properties of Stats class, and I need a fresh state for each test. (Previously it was possible by instantiation of StatsComponent class.)

What about more flexible composition by dependency injection? I can see some reasons why this would be better:

  • external test scenarios involving OpenTelemetry components (my case),
  • possibility to create multiple instances of OpenTelemetry classes with separate configurations,
  • more flexibility with regards to component implementation,
  • option to reinitialize the stats / trace subsystem,
  • nice integration with .NET (Core) applications which already heavily rely on DI.

It could be still possible to perform initialization of (for example) stats subsystem by explicit instantiation of Stats class, with reasonable default configuration. Currently even if I remove constructor protection by internal keyword it won't help much, because the properties are static.

@lmolkova
Copy link

lmolkova commented Oct 1, 2019

We are doing some changes that mostly eliminated static singletons in Tracing API. There will be global tracer, but you'll have control to set it.

Metrics/Tags everything else will get similar treatment in the next month or two.

Overall, we want to minimize static singletons usage and allow users to completely avoid them when possible.

Yun-Ting pushed a commit to Yun-Ting/opentelemetry-dotnet that referenced this issue Oct 13, 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 a pull request may close this issue.

2 participants