|
22 | 22 | import com.google.firebase.components.Lazy; |
23 | 23 | import com.google.firebase.perf.config.ConfigResolver; |
24 | 24 | import com.google.firebase.perf.logging.AndroidLogger; |
| 25 | +import com.google.firebase.perf.session.FirebasePerformanceSessionSubscriber; |
25 | 26 | import com.google.firebase.perf.session.PerfSession; |
26 | 27 | import com.google.firebase.perf.transport.TransportManager; |
27 | 28 | import com.google.firebase.perf.util.Timer; |
@@ -59,7 +60,7 @@ public class GaugeManager { |
59 | 60 | private final TransportManager transportManager; |
60 | 61 |
|
61 | 62 | @Nullable private GaugeMetadataManager gaugeMetadataManager; |
62 | | - @Nullable private ScheduledFuture gaugeManagerDataCollectionJob = null; |
| 63 | + @Nullable private ScheduledFuture<?> gaugeManagerDataCollectionJob = null; |
63 | 64 | @Nullable private String sessionId = null; |
64 | 65 | private ApplicationProcessState applicationProcessState = |
65 | 66 | ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN; |
@@ -94,8 +95,10 @@ private GaugeManager() { |
94 | 95 | } |
95 | 96 |
|
96 | 97 | /** Initializes GaugeMetadataManager which requires application context. */ |
97 | | - public void initializeGaugeMetadataManager(Context appContext) { |
| 98 | + public void initializeGaugeMetadataManager( |
| 99 | + Context appContext, ApplicationProcessState applicationProcessState) { |
98 | 100 | this.gaugeMetadataManager = new GaugeMetadataManager(appContext); |
| 101 | + this.applicationProcessState = applicationProcessState; |
99 | 102 | } |
100 | 103 |
|
101 | 104 | /** Returns the singleton instance of this class. */ |
@@ -206,7 +209,7 @@ public void stopCollectingGauges() { |
206 | 209 |
|
207 | 210 | // Flush any data that was collected for this session one last time. |
208 | 211 | @SuppressWarnings("FutureReturnValueIgnored") |
209 | | - ScheduledFuture unusedFuture = |
| 212 | + ScheduledFuture<?> unusedFuture = |
210 | 213 | gaugeManagerExecutor |
211 | 214 | .get() |
212 | 215 | .schedule( |
@@ -242,31 +245,32 @@ private void syncFlush(String sessionId, ApplicationProcessState appState) { |
242 | 245 | } |
243 | 246 |
|
244 | 247 | // Adding Session ID info. |
245 | | - gaugeMetricBuilder.setSessionId(sessionId); |
| 248 | + String aqsSessionId = |
| 249 | + FirebasePerformanceSessionSubscriber.Companion.getInstance() |
| 250 | + .getAqsMappedToPerfSession(sessionId); |
| 251 | + gaugeMetricBuilder.setSessionId(aqsSessionId); |
| 252 | + AndroidLogger.getInstance().debug("CFPR syncFlush: " + sessionId + " AQS: " + aqsSessionId); |
246 | 253 |
|
247 | 254 | transportManager.log(gaugeMetricBuilder.build(), appState); |
248 | 255 | } |
249 | 256 |
|
250 | 257 | /** |
251 | 258 | * Log the Gauge Metadata information to the transport. |
252 | 259 | * |
253 | | - * @param sessionId The {@link PerfSession#sessionId()} to which the collected Gauge Metrics |
| 260 | + * @param aqsSessionId The {@link FirebasePerformanceSessionSubscriber#getAqsMappedToPerfSession(String)} to which the collected Gauge Metrics |
254 | 261 | * should be associated with. |
255 | | - * @param appState The {@link ApplicationProcessState} for which these gauges are collected. |
256 | 262 | * @return true if GaugeMetadata was logged, false otherwise. |
257 | 263 | */ |
258 | | - public boolean logGaugeMetadata(String sessionId, ApplicationProcessState appState) { |
259 | | - // TODO(b/394127311): Re-introduce logging of metadata for AQS. |
260 | | - if (gaugeMetadataManager != null) { |
261 | | - GaugeMetric gaugeMetric = |
262 | | - GaugeMetric.newBuilder() |
263 | | - .setSessionId(sessionId) |
264 | | - .setGaugeMetadata(getGaugeMetadata()) |
265 | | - .build(); |
266 | | - transportManager.log(gaugeMetric, appState); |
267 | | - return true; |
268 | | - } |
269 | | - return false; |
| 264 | + public void logGaugeMetadata(String aqsSessionId) { |
| 265 | + // TODO(b/394127311): This can now throw an NPE. Explore if there's anything that should be |
| 266 | + // verified. |
| 267 | + AndroidLogger.getInstance().debug("CFPR logGaugeMetadata: " + aqsSessionId); |
| 268 | + GaugeMetric gaugeMetric = |
| 269 | + GaugeMetric.newBuilder() |
| 270 | + .setSessionId(aqsSessionId) |
| 271 | + .setGaugeMetadata(getGaugeMetadata()) |
| 272 | + .build(); |
| 273 | + transportManager.log(gaugeMetric, this.applicationProcessState); |
270 | 274 | } |
271 | 275 |
|
272 | 276 | private GaugeMetadata getGaugeMetadata() { |
|
0 commit comments