Skip to content

Commit

Permalink
Improve NRTask console logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
asllop committed Sep 1, 2023
1 parent 0f8d7a2 commit 1783598
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

## [3.2.2] - 2023/09/01
### Update
- Improve NRTask console logging, reducing task rendezvous.

## [3.2.1] - 2023/06/06
### Add
- Instrumentation specific tags
Expand Down
4 changes: 4 additions & 0 deletions components/NewRelicAgent/NRAgent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ function nrActivateLogging(state as Boolean) as Void
m.nrLogsState = state
end function

function nrCheckLoggingState() as Boolean
return m.nrLogsState
end function

function nrLog(msg as Dynamic) as Void
if m.nrLogsState = true
if type(msg) = "roArray"
Expand Down
3 changes: 2 additions & 1 deletion components/NewRelicAgent/NRAgent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<interface>
<!-- Properties -->
<field id="version" type="string" value="3.2.1"/>
<field id="version" type="string" value="3.2.2"/>
<!-- Public Methods (wrapped) -->
<function name="NewRelicInit"/>
<function name="NewRelicVideoStart"/>
Expand Down Expand Up @@ -46,6 +46,7 @@
<function name="nrSendSummaryMetric"/>
<!-- Internal Methods (not wrapped, but used from the outside by some internal components) -->
<function name="nrActivateLogging"/>
<function name="nrCheckLoggingState"/>
<function name="nrLog"/>
<function name="nrExtractAllSamples"/>
<function name="nrGetBackAllSamples"/>
Expand Down
22 changes: 14 additions & 8 deletions components/NewRelicAgent/NRTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

sub init()
m.top.functionName = "nrTaskMain"
m.loggingState = false
end sub

function nrPushSamples(samples as Object, endpoint as String, sampleType as String) as Object
Expand Down Expand Up @@ -37,24 +38,24 @@ function nrPushSamples(samples as Object, endpoint as String, sampleType as Stri
return msg.GetResponseCode()
else
'Timeout, cancel transfer and return error code
m.nr.callFunc("nrLog", "-- nrPushSamples: timeout, cancel request and return --")
nrLog("-- nrPushSamples: timeout, cancel request and return --")
urlReq.AsyncCancel()
return 0
end if
end function

function nrEventProcessor() as Void
m.nr.callFunc("nrLog", "-- nrEventProcessor at URL " + m.eventApiUrl)
nrLog("-- nrEventProcessor at URL " + m.eventApiUrl)
nrSampleProcessor("event", m.eventApiUrl)
end function

function nrLogProcessor() as Void
m.nr.callFunc("nrLog", "-- nrLogProcessor at URL " + m.logApiUrl)
nrLog("-- nrLogProcessor at URL " + m.logApiUrl)
nrSampleProcessor("log", m.logApiUrl)
end function

function nrMetricProcessor() as Void
m.nr.callFunc("nrLog", "-- nrMetricProcessor at URL " + m.metricApiUrl)
nrLog("-- nrMetricProcessor at URL " + m.metricApiUrl)
nrSampleProcessor("metric", m.metricApiUrl)
end function

Expand All @@ -68,7 +69,7 @@ function nrSampleProcessor(sampleType as String, endpoint as String) as Void
if samples.Count() > 0
res = nrPushSamples(samples, endpoint, sampleType)
if isStatusErr(res)
m.nr.callFunc("nrLog", "-- nrSampleProcessor (" + sampleType + "): FAILED with code " + Str(res) + ", retry later --")
nrLog("-- nrSampleProcessor (" + sampleType + "): FAILED with code " + Str(res) + ", retry later --")
if res = 429 or res = 408 or res = 503
'Increasing harvest cycle duration in case of error 408 or 503
'Refer: https://docs.newrelic.com/docs/data-apis/ingest-apis/event-api/introduction-event-api/#errors-submission
Expand All @@ -77,7 +78,7 @@ function nrSampleProcessor(sampleType as String, endpoint as String) as Void
m.nr.callFunc("nrReqErrorTooLarge", sampleType)
else if res = 403
'Handle 403 error in scenario of missing invalid key error from NR collector, printing the log and clearing the buffer
m.nr.callFunc("nrLog", "-- missingInvalidLicenseKey (" + sampleType + "): FAILED with code " + Str(res))
nrLog("-- missingInvalidLicenseKey (" + sampleType + "): FAILED with code " + Str(res))
m.nr.callFunc("nrReqOk", sampleType)
return
end if
Expand All @@ -100,20 +101,25 @@ function nrTaskMain() as Void
if m.eventApiUrl = "" then m.eventApiUrl = m.top.eventApiUrl
if m.logApiUrl = "" then m.logApiUrl = m.top.logApiUrl
if m.metricApiUrl = "" then m.metricApiUrl = m.top.metricApiUrl
m.loggingState = m.nr.callFunc("nrCheckLoggingState")
end if
m.nr.callFunc("nrLog", "---- Running NRTask ---- " + m.sampleType)
nrLog("---- Running NRTask ---- " + m.sampleType)
if m.sampleType = "event"
nrEventProcessor()
else if m.sampleType = "log"
nrLogProcessor()
else if m.sampleType = "metric"
nrMetricProcessor()
end if
m.nr.callFunc("nrLog", "---- Ended running NRTask ---- " + m.sampleType)
nrLog("---- Ended running NRTask ---- " + m.sampleType)
end function

function onConfigUpdate() as Void
m.eventApiUrl = m.top.eventApiUrl
m.logApiUrl = m.top.logApiUrl
m.metricApiUrl = m.top.metricApiUrl
end function

function nrLog(msg as Dynamic) as Void
if m.loggingState = true then m.nr.callFunc("nrLog", msg)
end function

0 comments on commit 1783598

Please sign in to comment.