Skip to content

Commit cebc37a

Browse files
authored
feat: web support (#5)
This PR adds support for the web platform as well as the JS layer on mobiles.
1 parent 812a2c4 commit cebc37a

26 files changed

+753
-355
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ android/keystores/debug.keystore
7878
# generated by bob
7979
lib/
8080

81+
# Vite
82+
dist/
83+
8184
# React Native Codegen
8285
ios/generated
8386
android/generated

README.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,52 @@ Best in class observability brought to React Native.
77

88
## Features
99

10-
* **Telemetry without lock-in**. Send to **any OTLP compliant backend** including [vendors](https://opentelemetry.io/ecosystem/vendors/).
10+
* **Telemetry without lock-in**. Send to **any OTLP compliant backend** including [vendors](https://opentelemetry.io/ecosystem/vendors/)
1111
* [**Tracing** API](https://opentelemetry.io/docs/specs/otel/trace/api/)
1212
* [**Metrics** API](https://opentelemetry.io/docs/specs/otel/metrics/api/)
13-
* **Android** support (experimental) with **iOS** and **Web** coming next
13+
* **Web**, **Android** (experimental) support with **iOS** coming soon
1414

1515
## Installation
1616

1717
```sh
1818
npm install react-native-open-telemetry
1919
```
2020

21-
## Usage
21+
## Usage
2222

23-
### 1. Start the native SDK
23+
### 1. Start the JS SDK
24+
25+
See OpenTelemetry's JS documentation on [Traces](https://opentelemetry.io/docs/languages/js/instrumentation/#acquiring-a-tracer) and [Metrics](https://opentelemetry.io/docs/languages/js/instrumentation/#acquiring-a-meter) for more information on available APIs.
26+
27+
```js
28+
import { openTelemetrySDK } from 'react-native-open-telemetry';
29+
30+
// Start the SDK
31+
const sdk = openTelemetrySDK({
32+
debug: true,
33+
url: "https://my-collector.com:4317",
34+
name: "my-app",
35+
version: "1.0.0-alpha",
36+
environment: "development",
37+
});
38+
39+
// Use available APIs
40+
const meter = sdk.metrics.getMeter("my-js-meter", "1.0");
41+
42+
const promoCounter = meter.createCounter("my-promo-counter", {
43+
description: "A counter metric for my promo section"
44+
});
45+
46+
function App() {
47+
function onPress() {
48+
promoCounter.add(1);
49+
}
50+
51+
return <Button title="Press me" onPress={onPress} />
52+
}
53+
```
54+
55+
### 2. Start the native SDK (optional)
2456

2557
**Android**
2658

@@ -32,7 +64,7 @@ import com.opentelemetry.OpenTelemetry
3264
class MainApplication : Application(), ReactApplication {
3365
override fun onCreate() {
3466
super.onCreate()
35-
67+
3668
// Start the SDK
3769
OpenTelemetry.init(this) {
3870
debug = true
@@ -41,9 +73,9 @@ class MainApplication : Application(), ReactApplication {
4173
version = "1.0.0"
4274
environment = "production"
4375
}
44-
76+
4577
// ..
46-
78+
4779
// Use available APIs
4880
val sdk = OpenTelemetry.get()
4981
val meter = sdk.getMeter("native-scope-name")
@@ -53,32 +85,6 @@ class MainApplication : Application(), ReactApplication {
5385
}
5486
```
5587

56-
### 2. Start the JS SDK
57-
58-
See OpenTelemetry's JS documentation on [Traces](https://opentelemetry.io/docs/languages/js/instrumentation/#acquiring-a-tracer) and [Metrics](https://opentelemetry.io/docs/languages/js/instrumentation/#acquiring-a-meter) for more information on available APIs.
59-
60-
```js
61-
import { observability } from 'react-native-open-telemetry';
62-
63-
// Start the SDK
64-
const sdk = observability();
65-
66-
// Use available APIs
67-
const meter = sdk.metrics.getMeter("my-js-meter", "1.0");
68-
69-
const promoCounter = meter.createCounter("my-promo-counter", {
70-
description: "A counter metric for my promo section"
71-
});
72-
73-
function App() {
74-
function onPress() {
75-
promoCounter.add(1);
76-
}
77-
78-
return <Button title="Press me" onPress={onPress} />
79-
}
80-
```
81-
8288
## Contributing
8389

8490
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

android/src/main/java/com/opentelemetry/OpenTelemetryModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class OpenTelemetryModule(reactContext: ReactApplicationContext) :
148148
override fun getTotalAttributeCount() = getAttributes().size()
149149

150150
override fun getInstrumentationScopeInfo(): InstrumentationScopeInfo {
151-
val instrumentation = rawSpan.getMap("instrumentationLibrary")
151+
val instrumentation = rawSpan.getMap("instrumentationScope")
152152
val name = instrumentation?.getString("name") ?: "unknown"
153153
val builder = InstrumentationScopeInfo.builder(name)
154154
instrumentation?.getString("version")?.let { builder.setSchemaUrl(it) }
@@ -157,7 +157,7 @@ class OpenTelemetryModule(reactContext: ReactApplicationContext) :
157157
}
158158

159159
override fun getInstrumentationLibraryInfo(): InstrumentationLibraryInfo {
160-
val instrumentation = rawSpan.getMap("instrumentationLibrary")
160+
val instrumentation = rawSpan.getMap("instrumentationScope")
161161
val name = instrumentation?.getString("name") ?: "unknown"
162162
val version = instrumentation?.getString("version") ?: "unknown"
163163
return InstrumentationLibraryInfo.create(name, version)
@@ -320,4 +320,4 @@ fun ReadableArray.hrTimeToNanoseconds(): Long {
320320
val seconds = this.getDouble(0).toLong()
321321
val nanos = this.getDouble(1).toLong()
322322
return seconds * 1_000_000_000 + nanos
323-
}
323+
}

0 commit comments

Comments
 (0)