Skip to content

Commit dca45c3

Browse files
chore(instrumentation-amqp): bump amqplib typings
1 parent 215c2b5 commit dca45c3

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

package-lock.json

Lines changed: 9 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-amqplib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"devDependencies": {
5656
"@opentelemetry/api": "^1.3.0",
5757
"@opentelemetry/contrib-test-utils": "^0.49.0",
58-
"@types/amqplib": "^0.5.17",
58+
"@types/amqplib": "^0.10.7",
5959
"@types/lodash": "4.14.199",
6060
"@types/mocha": "10.0.10",
6161
"@types/node": "18.18.14",

packages/instrumentation-amqplib/src/amqplib.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
getConnectionAttributesFromServer,
6767
getConnectionAttributesFromUrl,
6868
InstrumentationConsumeChannel,
69+
InstrumentationConsumeMessage,
6970
InstrumentationMessage,
7071
InstrumentationPublishChannel,
7172
isConfirmChannelTracing,
@@ -256,14 +257,7 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
256257
function (this: unknown, err, conn: Connection) {
257258
if (err == null) {
258259
const urlAttributes = getConnectionAttributesFromUrl(url);
259-
// the type of conn in @types/amqplib is amqp.Connection, but in practice the library send the
260-
// `serverProperties` on the `conn` and not in a property `connection`.
261-
// I don't have capacity to debug it currently but it should probably be fixed in @types or
262-
// in the package itself
263-
// currently setting as any to calm typescript
264-
const serverAttributes = getConnectionAttributesFromServer(
265-
conn as any
266-
);
260+
const serverAttributes = getConnectionAttributesFromServer(conn);
267261
(conn as any)[CONNECTION_ATTRIBUTES] = {
268262
...urlAttributes,
269263
...serverAttributes,
@@ -402,7 +396,7 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
402396

403397
const patchedOnMessage = function (
404398
this: unknown,
405-
msg: InstrumentationMessage | null
399+
msg: InstrumentationConsumeMessage | null
406400
) {
407401
// msg is expected to be null for signaling consumer cancel notification
408402
// https://www.rabbitmq.com/consumer-cancel.html
@@ -724,7 +718,7 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
724718

725719
private callConsumeEndHook(
726720
span: Span,
727-
msg: ConsumeMessage,
721+
msg: InstrumentationMessage,
728722
rejected: boolean | null,
729723
endOperation: EndOperation
730724
) {

packages/instrumentation-amqplib/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export type InstrumentationConsumeChannel = amqp.Channel & {
6060
export type InstrumentationMessage = amqp.Message & {
6161
[MESSAGE_STORED_SPAN]?: Span;
6262
};
63+
export type InstrumentationConsumeMessage = amqp.ConsumeMessage & {
64+
[MESSAGE_STORED_SPAN]?: Span;
65+
};
6366

6467
const IS_CONFIRM_CHANNEL_CONTEXT_KEY: symbol = createContextKey(
6568
'opentelemetry.amqplib.channel.is-confirm-channel'
@@ -117,7 +120,7 @@ const extractConnectionAttributeOrLog = (
117120
};
118121

119122
export const getConnectionAttributesFromServer = (
120-
conn: amqp.Connection['connection']
123+
conn: amqp.Connection
121124
): Attributes => {
122125
const product = conn.serverProperties.product?.toLowerCase?.();
123126
if (product) {

packages/instrumentation-amqplib/test/amqplib-promise.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const CHANNEL_CLOSED_IN_TEST = Symbol(
6868
);
6969

7070
describe('amqplib instrumentation promise model', () => {
71-
let conn: amqp.Connection;
71+
let conn: amqp.ChannelModel;
7272
before(async function () {
7373
if (!shouldTest) {
7474
this.skip();

packages/instrumentation-amqplib/test/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { rabbitMqUrl } from './config';
3333

3434
describe('utils', () => {
3535
describe('getConnectionAttributesFromServer', () => {
36-
let conn: amqp.Connection;
36+
let conn: amqp.ChannelModel;
3737
before(async function () {
3838
if (!shouldTest) {
3939
this.skip();

0 commit comments

Comments
 (0)