Skip to content

Commit

Permalink
Add support for no user:pass in amqp url
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Sep 9, 2024
1 parent c0079fc commit 2454e14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
17 changes: 11 additions & 6 deletions v3/integrations/nramqp/nramqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ func createProducerSegment(exchange, key string) *newrelic.MessageProducerSegmen
}

func GetHostAndPortFromURL(url string) (string, string) {
// url is of format amqp://user:password@host:port
// extract host from url after "@" symbol
parts := strings.Split(url, "@")
if len(parts) != 2 {
return "", ""
// url is of format amqp://user:password@host:port or amqp://host:port
var hostPortPart string

// extract the part after "@" symbol, if present
if parts := strings.Split(url, "@"); len(parts) == 2 {
hostPortPart = parts[1]
} else {
// assume the whole url after "amqp://" is the host:port part
hostPortPart = strings.TrimPrefix(url, "amqp://")
}
strippedURL := strings.Split(parts[1], ":")

// split the host:port part
strippedURL := strings.Split(hostPortPart, ":")
if len(strippedURL) != 2 {
return "", ""
}
Expand Down
18 changes: 11 additions & 7 deletions v3/integrations/nramqp/nramqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ func TestCreateProducerSegment(t *testing.T) {

}

func TestPublishWithContext(t *testing.T) {
app := createTestApp()
txn := app.StartTransaction("test")
defer txn.End()

}

func TestHostAndPortParsing(t *testing.T) {
app := createTestApp()
txn := app.StartTransaction("test")
Expand All @@ -101,6 +94,17 @@ func TestHostAndPortParsing(t *testing.T) {
"host",
"port",
},
{
"amqp://host:port",
"host",
"port",
},
{
"aaa://host:port",
"",
"",
},

{
"amqp://user:password@host",
"",
Expand Down

0 comments on commit 2454e14

Please sign in to comment.