Skip to Content
Xeonr Developer Docs

Devices

Send logs, metrics, events and errors from apps and devices you ship — desktop, mobile, TV, embedded, daemons on someone else's hardware — with a short-lived device token.

A device sends to Lantern's client ingest, https://in.lntrn.dev, into one of your org's client projects, with a token your own backend minted for it (see Authentication). Its earlier names, in.prod.wtf and telemetry.xeonr.io, are retired; an app that still names one must move to in.lntrn.dev, the SDK's default.

For a web page, which cannot keep a credential at all, see Browsers and React. For servers and clusters you run, see Server telemetry.

Lantern took over from forest. The fk_ API keys and the tokens are unchanged, so a token minted for forest verifies here. @xeonr/forest became @xeonr/lantern-device, which is now published as @lntrn/device (from 1.2.0, with the same API). From 1.0 it sends OpenTelemetry (OTLP) to the client ingest, https://in.lntrn.dev by default from 1.1.1. Forest's own batch format (POST /v1/ingest) is no longer accepted, so upgrade to 1.x; it is a version bump.

Already on OpenTelemetry? Add this

An app (Node, React Native, Electron, a desktop or TV app) already running an OpenTelemetry SDK keeps it. Nothing on the wire is only the device SDKs' to produce. The add-on gives the stock exporters a device token that renews itself, and, if you want it, the API below over your own providers:

npm install @lntrn/device
import { deviceTokenHeaders, OtelLantern, INGEST_URL } from "@lntrn/device/otel";

// One factory for every exporter, so they share one token.
const headers = deviceTokenHeaders(async () => (await fetch("/telemetry-token").then((r) => r.json())).token);

new OTLPTraceExporter({ url: `${INGEST_URL}/v1/traces`, headers });
new OTLPLogExporter({ url: `${INGEST_URL}/v1/logs`, headers });
new OTLPMetricExporter({ url: `${INGEST_URL}/v1/metrics`, headers });

// Optional: lantern.info / error / metric / event through your providers.
const lantern = new OtelLantern({ loggerProvider, meterProvider, release: "1.4.2" });

The exporters are the stock @opentelemetry/exporter-{trace,logs,metrics}-otlp-{proto,http}. They call headers before every export.

How the token is cached:

  • the token is reused until a minute before its exp, or four fifths of the way through a shorter lifetime;
  • concurrent exports share one fetch;
  • a failed fetch keeps the old token while it is still valid.

What OtelLantern sends. The same records as Lantern: errors with the exception.* attributes, events with event.name, counters and gauges. Batching and delivery are your processors' business.

What the entry pulls in. @lntrn/device/otel imports OpenTelemetry for types only, and the default entry still has no dependencies.

Other runtimes:

  • Node servers (node --import): use @lntrn/otel, which takes a device token the same way.
  • Go: use lntrn.Setup with a Token func.
  • Anything else: point its OTLP/HTTP exporter at https://in.lntrn.dev with Authorization: Bearer <device token>, and replace the header before the token expires.

Sending from JavaScript

npm install @lntrn/device
import { Lantern } from "@lntrn/device";

const lantern = new Lantern({ token, release: "1.4.2" });

lantern.info("user signed in");
lantern.warn("tunnel flapped", { gateway: "gw-b" });
lantern.metric("fps", 59.5);
lantern.event("checkout_completed", { plan: "pro" });

It runs anywhere with fetch and Web Crypto — browsers, Node 20+, Deno, Bun, React Native and Cloudflare Workers — and has no dependencies.

Records are queued and sent in batches in the background. Nothing blocks and nothing throws: a telemetry client that can break the application it observes is worse than no telemetry. Delivery problems go to onError.

Method
log(level, message, attrs?)A log line at trace, debug, info, warn, error or fatal
trace debug info warn fatal (message, attrs?)Shorthand for log at that level
error(errorOrMessage, options?)An error; see Errors and crashes
metric(name, value, attrs?)A numeric sample
event(name, attrs?)An analytics event
captureErrors(context?)Report uncaught errors and unhandled rejections
flush()Send everything queued now
close()Flush and stop the background timer

Tokens that expire

Pass a function rather than a string and the client asks it for a token whenever a batch is about to go, so a short-lived token renews without recreating the client:

const lantern = new Lantern({
  token: async () => (await fetch("/telemetry-token").then((r) => r.json())).token,
  release: "1.4.2",
});

Your endpoint mints that token with mintToken from @lntrn/device/server — see Authentication.

Options

OptionDefault
token—A token, or a function returning one. Required.
urlhttps://in.lntrn.devThe client ingest. Logs and events go to ${url}/v1/logs, metrics to ${url}/v1/metrics.
release—Your app's release, sent as service.version on every record.
attrs—Merged into every record; per-record attrs win.
logger—Sent as the logger on every log line.
batchSize100Flush once this many records are queued.
flushInterval5000Flush at least this often, in ms. 0 disables the timer.
maxQueue10000Queue cap; past it the oldest records are dropped.
retries3Attempts per batch.
onError—Delivery failures and dropped records.
onResponse—The ingest's reply, including the names of dropped fields.

Errors and crashes

lantern.error(err);
lantern.error(err, {
  release: "1.4.2",       // service.version (defaults to the client's `release`)
  route: "/player",       // url.path — the route or screen
  sessionId: playbackId,  // session.id — ties the record to a session
  attrs: { engine: "hls" },
});

An Error becomes a log line at error carrying the OpenTelemetry exception attributes — exception.type, exception.message and exception.stacktrace — which is the shape Lantern groups into issues. The stack also goes in the message body, so a view that shows only the body still has it.

To report crashes you did not catch:

const stop = lantern.captureErrors(() => ({ route: location.pathname, sessionId }));

The context is read at each crash. A throw of something that is not an Error is still reported as an exception. It is opt-in because installing global handlers from a constructor is a side effect nobody expects; call the returned function to remove them.

Shutting down

await lantern.flush(); // send what is queued
await lantern.close(); // flush and stop the timer

In a browser the client also flushes when the page is hidden or unloaded, as a keepalive request that survives the page going away. In Node the timer is unref'd, so it never keeps a process alive.

Sending from Go

go get git.prod.wtf/xeonr/lantern/device-sdk/go
import lanterndevice "git.prod.wtf/xeonr/lantern/device-sdk/go"

c, err := lanterndevice.New(lanterndevice.Options{
	URL:    "https://in.lntrn.dev",
	Token:  lanterndevice.StaticToken(token),
	Logger: "hub",
	Attrs:  lanterndevice.Attrs{"version": version},
})
if err != nil {
	return err
}
defer c.Close(ctx)

c.Info("started", nil)
c.Metric("encode_speed_x", 2.3, lanterndevice.Attrs{"session_id": id})
c.Event("transcode.start", lanterndevice.Attrs{"encoder": "vaapi"})

The package is lanterndevice. It batches in a background goroutine, never panics, and reports delivery problems to OnError. Token is called before every send, so pass a function that caches the current token and re-mints near expiry. Unlike the JavaScript client, a batch that failed on a 5xx or a network error goes back on the queue after its retries: a long-running process should lose nothing to a brief outage. The same package mints tokens; see Authentication.

Custom fields

Attributes a record carries are kept only if the project declares them, or if they are one of the OpenTelemetry keys Lantern understands without a declaration (exception.*, url.*, http.*, session.id, event.name and the like). Anything else is dropped and counted, never rejected: the batch is accepted and the response names what was dropped. Shipping a new field in a device release therefore never turns into an ingest outage — declare it in the console when you are ready and it starts being stored and filterable.

new Lantern({
  token,
  onResponse: (r) => {
    if (r.droppedFields) console.warn("lantern dropped:", r.droppedFieldNames);
  },
});

Some keys are never stored, declared or not: credentials and direct personal identifiers such as username, email, password, token, secret, authorization and cookie, and keys ending in .token, .secret, .email and similar. Identify a person by an opaque id instead.

The wire

Both SDKs send OTLP/HTTP JSON (the JavaScript one from 1.0, Go from v1.0.0): a log is a log record whose severity is its level and whose scope is its logger, an event is a log record with event.name (and event.value), and a metric is a gauge, or a monotonic delta sum for a counter. Anything that speaks OTLP can send the same way, with a device token as the bearer:

POST https://in.lntrn.dev/v1/logs
POST https://in.lntrn.dev/v1/traces
POST https://in.lntrn.dev/v1/metrics

Protobuf (application/x-protobuf) and JSON (application/json) are both accepted. A JSON request that is accepted answers 200 with what was stored and what was dropped:

{ "accepted": { "logs": 2 }, "droppedFields": 1, "droppedFieldNames": ["undeclared"] }

Refusals are 400 (malformed), 401/403 (the token), 413 (over 8 MiB or 10,000 records), 429 (quota; wait for Retry-After) and 503 (retry after Retry-After). The same declared-field rules apply, and the ingest sets the resource's identity itself — the project's service name and environment, and the token's subject as service.instance.id — over whatever the sender claimed.

Verify

Send a record, then look for it in the console under Client projects → your project → Records, or from a terminal with the CLI:

lntrn --org <org> query logs 'service.name:<project service name>' --since 15m

A 401 or 403 from the ingest names what was wrong with the token; see Authentication.

On this page