1717
1818package com .splunkotelreactnative ;
1919
20+ import android .app .Application ;
2021import android .content .ContextWrapper ;
2122import android .util .Log ;
2223
3536import com .splunkotelreactnative .crash .CrashEventAttributeExtractor ;
3637import com .splunkotelreactnative .crash .CrashReporter ;
3738import 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
3943import java .util .ArrayList ;
4044import 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
0 commit comments