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!: more specific types for getConfig and setConfig #2388

Closed
wants to merge 2 commits into from

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Aug 2, 2021

Fixes #2258 Should not require any change to existing instrumentations, but allows instrumentations to declare config types with more properties which are used by config get/set

@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #2388 (00c4864) into main (3b9cd16) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2388      +/-   ##
==========================================
- Coverage   92.78%   92.64%   -0.14%     
==========================================
  Files         145      142       -3     
  Lines        5226     5101     -125     
  Branches     1071     1048      -23     
==========================================
- Hits         4849     4726     -123     
+ Misses        377      375       -2     
Impacted Files Coverage Δ
...entelemetry-instrumentation/src/instrumentation.ts 70.37% <100.00%> (ø)
...ontext-async-hooks/src/AsyncHooksContextManager.ts
...sync-hooks/src/AbstractAsyncHooksContextManager.ts
...async-hooks/src/AsyncLocalStorageContextManager.ts

Copy link
Member

@Flarna Flarna left a comment

Choose a reason for hiding this comment

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

It would be nice to adapt one of the instrumentations like http to have an implicit test.

@dyladan dyladan requested a review from MSNev August 4, 2021 15:24
@dyladan
Copy link
Member Author

dyladan commented Aug 4, 2021

@MSNev re-requested your review since the last change is breaking

@dyladan dyladan changed the title feat: more specific types for getConfig and setConfig feat!: more specific types for getConfig and setConfig Aug 4, 2021
@@ -29,9 +29,9 @@ import * as types from './types';
/**
* Base abstract internal class for instrumenting node and web plugins
*/
export abstract class InstrumentationAbstract<T = any>
export abstract class InstrumentationAbstract<InstrumentedModuleType = any, Config = types.InstrumentationConfig>
Copy link
Member

Choose a reason for hiding this comment

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

would this work ?

Suggested change
export abstract class InstrumentationAbstract<InstrumentedModuleType = any, Config = types.InstrumentationConfig>
export abstract class InstrumentationAbstract<InstrumentedModuleType = any, Config extends types.InstrumentationConfig>

Copy link
Member Author

Choose a reason for hiding this comment

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

If we make Config required we have to also make InstrumentedModuleType optional (required types can't follow optional types). Is that what you're suggesting?

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be a combination - optional with default to types.InstrumentationConfig but if a concrete type is specified it must extend types.InstrumentationConfig (otherwise it would be allowed to use e.g. number).

Copy link
Member

@obecny obecny Aug 26, 2021

Choose a reason for hiding this comment

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

just a friendly ping here to prevent stuck

@Flarna
Copy link
Member

Flarna commented Aug 5, 2021

I think it's needed to additionally adapt abstract class InstrumentationBase in packages\opentelemetry-instrumentation\src\platform\node\instrumentation.ts otherwise the change is not visible to instrumentations in node case.

Once again, if you could adapt at least one instrumentation like http we would have an implicit test for this.

@dyladan
Copy link
Member Author

dyladan commented Aug 5, 2021

It is required. I've been wrestling with it all morning because the instrumentation loader doesn't like the parameterized types. It actually turns out it's been broken since forever because the InstrumentationBase doesn't pass the T type so it is always any.

@Flarna
Copy link
Member

Flarna commented Aug 5, 2021

Well, it was not really broken. As indicated in #2256 the base class has no real need for T - it passes it through only. The relevant type checking happens only in the concrete class.

@github-actions
Copy link

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Nov 15, 2021
@github-actions
Copy link

This PR was closed because it has been stale for 14 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InstrumentationAbstract#getConfig should return the type of the concrete instrumentation
4 participants