Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding logging metrics #6197

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firebase-crashlytics-ndk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Unreleased

* [changed] Updated `firebase-crashlytics` dependency to v19.0.4

# 19.0.3
* [changed] Updated `firebase-crashlytics` dependency to v19.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
import com.google.firebase.crashlytics.internal.Logger;
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorkers;
import com.google.firebase.crashlytics.internal.model.InternalTracingMetrics;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import com.google.firebase.remoteconfig.interop.FirebaseRemoteConfigInterop;
Expand Down Expand Up @@ -86,6 +87,9 @@ private FirebaseCrashlytics buildCrashlytics(ComponentContainer container) {
Logger.getLogger().d("Initializing Crashlytics blocked main for " + duration + " ms");
}

InternalTracingMetrics.InternalMetrics.put("crashlytics_init_time", String.valueOf(duration));
crashlytics.core.setCustomKeys(InternalTracingMetrics.InternalMetrics.getMetrics());
crashlytics.recordException(new RuntimeException("Crashlytics Initialization done"));
return crashlytics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.firebase.crashlytics.internal.metadata.LogFileManager;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport;
import com.google.firebase.crashlytics.internal.model.InternalTracingMetrics;
import com.google.firebase.crashlytics.internal.model.StaticSessionData;
import com.google.firebase.crashlytics.internal.persistence.FileStore;
import com.google.firebase.crashlytics.internal.settings.Settings;
Expand Down Expand Up @@ -303,6 +304,7 @@ public Task<Boolean> then(@Nullable Void aVoid) throws Exception {
/** This function must be called before opening the first session * */
boolean didCrashOnPreviousExecution() {
CrashlyticsWorkers.checkBackgroundThread(); // To not violate strict mode.
logThreadViolationIfNecessary();
if (!crashMarker.isPresent()) {
// Before the first session of this execution is opened, the current session ID still refers
// to the previous execution's last session, which is what we want.
Expand Down Expand Up @@ -495,6 +497,7 @@ private String getCurrentSessionId() {
*/
boolean finalizeSessions(SettingsProvider settingsProvider) {
CrashlyticsWorkers.checkBackgroundThread();
logThreadViolationIfNecessary();

if (isHandlingException()) {
Logger.getLogger().w("Skipping session finalization because a crash has already occurred.");
Expand Down Expand Up @@ -560,6 +563,7 @@ void doCloseSessions(SettingsProvider settingsProvider) {
private void doCloseSessions(
boolean skipCurrentSession, SettingsProvider settingsProvider, boolean isInitProcess) {
CrashlyticsWorkers.checkBackgroundThread();
logThreadViolationIfNecessary();
final int offset = skipCurrentSession ? 1 : 0;

// :TODO HW2021 this implementation can be cleaned up.
Expand Down Expand Up @@ -888,6 +892,15 @@ private static NativeSessionFile nativeCoreFile(NativeSessionFileProvider filePr
: new FileBackedNativeSessionFile("minidump_file", "minidump", minidump);
}

void logThreadViolationIfNecessary() {
if (InternalTracingMetrics.InternalMetrics.getMetrics()
.containsValue("crashlytics_violate_thread")) {
writeNonFatalException(
Thread.currentThread(), new RuntimeException("Crashlytics thread violation"));
InternalTracingMetrics.InternalMetrics.removeThreadViolationLog();
}
}

// endregion

// region ApplicationExitInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public Task<Settings> doBackgroundInitializationAsync(SettingsProvider settingsP
@CanIgnoreReturnValue
private Task<Settings> doBackgroundInitialization(SettingsProvider settingsProvider) {
CrashlyticsWorkers.checkBackgroundThread();
controller.logThreadViolationIfNecessary();
// create the marker for this run
markInitializationStarted();

Expand Down Expand Up @@ -458,6 +459,7 @@ private void finishInitSynchronously(SettingsProvider settingsProvider) {
/** Synchronous call to mark start of initialization */
void markInitializationStarted() {
CrashlyticsWorkers.checkBackgroundThread();
controller.logThreadViolationIfNecessary();

// Create the Crashlytics initialization marker file, which is used to determine
// whether the app crashed before initialization could complete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.crashlytics.internal.Logger;
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorkers;
import com.google.firebase.crashlytics.internal.model.InternalTracingMetrics;
import com.google.firebase.installations.FirebaseInstallationsApi;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -130,21 +131,25 @@ public synchronized InstallIds getInstallIds() {
if (Objects.equals(trueFid.getFid(), cachedFid)) {
// the current FID is the same as the cached FID, so we keep the cached Crashlytics ID
installIds = InstallIds.create(readCachedCrashlyticsInstallId(prefs), trueFid);
InternalTracingMetrics.InternalMetrics.put("crashlytics_fid_state", "cached");
} else {
// the current FID has changed, so we generate a new Crashlytics ID
installIds =
InstallIds.create(createAndCacheCrashlyticsInstallId(trueFid.getFid(), prefs), trueFid);
InternalTracingMetrics.InternalMetrics.put("crashlytics_fid_state", "fetched");
}
} else { // data collection is NOT enabled; we can't use the FID
if (isSyntheticFid(cachedFid)) {
// We already have a cached synthetic FID, so we don't need to change the Crashlytics ID
installIds = InstallIds.createWithoutFid(readCachedCrashlyticsInstallId(prefs));
InternalTracingMetrics.InternalMetrics.put("crashlytics_fid_state", "syntheticCached");
} else {
// we don't have a synthetic FID, so we need to replace the cached FID with a synthetic
// one and create a new Crashlytics install id.
installIds =
InstallIds.createWithoutFid(
createAndCacheCrashlyticsInstallId(createSyntheticFid(), prefs));
InternalTracingMetrics.InternalMetrics.put("crashlytics_fid_state", "syntheticCreate");
}
}
Logger.getLogger().v("Install IDs: " + installIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.google.firebase.crashlytics.internal.concurrency
import android.os.Build
import android.os.Looper
import com.google.firebase.crashlytics.internal.Logger
import com.google.firebase.crashlytics.internal.model.InternalTracingMetrics
import java.util.concurrent.ExecutorService

/**
Expand Down Expand Up @@ -93,6 +94,7 @@ class CrashlyticsWorkers(
private fun checkThread(isCorrectThread: () -> Boolean, failureMessage: () -> String) {
if (!isCorrectThread()) {
Logger.getLogger().d(failureMessage())
InternalTracingMetrics.metrics["crashlytics_violate_thread"] = failureMessage()
assert(!enforcement, failureMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.crashlytics.internal.model

internal class InternalTracingMetrics {
companion object InternalMetrics {
var metrics = mutableMapOf<String, String>()
fun put(key: String, value: String) {
metrics[key] = value
}
fun removeThreadViolationLog() {
metrics.remove("crashlytics_violate_thread")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.firebase.crashlytics.internal.common.IdManager;
import com.google.firebase.crashlytics.internal.common.SystemCurrentTimeProvider;
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorkers;
import com.google.firebase.crashlytics.internal.model.InternalTracingMetrics;
import com.google.firebase.crashlytics.internal.network.HttpRequestFactory;
import com.google.firebase.crashlytics.internal.persistence.FileStore;
import java.util.Locale;
Expand Down Expand Up @@ -170,6 +171,7 @@ public Task<Void> loadSettingsData(
if (cachedSettings != null) {
settings.set(cachedSettings);
settingsTask.get().trySetResult(cachedSettings);
InternalTracingMetrics.InternalMetrics.put("crashlytics_init_setting_state", "cached");
return Tasks.forResult(null);
}
}
Expand All @@ -183,6 +185,7 @@ public Task<Void> loadSettingsData(
getCachedSettingsData(SettingsCacheBehavior.IGNORE_CACHE_EXPIRATION);
if (expiredSettings != null) {
settings.set(expiredSettings);
InternalTracingMetrics.InternalMetrics.put("crashlytics_init_setting_state", "expired");
settingsTask.get().trySetResult(expiredSettings);
}

Expand Down Expand Up @@ -212,10 +215,11 @@ public Task<Void> then(@Nullable Void aVoid) throws Exception {
cachedSettingsIo.writeCachedSettings(
fetchedSettings.expiresAtMillis, settingsJson);
logSettings(settingsJson, "Loaded settings: ");

setStoredBuildInstanceIdentifier(settingsRequest.instanceId);

// Update the regular settings.
InternalTracingMetrics.InternalMetrics.put(
"crashlytics_init_setting_state", "fetched");
settings.set(fetchedSettings);

// Signal the Task that we have a new valid settings
Expand Down
10 changes: 10 additions & 0 deletions release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "M135_1",
"libraries": [
":firebase-crashlytics",
":firebase-crashlytics-ndk",
":firebase-sessions",
":firebase-components",
":firebase-crashlytics:ktx"
]
}
Loading