forked from newrelic/node-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed amqplib instrumentation via ESM
- Loading branch information
1 parent
b917b3e
commit 70887b0
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import test from 'node:test' | ||
import assert from 'node:assert' | ||
import helper from '../../lib/agent_helper.js' | ||
import promiseResolvers from '../../lib/promise-resolvers.js' | ||
|
||
const agent = helper.instrumentMockedAgent({ | ||
attributes: { | ||
enabled: true | ||
} | ||
}) | ||
const params = { | ||
encoding_key: 'this is an encoding key', | ||
cross_process_id: '1234#4321' | ||
} | ||
agent.config._fromServer(params, 'encoding_key') | ||
agent.config._fromServer(params, 'cross_process_id') | ||
agent.config.trusted_account_ids = [1234] | ||
|
||
import amqpUtils from '../amqplib/amqp-utils.js' | ||
// const amqplib = await import('amqplib') | ||
import amqplib from 'amqplib' | ||
|
||
test('esm import does instrumentation', async () => { | ||
const { promise, resolve } = promiseResolvers() | ||
const { connection: conn, channel } = await amqpUtils.getChannel(amqplib) | ||
await channel.assertQueue('testQueue') | ||
|
||
test.after(async () => { | ||
helper.unloadAgent(agent) | ||
await conn.close() | ||
}) | ||
|
||
const exchange = amqpUtils.DIRECT_EXCHANGE | ||
|
||
await channel.assertExchange(exchange, 'direct') | ||
const { queue } = await channel.assertQueue('', { exclusive: true }) | ||
await channel.bindQueue(queue, exchange, 'consume-tx-key') | ||
await helper.runInTransaction(agent, async function (tx) { | ||
channel.publish(exchange, 'consume-tx-key', Buffer.from('hello')) | ||
const msg = await channel.get(queue) | ||
assert.ok(msg, 'should receive a message') | ||
const body = msg.content.toString('utf8') | ||
assert.equal(body, 'hello', 'should receive expected body') | ||
|
||
amqpUtils.verifyTransaction(tx, 'get') | ||
channel.ack(msg) | ||
tx.end() | ||
amqpUtils.verifyGet({ | ||
tx, | ||
exchangeName: exchange, | ||
routingKey: 'consume-tx-key', | ||
queue, | ||
assertAttr: true | ||
}) | ||
resolve() | ||
}) | ||
|
||
await promise | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
exports.config = { | ||
app_name: ['My Application'], | ||
license_key: 'license key here', | ||
logging: { | ||
level: 'trace', | ||
filepath: '../../../newrelic_agent.log' | ||
}, | ||
utilization: { | ||
detect_aws: false, | ||
detect_pcf: false, | ||
detect_azure: false, | ||
detect_gcp: false, | ||
detect_docker: false | ||
}, | ||
transaction_tracer: { | ||
enabled: true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "amqplib-esm-tests", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"private": true, | ||
"tests": [ | ||
{ | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"dependencies": { | ||
"amqplib": ">=0.5.0" | ||
}, | ||
"files": [ | ||
"issue-2663.test.mjs" | ||
] | ||
} | ||
], | ||
"dependencies": {} | ||
} |