-
Notifications
You must be signed in to change notification settings - Fork 552
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(amqplib): stop importing from amqplib
directly in compiled types
#1394
fix(amqplib): stop importing from amqplib
directly in compiled types
#1394
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1394 +/- ##
=======================================
Coverage 96.10% 96.10%
=======================================
Files 14 14
Lines 898 898
Branches 192 192
=======================================
Hits 863 863
Misses 35 35 |
Failed test is unrelated => lerna/lerna#3536 |
Thanks for reporting this.
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { AmqplibInstrumentationConfig, ConsumeMessage, Options, Replies } from './types';
import { InstrumentationConsumeChannel, InstrumentationPublishChannel } from './utils';
export declare class AmqplibInstrumentation extends InstrumentationBase {
protected _config: AmqplibInstrumentationConfig;
constructor(config?: AmqplibInstrumentationConfig);
setConfig(config?: AmqplibInstrumentationConfig): void;
protected init(): InstrumentationNodeModuleDefinition<unknown>;
private patchConnect;
private unpatchConnect;
private patchChannelModel;
private unpatchChannelModel;
private getConnectPatch;
private getChannelEmitPatch;
private getAckAllPatch;
private getAckPatch;
protected getConsumePatch(moduleVersion: string | undefined, original: Function): (this: InstrumentationConsumeChannel, queue: string, onMessage: (msg: ConsumeMessage | null) => void, options?: Options.Consume | undefined) => Promise<Replies.Consume>;
protected getConfirmedPublishPatch(moduleVersion: string | undefined, original: Function): (this: InstrumentationConsumeChannel, exchange: string, routingKey: string, content: Buffer, options?: Options.Publish | undefined, callback?: ((err: any, ok: Replies.Empty) => void) | undefined) => boolean;
protected getPublishPatch(moduleVersion: string | undefined, original: Function): (this: InstrumentationPublishChannel, exchange: string, routingKey: string, content: Buffer, options?: Options.Publish | undefined) => boolean;
private createPublishSpan;
private endConsumerSpan;
private endAllSpansOnChannel;
private callConsumeEndHook;
private checkConsumeTimeoutOnChannel;
}
//# sourceMappingURL=amqplib.d.ts.map I think a possible alternative fix will be to make the This will reduce the number of types we need to copy into the instrumentation code, which hopefully can make it a bit simpler to maintain. WDYT? @dotboris @Flarna |
moving more APIs to private sounds good. can be also done as followup depending on @dotboris motivation to rework this PR. |
If I got it right, that would mean we don't need to vendor any new amqplib type in |
I'll give making the methods private a shot to see how it goes. |
Previously the `amqplib.d.ts` file would import `./utils` (resolved as `utils.d.ts`) which imports `amqplib` directly. This can cause typechecking issues for users who don't use `amqplib` but still import the `amqplib` instrumentation through the node autoinstrumentation. The `./utils` import was generated by typescript because some of the protected methods have their argument and return types defined in `utils.ts`. Now that these methods are private, typescript no longer needs to generate the type information for those methods and omits the `./utils` import. Signed-off-by: Boris Bera <bbera@coveo.com>
Signed-off-by: Boris Bera <bbera@coveo.com>
Thanks for updating the PR. Do we still need the changes in |
I have reverted the additional types that I previously vendored. I've also removed a bunch of types that did not need to be there anymore. The rest of the vendored types are required because they're used as part of the instrumentation config. To answer your question more directly: yes we still need them. |
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.
LGTM, thanks for the fix 🙏
open-telemetry#1394) * fix(amqplib): make all instrumentation methods private Previously the `amqplib.d.ts` file would import `./utils` (resolved as `utils.d.ts`) which imports `amqplib` directly. This can cause typechecking issues for users who don't use `amqplib` but still import the `amqplib` instrumentation through the node autoinstrumentation. The `./utils` import was generated by typescript because some of the protected methods have their argument and return types defined in `utils.ts`. Now that these methods are private, typescript no longer needs to generate the type information for those methods and omits the `./utils` import. Signed-off-by: Boris Bera <bbera@coveo.com> * fix(amqplib): reduce the number of vendored types Signed-off-by: Boris Bera <bbera@coveo.com> --------- Signed-off-by: Boris Bera <bbera@coveo.com>
Which problem is this PR solving?
I started getting type checking errors when using node auto instrumentation:
Turns out that the compiled
utils.d.ts
importsamqplib
directly which breaks. This worked fine before #1320 which moved@types/amqplib
as a dev dependency. The PR adjusted most places whereamqplib
was imported but it missed one.Short description of the changes
getConsumePatch
,getConfirmedPublishPatch
andgetPublishPatch
inAmqplibInstrumentation
private. They used to be protected.types.ts
The generate
amqplib.d.ts
now looks like this: (no longer imports./utils
which importsamqplib
)