Skip to main content

API reference

Every entry point the SDK exposes, grouped by topic and alphabetical within each group.

Calling the SDK​

Apart from coralogix_roku_initialize(), which is an ordinary function, every call below is reached through the node the SDK attaches to m.global:

m.global.cxRum.callfunc("<name>", <arguments>)

The name is a string argument to callfunc, which is why these entry points carry no parentheses. m.global.cxRum is invalid before coralogix_roku_initialize() and after shutdown, and a callfunc on invalid crashes the thread, so guard any call that can run outside that window. Every call returns immediately; the SDK builds and sends records on its own thread. After shutdown, every other call is ignored.

Warning

reportErrorLog and reportError are not interchangeable. reportErrorLog writes a log at error severity. reportError writes an error event, a different record type that also marks the session as having errored. Choosing the wrong one puts the data in the wrong place in Coralogix.

Lifecycle methods​

coralogix_roku_initialize​

Starts the SDK. Call it in main.brs straight after screen.show(), before any other entry point. Calling it a second time changes nothing and warns on the console.

coralogix_roku_initialize(options, globalNode)
ArgumentTypeRequiredDescription
optionsObjectYesThe SDK's configuration. See configuration options
globalNodeNodeYesscreen.getGlobalNode(). The SDK attaches itself here as m.global.cxRum

Returns

TypeDescription
Booleantrue when the SDK started, or when it was already running. false when an option failed validation, in which case the SDK sends nothing and the console names the option

shutdown​

Stops the SDK. Both its threads exit, records still queued are dropped, and m.global.cxRum becomes invalid. After shutdown, every other call is ignored.

m.global.cxRum.callfunc("shutdown")

Returns

void

Managing logs​

The SDK has a function to report logs of each severity level. Every call below records a log based on its assigned severity level.

Severity levels​

A severity level determines the urgency of a log line fom least to most urgent. Levels appear as values included in the record sent to Coralogix.

FieldValueSeverity
DEBUG1Debug
VERBOSE2Verbose
INFO3Info
WARN4Warning
ERROR5Error
CRITICAL6Critical

When the severity is known in advance, call the appropriate function. When the level is decided at runtime, use getSeverity and pass one to reportLog.

getSeverity​

Returns the severity levels to pass to reportLog at runtime.

m.global.cxRum.callfunc("getSeverity")

Returns

TypeDescription
ObjectOne field per severity level

reportCritical​

Records a log at Critical severity: a failure that stops the channel doing its job.

m.global.cxRum.callfunc("reportCritical", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

reportDebug​

Records a log at Debug severity: detail useful only while developing the channel.

m.global.cxRum.callfunc("reportDebug", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

reportErrorLog​

Records a log at Error severity: a failure worth investigating, recorded as a log.

m.global.cxRum.callfunc("reportErrorLog", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

reportInfo​

Records a log at Info severity: ordinary milestones, such as a screen shown or content loaded.

m.global.cxRum.callfunc("reportInfo", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

reportLog​

Records a log at a severity decided at runtime. Use a named method above when the level is known at the call site.

m.global.cxRum.callfunc("reportLog", severity, message, options)
ArgumentTypeRequiredDescription
severityIntegerYesA level from getSeverity, 1 through 6. An out-of-range or non-numeric value is recorded as Info and warned about on the console
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }, as for the named level methods

Returns

void

reportVerbose​

Records a log at Verbose severity: high-volume tracing you would not keep on in production.

m.global.cxRum.callfunc("reportVerbose", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

reportWarn​

Records a log at Warning severity: something recoverable that a viewer may have noticed.

m.global.cxRum.callfunc("reportWarn", message, options)
ArgumentTypeRequiredDescription
messageStringYesThe line to record. Truncated at 2048 characters
optionsObjectNo{ data, labels }. data is a free-form block dropped whole over 3584 characters; labels apply to this record only

Returns

void

Reporting errors​

reportError​

Reports an error event: a caught exception, an object you build, or a message. Marks the session as having errored.

m.global.cxRum.callfunc("reportError", error, options)
ArgumentTypeRequiredDescription
errorObject or StringYesA caught exception, an object carrying message and errorType, or a plain message string
optionsObjectNo{ data, labels }. data is dropped whole over 2048 characters, tighter than a log's

Returns

void

Managing views​

endView​

Clears the current view. Records that follow carry an empty view name until the next startView.

m.global.cxRum.callfunc("endView")

Returns

void

startView​

Names the screen the viewer is on. Every record that follows carries the name, until the next startView or an endView.

m.global.cxRum.callfunc("startView", viewName)
ArgumentTypeRequiredDescription
viewNameStringYesThe screen name to attach to records. Replaces the current view

Returns

void

Managing labels​

getLabels​

Returns the channel-wide labels as they currently stand. Labels passed to a single call are not included.

m.global.cxRum.callfunc("getLabels")

Returns

TypeDescription
ObjectThe merged labels from coralogix_roku_initialize() and every setLabels since

setLabels​

Merges labels into the channel-wide set. Keys it names are added or replaced; the rest are kept.

m.global.cxRum.callfunc("setLabels", labels)
ArgumentTypeRequiredDescription
labelsObjectYesKeys with string, number or boolean values. Ignored whole if the merged set exceeds 512 serialized characters

Returns

void

Managing user context​

setUserContext​

Replaces the viewer every record from now on describes. A field you don't pass is cleared, so {} signs the viewer out.

m.global.cxRum.callfunc("setUserContext", user)
ArgumentTypeRequiredDescription
userObjectYesuser_id, user_name, user_email, account_id, account_name (strings) and user_metadata (an object). An unknown field or a wrong type refuses the whole call. So does exceeding 512 serialized characters

Returns

void. The console reports a rejected call.

Managing sessions​

createNewSession​

Ends the current session and starts a new one, for example when a viewer signs out.

m.global.cxRum.callfunc("createNewSession")

Returns

TypeDescription
StringThe ID of the new session

getSessionId​

Returns the ID of the current session, without extending it or starting a new one.

m.global.cxRum.callfunc("getSessionId")

Returns

TypeDescription
StringThe session ID, or "" once the session has ended and the next record has not yet started a new one

reportUserActivity​

Refreshes the session's idle timer so it doesn't end prematurely. By default, sessions where the user does not press any key time out after 2 hours. Call reportUserActivity to prevent the session from ending, for example during video playback, which produces no key pressesv of its own.

m.global.cxRum.callfunc("reportUserActivity")

The function refreshes the idle timer only. The four-hour total session limit still applies, so a session ends at four hours however often you call this function.

The SDK applies no throttling of its own. The call sends no record and makes no network request. It reads the session, stamps it with the current time and returns, so calling it on every playback position update is cheap.

When the session already ended, calling this function starts a new session and returns the new session ID. Use this value instead of reading the session ID afterwards.

Returns

TypeDescription
StringID of the session the activity belongs to. When the previous session had already ended, a new session ID.

Reporting network requests​

reportNetworkRequest​

Reports one HTTP request the SDK did not observe itself. Requests made with CxUrlTransfer are reported automatically and need no call.

m.global.cxRum.callfunc("reportNetworkRequest", request)
ArgumentTypeRequiredDescription
request.methodStringYesThe HTTP method, such as GET
request.urlStringYesThe request URL. A request with no usable URL is not reported
request.statusCodeIntegerYesThe HTTP status. 0 or below means no response arrived
request.durationMsIntegerYesHow long the request took, in milliseconds
request.startTimeLongIntegerNoWhen the request started, epoch milliseconds. Defaults to now
request.failureReasonStringNoThe transport's reason text, when the request failed
request.responseContentLengthIntegerNoResponse size in bytes

Returns

void

Reading SDK state​

getConfig​

Returns the configuration the SDK resolved at start-up, with defaults filled in.

m.global.cxRum.callfunc("getConfig")

Returns

TypeDescription
ObjectThe resolved configuration

getDeviceContext​

Returns the device description the SDK gathered at start-up and attaches to every record.

m.global.cxRum.callfunc("getDeviceContext")

Returns

TypeDescription
ObjectThe device block as sent

getDeviceState​

Returns the device readings the SDK takes per record, rather than once at start-up.

m.global.cxRum.callfunc("getDeviceState")

Returns

TypeDescription
ObjectThe current network, memory and uptime readings

getSessionContext​

Returns the session block the SDK attaches to every record.

m.global.cxRum.callfunc("getSessionContext")

Returns

TypeDescription
ObjectThe session block as sent

Observing delivery​

Observe the cxExportResult field to show or log whether your telemetry is reaching Coralogix.

m.global.cxRum.observeField("cxExportResult", "onExportResult")

sub onExportResult(event as object)
result = event.getData()
print "post "; result.status; " — "; result.chars; " chars"
end sub

The field carries one delivery attempt:

FieldTypeDescription
statusIntegerThe HTTP status of the upload. 0 or below means no response arrived at all
charsIntegerThe size of the payload sent, in characters

onExportResult runs on the render thread, so calling back into the SDK from inside it is safe.

Last updated on