Getting started

This article includes code samples. If you would like to see them for a specific language, select a language now.

Moonsense Network Telemetry is an easy way to collect network telemetry data in conjunction with sensor data through the SDK or all by itself. This data can then be fed into an a mechanism for determining many things. For example, it can be used to determine the user's operating system or for determining if a proxy server is being used.

What is captured?

Calling the regional network telemetry endpoints will trigger the Moonsense cloud to capture network interaction between the end user and the Moonsense cloud. The Moonsense cloud captures all packet information and associates it with a given Session. This information includes the TCP handshake, TLS handshake, and the application data. This data is accessible through the Moonsense Console as a PCAP file.

Capturing with the SDK

**Feature in Development**

Network Telemetry capture can be done directly in the Moonsense SDK. The SDK will automatically handle region resolution and connect to the nearest Moonsense Network Telemetry server. The telemetry data will be recorded in the same session as other sensors, if so configured, or can be recorded in a session of it's own.

Add the network telemetry configuration to the Session start command to include Network Telemetry capture in your Session.

Sample SDK Request

**Code Subject to Change**

// Creates a session that will capture network telemetry val session = Moonsense.startSession( ..., networkTelemetryConfig = NetworkTelemetryConfig() )
// Creates a session that will capture network telemetry Moonsense.startSession(..., NetworkTelemetryConfig())
// Creates a session that will capture network telemetry const session = moonsenseSdk.startSession({ ..., networkTelemetryConfig: {ip: true} });

Capturing without the SDK

Network Telemetry capture can also be done without the use of the Moonsense SDK. This method uses a specific URL to point users at the Moonsense cloud that will trigger the creation of a new session, redirect the user to their closest region, and capture network telemetry data. This method can be called directly through a standard HTTP request or by including the URL as the source in an HTML <img src="<Moonsense Telemetry URL>" /> tag.

The URL to use is associated with the App within Moonsense being used to capture the data. This will correctly associate captured network telemetry data with the App you want to associate it with.

Get the URL to use by going to the Moonsense Console, navigating to your Apps, and selecting the App you would like to use. The icons in the Packets column can be used to copy the needed URL.

Screen Shot packet url 2022 08 30

Clicking on the left icon copies the URL to capture network telemetry through an HTTP request and will return a JSON response with the created SessionId. Clicking on the right icon copies the URL to capture network telemetry through an <img /> tag which will return a 1x1 pixel transparent image.

Sample JS fetch Request

// Fetch request to capture network telemetry fetch("${myPublicAppToken}", { redirect: 'follow', }) .then((resp) => resp.json()) .then((data) => console.log('Created Session', data.sessionId)) .catch((error) => console.log('Network Telemetry Catpure Error', error));

It is important to include redirect: 'follow' to ensure that the request follows the redirect to the closest Moonsense Network Telemetry region.