JLPluginOpenTelemetry
A Jasonelle plugin that wraps the OpenTelemetry SDK to track application metrics.
Overview
JLPluginOpenTelemetry bridges the OpenTelemetry Java SDK to JavaScript. It records counters and histograms on any meter, so metrics raised in the web view reach whatever exporter the app has configured.
Structure
| File | Role |
|---|---|
|
Native side – connects to |
|
JavaScript side – registers the plugin on |
How it works
-
The plugin is injected into the web view on page load and registers itself on
window.jasonelle.plugins.opentelemetry. -
counter(name, value, meterName)andhistogram(name, value, meterName)post a message to native and return a promise. -
The call is routed to
Plugin.kthandle_call(callbackId:args:respond:), which readsactionand dispatches to the requested metric action. -
The plugin builds the instrument on the requested meter, records the value, and resolves the promise.
await window.jasonelle.plugins.opentelemetry.counter("button_clicks", 1);
await window.jasonelle.plugins.opentelemetry.histogram("load_time_ms", 124.5);
The same call can be made without the JavaScript wrapper, using window.jasonelle.post
to send the arguments straight to handle_call. The first argument is the plugin
id, not the short name used to register it on window.jasonelle.plugins:
await window.jasonelle.post("com.jasonelle.plugins.opentelemetry", {
action: "counter.add",
name: "button_clicks",
value: 1,
meterName: "jasonelle.app.meter"
});
Arguments
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
|
string |
yes |
– |
|
|
string |
yes |
– |
Instrument name, for example |
|
number |
yes |
– |
Value added to the counter, or recorded in the histogram. |
|
string |
no |
|
Meter the instrument is created on. |
counter.add truncates value to a whole number, matching the LongCounter
instrument on other platforms.
Response
{
"status": "ok",
"callbackId": "call_1",
"success": true
}
success reports that the bridge call was accepted, not that a value reached the
SDK. A missing or non-numeric name or value is dropped natively and the promise
still resolves with success: true.
Errors
{
"status": "error",
"callbackId": "call_1",
"error": "No action provided"
}
-
No action provided– the arguments carried no stringaction. -
Unknown action <action>–actionwas neithercounter.addnorhistogram.record.
SDK requirement
The app must register an OpenTelemetry SDK before the first call. Without one
GlobalOpenTelemetry.get() returns a no-op OpenTelemetry, every value is discarded
and the promise still resolves with success: true.
|
GlobalOpenTelemetry.set(
OpenTelemetrySdk.builder()
.setMeterProvider(
SdkMeterProvider.builder()
.setResource(Resource.getDefault().merge(Resource.create(Attributes.of(...))))
.registerMetricReader(PeriodicMetricReader.create(exporter))
.build()
)
.build()
)
Register the SDK in the Application module, before the web view loads the page that raises the first metric.
Reference
-
com.jasonelle.kernel.Plugin– the base class this plugin extends. -
Plugin.jsinsrc/main/assets/plugins/opentelemetry/– the JavaScript client, byte-identical to the Xcode plugin. -
io.opentelemetry:opentelemetry-apiandio.opentelemetry:opentelemetry-sdk1.30.0, declared in the module’sbuild.gradle.kts.