Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Fixes and Improvements #73

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
33 changes: 19 additions & 14 deletions components/NewRelicAgent/NRAgent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1427,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
Expand Down
2 changes: 1 addition & 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.4"/>
<field id="version" type="string" value="3.2.5"/>
<!-- Public Methods (wrapped) -->
<function name="NewRelicInit"/>
<function name="NewRelicVideoStart"/>
Expand Down
20 changes: 18 additions & 2 deletions components/NewRelicAgent/NRTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading