Skip to content

Commit a7454cd

Browse files
chore: add InstrumentationConnection to avoid as any casts
1 parent dca45c3 commit a7454cd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/instrumentation-amqplib/src/amqplib.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
CONNECTION_ATTRIBUTES,
6666
getConnectionAttributesFromServer,
6767
getConnectionAttributesFromUrl,
68+
InstrumentationConnection,
6869
InstrumentationConsumeChannel,
6970
InstrumentationConsumeMessage,
7071
InstrumentationMessage,
@@ -254,11 +255,11 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
254255
this,
255256
url,
256257
socketOptions,
257-
function (this: unknown, err, conn: Connection) {
258+
function (this: unknown, err, conn: InstrumentationConnection) {
258259
if (err == null) {
259260
const urlAttributes = getConnectionAttributesFromUrl(url);
260261
const serverAttributes = getConnectionAttributesFromServer(conn);
261-
(conn as any)[CONNECTION_ATTRIBUTES] = {
262+
conn[CONNECTION_ATTRIBUTES] = {
262263
...urlAttributes,
263264
...serverAttributes,
264265
};

packages/instrumentation-amqplib/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ export const CONNECTION_ATTRIBUTES: unique symbol = Symbol(
4545
'opentelemetry.amqplib.connection.attributes'
4646
);
4747

48+
export type InstrumentationConnection = amqp.Connection & {
49+
[CONNECTION_ATTRIBUTES]?: Attributes;
50+
};
4851
export type InstrumentationPublishChannel = (
4952
| amqp.Channel
5053
| amqp.ConfirmChannel
51-
) & { connection: { [CONNECTION_ATTRIBUTES]: Attributes } };
54+
) & { connection: InstrumentationConnection };
5255
export type InstrumentationConsumeChannel = amqp.Channel & {
53-
connection: { [CONNECTION_ATTRIBUTES]: Attributes };
56+
connection: InstrumentationConnection;
5457
[CHANNEL_SPANS_NOT_ENDED]?: {
5558
msg: amqp.ConsumeMessage;
5659
timeOfConsume: HrTime;

0 commit comments

Comments
 (0)