Is it possible to manually track exceptions using Firebase GA4 Analytics?
I have been checking few documents that refers to two different events:
app_exception
exception
So... what should I do? Are both ways correct?
analytics.logEvent("exception", {
description: error.message ?? "Unexpected error.",
fatal: false,
});
VS
analytics.logEvent("app_exception", {
description: error.message ?? "Unexpected error.",
fatal: false,
});
Related
I have integrated sentry on one of my NextJS application and using captureException in the catch block to capture exceptions on the platform. Still it is not logging out all the nested error object fields rather it is logging only the error message. Tried other various functions as well but none of them is fulfilling my use case.
Tried all workarounds but got no help. Following is the code, I have used
catch (error) {
console.log("log message", error);
console.error("error message", error);
console.log("log message", JSON.stringify(error));
console.error("error message", JSON.stringify(error));
Sentry.addBreadcrumb({
message: 'Breadcrumb message 1',
});
Sentry.captureMessage('Message 1');
Sentry.captureException('Error 1');
Sentry.captureException(error);
Sentry.captureException(new Error(error));
Sentry.captureEvent({
message: 'Manual'
});
Sentry.captureEvent(error);
Sentry.captureEvent(new Error(error));
}
Checked sentry docs and forums but got no help from there as well. If there is any other solution also, please let me know
You can use ExtraErrorData as following in Sentry.init method for this
import { ExtraErrorData } from "#sentry/integrations";
integrations: [
new ExtraErrorData({ depth: 10 })
]
I'm using Serilog with the Serilog.Formatting.Json.JsonFormatter formatter in a .NET Core app in GKE. I am logging to Console, which is read by a GKE Logging agent. The GKE logging agent expects a "severity" property at the top level of the Log Event: GCP Cloud Logging LogEntry docs
Because of this, all of my logs show up in GCP Logging with severity "Info", as the Serilog Level is found in the jsonPayload property of the LogEntry in GCP. Here is an example LogEntry as seen in Cloud Logging:
{
insertId: "1cu507tg3by7sr1"
jsonPayload: {
Properties: {
SpanId: "|a85df301-4585ee48ea1bc1d1."
ParentId: ""
ConnectionId: "0HM64G0TCF3RI"
RequestPath: "/health/live"
RequestId: "0HM64G0TCF3RI:00000001"
TraceId: "a85df301-4585ee48ea1bc1d1"
SourceContext: "CorrelationId.CorrelationIdMiddleware"
EventId: {2}
}
Level: "Information"
Timestamp: "2021-02-03T17:40:28.9343987+00:00"
MessageTemplate: "No correlation ID was found in the request headers"
}
resource: {2}
timestamp: "2021-02-03T17:40:28.934566174Z"
severity: "INFO"
labels: {3}
logName: "projects/ah-cxp-common-gke-np-946/logs/stdout"
receiveTimestamp: "2021-02-03T17:40:32.020942737Z"
}
My first thought was to add a "Severity" property using an Enricher:
class SeverityEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddOrUpdateProperty(
propertyFactory.CreateProperty("Severity", LogEventLevel.Error));
}
}
The generated log looks like this in GCP, and is still tagged as Info:
{
insertId: "wqxvyhg43lbwf2"
jsonPayload: {
MessageTemplate: "test error!"
Level: "Error"
Properties: {
severity: "Error"
}
Timestamp: "2021-02-03T18:25:32.6238842+00:00"
}
resource: {2}
timestamp: "2021-02-03T18:25:32.623981268Z"
severity: "INFO"
labels: {3}
logName: "projects/ah-cxp-common-gke-np-946/logs/stdout"
receiveTimestamp: "2021-02-03T18:25:41.029632785Z"
}
Is there any way in Serilog to add the "severity" property at the same level as "jsonPayload" instead of inside it? I suspect GCP would then pick it up and log the error type appropriately.
As a last resort I could probably use a GCP Logging sink, but my current setup is much more convenient and performant with the GKE Logging Agent already existing.
Here's a relevant Stack Overflow post with no information or advice past what I already have, which is not enough to solve this: https://stackoverflow.com/questions/57215700
I found the following information detailing the severity of each SeriLog to Stackdriver log level, the next table might also help you
Serilog
Stackdriver
Verbose
Debug
Debug
Debug
Information
Info
Warning
Warning
Error
Error
Fatal
Critical
The complete information can be found at the following link
https://github.com/manigandham/serilog-sinks-googlecloudlogging#log-level-mapping
I think this code could help you to make Stackdriver recognize the severity of the logs given by SeriLogs.
private static LogSeverity TranslateSeverity(LogEventLevel level) => level switch
{
LogEventLevel.Verbose => LogSeverity.Debug,
LogEventLevel.Debug => LogSeverity.Debug,
LogEventLevel.Information => LogSeverity.Info,
LogEventLevel.Warning => LogSeverity.Warning,
LogEventLevel.Error => LogSeverity.Error,
LogEventLevel.Fatal => LogSeverity.Critical,
_ => LogSeverity.Default
};
I will leave the link to the complete code here
https://github.com/manigandham/serilog-sinks-googlecloudlogging/blob/master/src/Serilog.Sinks.GoogleCloudLogging/GoogleCloudLoggingSink.cs#L251
Greetings!
When trying to invoke the Stackdriver Error Reporting API (via the API explorer or via the Client-Side JavaScript library), I receive the following error:
Request:
{ "message" : "test" }
Response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
The Stackdriver Error Reporting API is enabled and I have Owner rights to the App Engine project.
Is the API simply not functional? If I'm doing something wrong, can someone try to help?
The documentation for reporting events says that a ServiceContext is required.
If you're only sending a message (not a stacktrace / exception) you'll need to include a context with a reportLocation as well. This is noted in the documentation of the message field, but it's not obvious.
The following works from the API explorer:
{
"context": {
"reportLocation": {
"functionName": "My Function"
}
},
"message": "error message",
"serviceContext": {
"service": "My Microservice",
}
}
You might be interested in the docs on How Error are Grouped too.
FWIW, I work on this product and I think the error message is too generic. The problem is (?) that the serving stack scrubs the message unless they're annotated as being for public consumption. I'll chase that down.
I've been trying to send push notification via Cloud Functions.
This is the guide on how to do it from Firebase:
https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js
This is the payload I have
const payload = {
"notification": {
title: 'Title!',
body: 'Body!',
sound: 'default'
},
"data":{"score":"3x1"},
"content_available": true,
};
Now, this throwing an error, and when I check the log, here's the error:
Error: Messaging payload contains an invalid "content_available" property. Valid properties are "data" and "notification".
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:130:23)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:465:23
at Array.forEach (native)
at Messaging.validateMessagingPayload (/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:462:21)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging.js:204:37
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
If I removing the content_available: true, it works fine, so I know the code works.
I also tried to send this manually with CURL/POST request WITH content_available: true, and it also works.
Thanks!
contentAvailable is passed in the options parameter of sendToDevice(regToken, payload, options). Example code is in this documentation. The documentation for MessagingOptions is here.
I would like to use GA for my Ionic 2 app but for hybrid applications it looks a little bit tricky.
In my app.component I have:
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
GoogleAnalytics.debugMode();
GoogleAnalytics.startTrackerWithId(this.config.googleAnalyticsId).then(() => {
console.log(this.TAG + ' ANALYTICS+');
}).catch((err) => {
console.log(this.TAG + ' ANALYTICS- ' + err);
});
GoogleAnalytics.enableUncaughtExceptionReporting(true)
.then((_success) => {
console.log(_success);
}).catch((_error) => {
console.log(_error);
});
...
And got such error log:
I: Google Analytics 10.2.98 is starting up. To enable debug logging on a device run:
adb shell setprop log.tag.GAv4 DEBUG
adb logcat -s GAv4
I: Logger is deprecated. To enable debug logging, please run:
adb shell setprop log.tag.GAv4 DEBUG
W: THREAD WARNING: exec() call to UniversalAnalytics.debugMode blocked the main thread for 57ms. Plugin should use CordovaInterface.getThreadPool().
W: Attempted to send a second callback for ID: UniversalAnalytics549833873
Result was: "Invalid action"
W: Attempted to send a second callback for ID: UniversalAnalytics549833875
Result was: "Invalid action"
I: [INFO:CONSOLE(16)] "Tracker not started", source: file:///android_asset/www/build/main.js (16)
The straightforward goal for me is to collect information about bugs during beta-testing. Because I didn't find enough information about this quite new subject for me, any hints or best practices would be appreciated.