---
title: Roku Log Collection
description: Collect logs from your Roku channel.
breadcrumbs: Docs > Log Management > Log Collection and Integrations > Roku Log Collection
---

# Roku Log Collection

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

{% callout %}
# Important note for users on the following Datadog sites: app.datadoghq.com, us3.datadoghq.com, us5.datadoghq.com, app.datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com



{% alert level="info" %}
Roku Log collection is in Preview.
{% /alert %}


{% /callout %}

Send logs to Datadog from your Roku channel with [Datadog's `dd-sdk-roku` logging library](https://github.com/DataDog/dd-sdk-roku) and leverage the following features:

- Log to Datadog in JSON format natively.
- Add `context` and extra custom attributes to each log sent.
- Record real client IP addresses and User-Agents.
- Optimized network usage with automatic bulk posts.

## Setup{% #setup %}

1. Add the dependency to your project using `ROPM`, or download the [latest zip archive](https://github.com/DataDog/dd-sdk-roku/releases) and extract it to your project.

   ```shell
   ropm install datadog-roku
   ```

1. Initialize the library with your [Datadog client token](https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens) and Application ID generated when you create a new RUM application in the Datadog UI (see [Getting Started with Roku RUM Collection](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/roku/setup/?tab=us) for more information). For security reasons, you must use a client token: you cannot use [Datadog API keys](https://docs.datadoghq.com/account_management/api-app-keys/#api-keys) to configure the `dd-sdk-roku` library as they would be exposed client-side in the Roku channel's package.

For more information about setting up a client token, see the [client token documentation](https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens).

```
sub RunUserInterface(args as dynamic)
    screen = CreateObject("roSGScreen")
    scene = screen.CreateScene("MyScene")
    screen.show()

    datadogroku_initialize({
        clientToken: "<CLIENT_TOKEN>",
        applicationId: "<APPLICATION_ID>"
        site: "",
        env: "<ENV_NAME>",
        sessionSampleRate: 100, ' the percentage (integer) of sessions to track
        launchArgs: args
    })

    ' complete your channel setup here
end sub
```

(Optional) When writing your application, you can enable development logs by setting the `datadogVerbosity` attribute on the global node. All internal messages in the library with a priority equal to or higher than the provided level are then logged to your Roku device's telnet output:

```
' 0 = none; 1 = error; 2 = warning; 3 = info; 4 = verbose;
m.globalNode.addFields({ datadogVerbosity: 2 }) 
```

Send a custom log entry directly to Datadog with one of the following functions:

```
msg = "A log message"
m.global.datadogLogsAgent.callfunc("logOk", msg, {})
m.global.datadogLogsAgent.callfunc("logDebug", msg, {})
m.global.datadogLogsAgent.callfunc("logInfo", msg, {})
m.global.datadogLogsAgent.callfunc("logNotice", msg, {})
m.global.datadogLogsAgent.callfunc("logWarn", msg, {})
m.global.datadogLogsAgent.callfunc("logError", msg, {})
m.global.datadogLogsAgent.callfunc("logCritical", msg, {})
m.global.datadogLogsAgent.callfunc("logAlert", msg, {})
m.global.datadogLogsAgent.callfunc("logEmergency", msg, {})
```

(Optional) Provide an Associative Array alongside your log message to add attributes to the emitted log. Each entry of the AssocArray is added as an attribute.

```
 m.global.datadogLogsAgent.callfunc(
     "logInfo", 
     "Video started", 
     { video_id: 42, video_type: "advert"}
 )
```

## Batch collection{% #batch-collection %}

All the logs are first stored on the local device in batches. Each batch follows the intake specification. They are sent as soon as network is available. If the network is not available while your channel is opened, or if an upload of data fails, the batch is kept until it can be sent successfully.

To ensure the SDK doesn't use too much disk space, the data on the disk is automatically discarded if it gets too old.

**Note**: Before data is uploaded to Datadog, it is stored in cleartext in your channel's [cache directory](https://developer.roku.com/fr-fr/docs/developer-program/getting-started/architecture/file-system.md#cachefs), meaning that this data can't be read by other applications. The OS can evict the data at any time, which may result in data loss in some rare cases.

## Further Reading{% #further-reading %}

- [Source code for dd-sdk-roku](https://github.com/DataDog/dd-sdk-roku)
- [Learn how to explore your logs](https://docs.datadoghq.com/logs/explorer)
