Skip to content
Merged
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
18 changes: 17 additions & 1 deletion crashlytics/src/AndroidImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Firebase.Crashlytics
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

using UnityEngine;

Expand Down Expand Up @@ -143,6 +144,21 @@ public override void LogException(Exception exception) {

public override void LogExceptionAsFatal(Exception exception) {
var loggedException = LoggedException.FromException(exception);
Dictionary<string, string>[] parsedStackTrace = loggedException.ParsedStackTrace;

if (parsedStackTrace.Length == 0) {
// if for some reason we don't get stack trace from exception, we add current stack trace in
var currentStackTrace = System.Environment.StackTrace;
LoggedException loggedExceptionWithCurrentStackTrace = new LoggedException(loggedException.Name, loggedException.Message, currentStackTrace);
parsedStackTrace = loggedExceptionWithCurrentStackTrace.ParsedStackTrace;

if (parsedStackTrace.Length > 2) {
// remove RecordCustomException and System.Environment.StackTrace frame for fault blame on crashlytics sdk
var slicedParsedStackTrace = parsedStackTrace.Skip(2).Take(parsedStackTrace.Length - 2).ToArray();
parsedStackTrace = slicedParsedStackTrace;
}
}

StackFrames frames = new StackFrames();
foreach (Dictionary<string, string> frame in loggedException.ParsedStackTrace) {
frames.Add(new FirebaseCrashlyticsFrame {
Expand All @@ -152,7 +168,7 @@ public override void LogExceptionAsFatal(Exception exception) {
lineNumber = frame["line"],
});
}
// TODO(mrober): Do something for empty stacktrace. Get current stacktrace?

CallInternalMethod(() => {
crashlyticsInternal.LogExceptionAsFatal(loggedException.Name,
loggedException.Message, frames);
Expand Down
14 changes: 14 additions & 0 deletions crashlytics/src/IOSImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Firebase.Crashlytics
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;


Expand Down Expand Up @@ -116,6 +117,19 @@ public override void SetCrashlyticsCollectionEnabled(bool enabled) {
private void RecordCustomException(LoggedException loggedException, bool isOnDemand) {
Dictionary<string, string>[] parsedStackTrace = loggedException.ParsedStackTrace;

if (isOnDemand && parsedStackTrace.Length == 0) {
// if for some reason we don't get stack trace from exception, we add current stack trace in
var currentStackTrace = System.Environment.StackTrace;
LoggedException loggedExceptionWithCurrentStackTrace = new LoggedException(loggedException.Name, loggedException.Message, currentStackTrace);
parsedStackTrace = loggedExceptionWithCurrentStackTrace.ParsedStackTrace;

if (parsedStackTrace.Length > 2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't add this logic, the stack trace will look like this as it still blame on crashlytics frame:
Screen Shot 2023-01-13 at 12 27 19 AM

Remove these two frame for logging purpose then here is the result:
Screen Shot 2023-01-13 at 12 26 43 AM

// remove RecordCustomException and System.Environment.StackTrace frame for fault blame on crashlytics sdk
var slicedParsedStackTrace = parsedStackTrace.Skip(2).Take(parsedStackTrace.Length - 2).ToArray();
parsedStackTrace = slicedParsedStackTrace;
}
}

List<Frame> frames = new List<Frame>();
foreach (Dictionary<string, string> frame in parsedStackTrace) {
frames.Add(new Frame {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 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.
*/
//
// Crashlytics_ExceptionModel.h
// Crashlytics
//

#import <FIRCrashlytics.h>

@interface FIRExceptionModel (Platform)

@property(nonatomic) BOOL isFatal;
@property(nonatomic) BOOL onDemand;

@end
4 changes: 4 additions & 0 deletions crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "CrashlyticsiOSWrapper.h"
#import "FirebaseCrashlytics.h"
#import "./Crashlytics_PrivateHeaders/Crashlytics_Platform.h"
#import "./Crashlytics_PrivateHeaders/ExceptionModel_Platform.h"

@interface FIRCrashlytics ()
- (BOOL)isCrashlyticsStarted;
Expand Down Expand Up @@ -58,6 +59,9 @@ void CLURecordCustomException(const char *name, const char *reason, Frame *frame
model.stackTrace = framesArray;

if (isOnDemand) {
// For on demand exception, we log them as fatal
model.onDemand = YES;
model.isFatal = YES;
[[FIRCrashlytics crashlytics] recordOnDemandExceptionModel:model];
return;
}
Expand Down