-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Updated amqplib instrumentation to properly parse host/port from…
… connect (#2461)
- Loading branch information
Showing
7 changed files
with
166 additions
and
94 deletions.
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
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
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,59 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const { parseConnectionArgs } = require('../../../../lib/instrumentation/amqplib/utils') | ||
|
||
test('should parse host port if connection args is a string', () => { | ||
const stub = { | ||
isString() { | ||
return true | ||
} | ||
} | ||
const params = parseConnectionArgs({ shim: stub, connArgs: 'amqp://host:5388/' }) | ||
assert.equal(params.host, 'host') | ||
assert.equal(params.port, 5388) | ||
}) | ||
|
||
test('should parse host port if connection is an object', () => { | ||
const stub = { | ||
isString() { | ||
return false | ||
} | ||
} | ||
const params = parseConnectionArgs({ shim: stub, connArgs: { hostname: 'host', port: 5388 } }) | ||
assert.equal(params.host, 'host') | ||
assert.equal(params.port, 5388) | ||
}) | ||
|
||
test('should default port to 5672 if protocol is amqp:', () => { | ||
const stub = { | ||
isString() { | ||
return false | ||
} | ||
} | ||
const params = parseConnectionArgs({ | ||
shim: stub, | ||
connArgs: { hostname: 'host', protocol: 'amqp' } | ||
}) | ||
assert.equal(params.host, 'host') | ||
assert.equal(params.port, 5672) | ||
}) | ||
|
||
test('should default port to 5671 if protocol is amqps:', () => { | ||
const stub = { | ||
isString() { | ||
return false | ||
} | ||
} | ||
const params = parseConnectionArgs({ | ||
shim: stub, | ||
connArgs: { hostname: 'host', protocol: 'amqps' } | ||
}) | ||
assert.equal(params.host, 'host') | ||
assert.equal(params.port, 5671) | ||
}) |
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