Skip to content

Commit 55fbe0b

Browse files
authored
Carrier info (signalfx#66)
1 parent e48a4e7 commit 55fbe0b

14 files changed

Lines changed: 451 additions & 354 deletions

File tree

android/src/main/java/com/splunkotelreactnative/SplunkOtelReactNativeModule.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.splunkotelreactnative;
1919

20+
import android.app.Application;
2021
import android.content.ContextWrapper;
2122
import android.util.Log;
2223

@@ -35,6 +36,9 @@
3536
import com.splunkotelreactnative.crash.CrashEventAttributeExtractor;
3637
import com.splunkotelreactnative.crash.CrashReporter;
3738
import com.splunkotelreactnative.exporter.disk.DiskBufferingExporterFactory;
39+
import com.splunkotelreactnative.exporter.network.CurrentNetwork;
40+
import com.splunkotelreactnative.exporter.network.CurrentNetworkAttributesExtractor;
41+
import com.splunkotelreactnative.exporter.network.CurrentNetworkProvider;
3842

3943
import java.util.ArrayList;
4044
import java.util.Collections;
@@ -60,6 +64,7 @@ public class SplunkOtelReactNativeModule extends ReactContextBaseJavaModule {
6064
private final long moduleStartTime;
6165
private volatile SpanExporter exporter;
6266
private volatile CrashReporter crashReporter;
67+
private CurrentNetworkProvider currentNetworkProvider;
6368

6469
public SplunkOtelReactNativeModule(ReactApplicationContext reactContext) {
6570
super(reactContext);
@@ -85,6 +90,8 @@ public void initialize(ReadableMap configMap, Promise promise) {
8590

8691
String endpointWithAuthentication = beaconEndpoint + "?auth=" + accessToken;
8792

93+
currentNetworkProvider = CurrentNetworkProvider.createAndStart((Application) getReactApplicationContext().getApplicationContext());
94+
8895
exporter = createExporter(endpointWithAuthentication, getReactApplicationContext(),
8996
mapReader.getEnableDiskBuffering(), mapReader.getMaxStorageUseMb());
9097

@@ -124,6 +131,11 @@ public void export(ReadableArray spanMaps, Promise promise) {
124131

125132
List<SpanData> spanDataList = new ArrayList<>();
126133

134+
CurrentNetwork network = currentNetworkProvider.refreshNetworkStatus();
135+
CurrentNetworkAttributesExtractor networkAttributesExtractor = new CurrentNetworkAttributesExtractor();
136+
Attributes networkAttributes = networkAttributesExtractor.extract(network);
137+
setGlobalAttributes(networkAttributes);
138+
127139
for (int i = 0; i < spanMaps.size(); i++) {
128140
ReadableMap spanMap = spanMaps.getMap(i);
129141
SpanMapReader mapReader = new SpanMapReader(spanMap);
@@ -142,7 +154,7 @@ public void export(ReadableArray spanMaps, Promise promise) {
142154
return;
143155
}
144156

145-
Attributes attributes = attributesFromMap(mapReader.getAttributes());
157+
Attributes attributes = attributesFromMap(mapReader.getAttributes()).toBuilder().putAll(networkAttributes).build();
146158
ReactSpanData spanData = new ReactSpanData(spanProperties, attributes, context, parentContext,
147159
Collections.emptyList());
148160

@@ -166,10 +178,15 @@ public void setSessionId(String sessionId) {
166178

167179
@ReactMethod
168180
public void setGlobalAttributes(ReadableMap attributeMap) {
181+
Attributes attributesFromMap = attributesFromMap(attributeMap);
182+
setGlobalAttributes(attributesFromMap);
183+
}
184+
185+
private void setGlobalAttributes(Attributes attributes) {
169186
CrashReporter currentCrashReporter = crashReporter;
170187

171188
if (currentCrashReporter != null) {
172-
currentCrashReporter.updateGlobalAttributes(attributesFromMap(attributeMap));
189+
currentCrashReporter.updateGlobalAttributes(attributes);
173190
}
174191
}
175192

@@ -198,7 +215,7 @@ private SpanExporter createExporter(String endpoint, ContextWrapper application,
198215
.setEncoder(new CustomZipkinEncoder())
199216
.build());
200217
}
201-
return DiskBufferingExporterFactory.setupDiskBuffering(endpoint, application, maxStorageUseMb);
218+
return DiskBufferingExporterFactory.setupDiskBuffering(endpoint, application, maxStorageUseMb, currentNetworkProvider);
202219
}
203220

204221
@NonNull

android/src/main/java/com/splunkotelreactnative/exporter/disk/DiskBufferingExporterFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import zipkin2.reporter.okhttp3.OkHttpSender;
1919

2020
public class DiskBufferingExporterFactory {
21-
public static SpanExporter setupDiskBuffering(String endpoint, ContextWrapper application, int maxStorageUseMb) {
22-
CurrentNetworkProvider currentNetworkProvider = CurrentNetworkProvider.createAndStart((Application) application.getApplicationContext());
23-
21+
public static SpanExporter setupDiskBuffering(String endpoint, ContextWrapper application, int maxStorageUseMb, CurrentNetworkProvider currentNetworkProvider) {
2422
Sender sender = OkHttpSender.newBuilder().endpoint(endpoint).build();
2523
File spanFilesPath = FileUtils.getSpansDirectory(application);
2624
BandwidthTracker bandwidthTracker = new BandwidthTracker();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.splunkotelreactnative.exporter.network;
2+
3+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CARRIER_ICC;
4+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CARRIER_MCC;
5+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CARRIER_MNC;
6+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CARRIER_NAME;
7+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CONNECTION_SUBTYPE;
8+
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_HOST_CONNECTION_TYPE;
9+
10+
import androidx.annotation.Nullable;
11+
import io.opentelemetry.api.common.AttributeKey;
12+
import io.opentelemetry.api.common.Attributes;
13+
import io.opentelemetry.api.common.AttributesBuilder;
14+
15+
public final class CurrentNetworkAttributesExtractor {
16+
17+
public Attributes extract(CurrentNetwork network) {
18+
AttributesBuilder builder =
19+
Attributes.builder()
20+
.put(NET_HOST_CONNECTION_TYPE, network.getState().getHumanName());
21+
22+
setIfNotNull(builder, NET_HOST_CONNECTION_SUBTYPE, network.getSubType());
23+
setIfNotNull(builder, NET_HOST_CARRIER_NAME, network.getCarrierName());
24+
setIfNotNull(builder, NET_HOST_CARRIER_MCC, network.getCarrierCountryCode());
25+
setIfNotNull(builder, NET_HOST_CARRIER_MNC, network.getCarrierNetworkCode());
26+
setIfNotNull(builder, NET_HOST_CARRIER_ICC, network.getCarrierIsoCountryCode());
27+
28+
return builder.build();
29+
}
30+
31+
private static void setIfNotNull(
32+
AttributesBuilder builder, AttributeKey<String> key, @Nullable String value) {
33+
if (value != null) {
34+
builder.put(key, value);
35+
}
36+
}
37+
}

example/__tests__/e2e/configs/wdio.ios.local.conf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const config: Options.Testrunner = {
2828
'appium:deviceName': 'iPhone 15 Pro',
2929
'appium:platformVersion': '17.0',
3030
'appium:automationName': 'XCUITest',
31+
'appium:autoAcceptAlerts': true,
3132
//TODO find local app file
3233
'appium:app': 'SplunkOtelReactNativeExample.app'
3334
},

example/__tests__/e2e/configs/wdio.ios.sauce.conf.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const config: Options.Testrunner = {
3535
'appium:deviceName': 'iPhone Instant Simulator',
3636
'appium:automationName': 'XCUITest',
3737
'appium:app': 'storage:filename=SplunkOtelReactNativeExample.zip',
38+
'appium:autoAcceptAlerts': true,
39+
'appium:autoDismissAlerts': true,
3840
'sauce:options': {
3941
tunnelIdentifier: process.env.SAUCE_TUNNEL_ID,
4042
},

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
xmlns:tools="http://schemas.android.com/tools">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5+
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
6+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> -->
57

68
<application
79
android:name=".MainApplication"

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ PODS:
497497
- RCT-Folly (= 2021.07.22.00)
498498
- React-Core
499499
- SocketRocket (0.6.1)
500-
- splunk-otel-react-native (0.1.1):
500+
- splunk-otel-react-native (0.2.0):
501501
- DeviceKit (~> 4.0)
502502
- PLCrashReporter (~> 1.11)
503503
- React-Core
@@ -739,7 +739,7 @@ SPEC CHECKSUMS:
739739
ReactCommon: 91ece8350ebb3dd2be9cef662abd78b6948233c0
740740
RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581
741741
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
742-
splunk-otel-react-native: 35ecfed848370d2b2c36d02bd86fb2dfd92d917c
742+
splunk-otel-react-native: b82a0b557bfd9518cd9d36b2e79b04227642bb02
743743
Yoga: 86fed2e4d425ee4c6eab3813ba1791101ee153c6
744744
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
745745

0 commit comments

Comments
 (0)