From 9138036d2c1f7dd5048c5ac6fae7c461d67df960 Mon Sep 17 00:00:00 2001 From: Andreu Date: Fri, 12 Jul 2024 12:31:48 +0200 Subject: [PATCH 1/4] Add instrumentation attributes to metrics and logs. --- components/NewRelicAgent/NRTask.brs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/NewRelicAgent/NRTask.brs b/components/NewRelicAgent/NRTask.brs index 13c2afb..4cda904 100644 --- a/components/NewRelicAgent/NRTask.brs +++ b/components/NewRelicAgent/NRTask.brs @@ -11,12 +11,28 @@ sub init() end sub function nrPushSamples(samples as Object, endpoint as String, sampleType as String) as Object - 'Metric API requires a specific format + 'Common attributes, only used with Metric and Log API. Event API uses a different format, without a common object, and these + 'properties are inserted in every event. + commonObject = { + "attributes": { + "instrumentation.provider": "media", + "instrumentation.name": "roku", + "instrumentation.version": m.top.getParent().version + } + } + 'Use a different format for Metric API and Log API if sampleType = "metric" metricsModel = [{ - "metrics": samples + "metrics": samples, + "common": commonObject, }] samples = metricsModel + else if sampleType = "log" + logsModel = [{ + "logs": samples, + "common": commonObject, + }] + samples = logsModel end if jsonString = FormatJson(samples) From b4b6d24639df0f6cd8b58622b7efbf99bccf5d5a Mon Sep 17 00:00:00 2001 From: Andreu Date: Fri, 12 Jul 2024 15:21:43 +0200 Subject: [PATCH 2/4] Fix overwriting of custom attributes. --- components/NewRelicAgent/NRAgent.brs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/NewRelicAgent/NRAgent.brs b/components/NewRelicAgent/NRAgent.brs index d8c4cd4..2fe69ce 100644 --- a/components/NewRelicAgent/NRAgent.brs +++ b/components/NewRelicAgent/NRAgent.brs @@ -253,6 +253,7 @@ end function function nrSendCustomEvent(eventType as String, actionName as String, attr = invalid as Object) as Void nrLog("nrSendCustomEvent") ev = nrCreateEvent(eventType, actionName) + ev = nrAddCustomAttributes(ev) if attr <> invalid ev.Append(attr) end if @@ -266,6 +267,7 @@ end function function nrSendVideoEvent(actionName as String, attr = invalid) as Void ev = nrCreateEvent("RokuVideo", actionName) ev = nrAddVideoAttributes(ev) + ev = nrAddCustomAttributes(ev) if type(attr) = "roAssociativeArray" ev.Append(attr) end if @@ -704,13 +706,12 @@ function nrCreateEvent(eventType as String, actionName as String) as Object if eventType <> invalid and eventType <> "" then ev["eventType"] = eventType ev["timestamp"] = FormatJson(nrTimestamp()) - ev = nrAddAttributes(ev) + ev = nrAddBaseAttributes(ev) return ev end function -function nrAddAttributes(ev as Object) as Object - +function nrAddBaseAttributes(ev as Object) as Object 'Add default custom attributes for instrumentation' ev.AddReplace("instrumentation.provider", "media") ev.AddReplace("instrumentation.name", "roku") @@ -770,17 +771,19 @@ function nrAddAttributes(ev as Object) as Object ev.AddReplace("appBuild", appbuild) 'Uptime ev.AddReplace("uptime", Uptime(0)) - 'Add custom attributes + 'Time Since Load + date = CreateObject("roDateTime") + ev.AddReplace("timeSinceLoad", date.AsSeconds() - m.nrInitTimestamp) + + return ev +end function + +function nrAddCustomAttributes(ev as Object) as Object genCustomAttr = m.nrCustomAttributes["GENERAL_ATTR"] if genCustomAttr <> invalid then ev.Append(genCustomAttr) actionName = ev["actionName"] actionCustomAttr = m.nrCustomAttributes[actionName] if actionCustomAttr <> invalid then ev.Append(actionCustomAttr) - - 'Time Since Load - date = CreateObject("roDateTime") - ev.AddReplace("timeSinceLoad", date.AsSeconds() - m.nrInitTimestamp) - return ev end function @@ -868,6 +871,9 @@ function nrSendBandwidth(info as Object) as Void nrSendCustomEvent("RokuSystem", "BANDWIDTH_MINUTE", attr) end function +'TODO: Testing endpoint. If nrRegion is not US or EU, use it as endpoint. Deprecate the "TEST" region and "m.testServer". +' We could even pass an object containing different endpoints for events, metrics and logs. + function nrEventApiUrl() as String if m.nrRegion = "US" return "https://insights-collector.newrelic.com/v1/accounts/" + m.nrAccountNumber + "/events" @@ -1167,6 +1173,7 @@ function nrSendRAFEvent(actionName as String, ctx as Dynamic, attr = invalid) as ev = nrCreateEvent("RokuVideo", actionName) ev = nrAddVideoAttributes(ev) ev = nrAddRAFAttributes(ev, ctx) + ev = nrAddCustomAttributes(ev) if type(attr) = "roAssociativeArray" ev.Append(attr) end if From 152724083ac9a17ee456a5612d4214060c369714 Mon Sep 17 00:00:00 2001 From: Andreu Date: Mon, 15 Jul 2024 13:22:53 +0200 Subject: [PATCH 3/4] Do not require position = 0 to send CONTENT_START. --- components/NewRelicAgent/NRAgent.brs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/NewRelicAgent/NRAgent.brs b/components/NewRelicAgent/NRAgent.brs index 2fe69ce..e6a172b 100644 --- a/components/NewRelicAgent/NRAgent.brs +++ b/components/NewRelicAgent/NRAgent.brs @@ -1434,11 +1434,9 @@ function nrStateTransitionPlaying() as Void shouldSendStart = m.nrIsInitialBuffering nrSendBufferEnd() - if m.nrVideoObject.position = 0 - if lastSrc = currentSrc OR m.nrVideoObject.contentIsPlaylist = false - 'Send Start only if initial start not sent already - if shouldSendStart then nrSendStart() - end if + if lastSrc = currentSrc OR m.nrVideoObject.contentIsPlaylist = false + 'Send Start only if initial start not sent already + if shouldSendStart then nrSendStart() end if end if end function From 3c6f1f5d85119bff4f945fcc63f54885aea466c9 Mon Sep 17 00:00:00 2001 From: Andreu Date: Tue, 16 Jul 2024 15:51:57 +0200 Subject: [PATCH 4/4] Update version and changelog. --- CHANGELOG.md | 7 +++++++ components/NewRelicAgent/NRAgent.xml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df5a68..0d44222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # CHANGELOG All notable changes to this project will be documented in this file. +## [3.2.5] - 2024/07/16 +### Add +- Instrument attributes for metrics and logs. +### Fix +- Allow overwriting custom attributes. +- Send `CONTENT_START` when resuming a video. + ## [3.2.4] - 2024/01/10 ### Add - Memory attributes. diff --git a/components/NewRelicAgent/NRAgent.xml b/components/NewRelicAgent/NRAgent.xml index d2d619a..ac5a5b3 100644 --- a/components/NewRelicAgent/NRAgent.xml +++ b/components/NewRelicAgent/NRAgent.xml @@ -13,7 +13,7 @@ - +