diff --git a/v3/internal/connect_reply.go b/v3/internal/connect_reply.go index b5ffaf9fe..2e5484722 100644 --- a/v3/internal/connect_reply.go +++ b/v3/internal/connect_reply.go @@ -229,9 +229,9 @@ const ( // consumer. func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string { var afterURLRules string - if "" != input { + if input != "" { afterURLRules = reply.URLRules.Apply(input) - if "" == afterURLRules { + if afterURLRules == "" { return "" } } @@ -249,7 +249,7 @@ func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string { } afterNameRules := reply.TxnNameRules.Apply(beforeNameRules) - if "" == afterNameRules { + if afterNameRules == "" { return "" } @@ -266,6 +266,13 @@ const ( CustomEventHarvestsPerMinute = 5 ) +// IsConnectedToNewRelic returns true if the connect reply is a valid connect reply +// from a New Relic connect endpoint. This is determined by the presence of a RunID +// and an EntityGUID which the agent needs to send data to a collector. +func (r *ConnectReply) IsConnectedToNewRelic() bool { + return r != nil && r.RunID != "" && r.EntityGUID != "" +} + // MockConnectReplyEventLimits sets up a mock connect reply to test event limits // currently only verifies custom insights events func (r *ConnectReply) MockConnectReplyEventLimits(limits *RequestEventLimits) { diff --git a/v3/internal/connect_reply_test.go b/v3/internal/connect_reply_test.go index 0ef0deeed..87718c8c4 100644 --- a/v3/internal/connect_reply_test.go +++ b/v3/internal/connect_reply_test.go @@ -184,3 +184,17 @@ func TestDefaultEventHarvestConfigJSON(t *testing.T) { t.Errorf("DefaultEventHarvestConfig does not match expected valued:\nExpected:\t%s\nActual:\t\t%s", expect, string(js)) } } + +func TestConnectReply_IsConnectedToNewRelic(t *testing.T) { + reply := ConnectReplyDefaults() + if reply.IsConnectedToNewRelic() { + t.Error("Connect Reply Defaults should not be considered connected to New Relic") + } + + reply = ConnectReplyDefaults() + reply.RunID = "foo" + reply.EntityGUID = "bar" + if !reply.IsConnectedToNewRelic() { + t.Error("Connect Reply with RunID and EntityGUID should be considered connected to New Relic") + } +} diff --git a/v3/newrelic/secure_agent.go b/v3/newrelic/secure_agent.go index 86aa8390b..457430cb4 100644 --- a/v3/newrelic/secure_agent.go +++ b/v3/newrelic/secure_agent.go @@ -43,7 +43,7 @@ func (app *Application) RegisterSecurityAgent(s securityAgent) { if app != nil && app.app != nil && s != nil { secureAgent = s run, _ := app.app.getState() - if run != nil { + if run.Reply.IsConnectedToNewRelic() { secureAgent.RefreshState(getLinkedMetaData(app.app)) } }