Skip to content

Commit

Permalink
feat: Log Forwarding and ANR reporting through android sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndesai-newrelic committed Aug 1, 2024
1 parent d257269 commit f69031e
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 13 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 1.4.0

## New Features

1. Application Exit Information
- Added ApplicationExitInfo to data reporting
- Enabled by default

2. Log Forwarding to New Relic
- Implement static API for sending logs to New Relic
- Can be enabled/disabled in your mobile application's entity settings page

## Improvements

- Native Android agent updated to version 7.5.0
- Native iOS agent updated to version 7.5.0

## 1.3.6

* Improvements
Expand Down
4 changes: 2 additions & 2 deletions com.newrelic.agent/Editor/TestUnityDependencies.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<dependencies>
<androidPackages>
<androidPackage spec="com.newrelic.agent.android:agent-ndk:1.+"></androidPackage>
<androidPackage spec="com.newrelic.agent.android:android-agent:7.3.1">
<androidPackage spec="com.newrelic.agent.android:android-agent:7.5.+">
</androidPackage>
</androidPackages>
<iosPods>
<iosPod name="NewRelicAgent" version="~> 7.4.12" minTargetSdk="11.0">
<iosPod name="NewRelicAgent" version="~> 7.5.0" minTargetSdk="11.0">
<sources>
<source>https://github.com/CocoaPods/Specs</source>
</sources>
Expand Down
75 changes: 72 additions & 3 deletions com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ override public void start(string applicationToken)
agentInstance.CallStatic("disableFeature", OfflineStorage);

}
AndroidJavaObject BackgroundReporting = featureFlags.GetStatic<AndroidJavaObject>("BackgroundReporting");

if (plugin.backgroundReportingEnabled)
{
agentInstance.CallStatic("enableFeature", BackgroundReporting);
} else
{
agentInstance.CallStatic("enableFeature", BackgroundReporting);
}

// finally, start the agent
agentInstance.Call("start", this.activityContext);
Expand Down Expand Up @@ -519,7 +528,8 @@ override public void recordHandleException(Exception exception)
{
logMessageHandler(exception.Message, exception.StackTrace, LogType.Exception);
}



public static void logMessageHandler(string logString, string stackTrace, LogType type)
{
if (type == LogType.Exception)
Expand Down Expand Up @@ -554,7 +564,7 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp
if (pluginInstance != null)
{
Dictionary<string, object> attributes = new Dictionary<string, object>();
attributes.Add("logType", type.ToString());
attributes.Add("level", type.ToString());
attributes.Add("log", logString);
if (stackTrace.Length > 0)
{
Expand All @@ -580,7 +590,7 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp
}
}

pluginInstance.CallStatic<Boolean>("recordCustomEvent", "Mobile Unity Logs", mapInstance);
pluginInstance.CallStatic("logAttributes", mapInstance);
}


Expand Down Expand Up @@ -716,6 +726,65 @@ public override void setMaxOfflineStorageSize(uint megabytes)
{
pluginInstance.CallStatic("setMaxOfflineStorageSize", megabytes);
}

public override void LogInfo(string message)
{
pluginInstance.CallStatic("logInfo", message);

}

public override void LogError(string message)
{
pluginInstance.CallStatic("logError", message);
}

public override void LogVerbose(string message)
{
pluginInstance.CallStatic("logVerbose", message);
}

public override void LogWarning(string message)
{
pluginInstance.CallStatic("logWarning", message);
}

public override void LogDebug(string message)
{
pluginInstance.CallStatic("logDebug", message);
}

public override void Log(NewRelicAgent.AgentLogLevel level, string message)
{
String logLevel = "INFO";

if(level == NewRelicAgent.AgentLogLevel.ERROR)
{
logLevel = "ERROR";
}
else if(level == NewRelicAgent.AgentLogLevel.VERBOSE)
{
logLevel = "VERBOSE";
}
else if(level == NewRelicAgent.AgentLogLevel.WARNING)
{
logLevel = "WARNING";
}
else if(level == NewRelicAgent.AgentLogLevel.DEBUG)
{
logLevel = "DEBUG";
}

Dictionary<string,object> attributes = new Dictionary<string, object>();
attributes.Add("level",logLevel);
attributes.Add("message",message);
LogAttributes(attributes);
}

public override void LogAttributes(Dictionary<string, object> attributes)
{
AndroidJavaObject javaMap = CreateJavaMapFromDictionary(attributes);
pluginInstance.CallStatic("logAttributes", javaMap);
}
}
}

Expand Down
86 changes: 84 additions & 2 deletions com.newrelic.agent/Scripts/Native/NewRelicIos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ private static extern void NR_noticeNetworkFailure(string url,

[DllImport("__Internal")]
private static extern void NR_recordHandledExceptionWithStackTrace(System.IntPtr attributes);

[DllImport("__Internal")]
private static extern void NR_logInfo(string message);

[DllImport("__Internal")]
private static extern void NR_logError(string message);

[DllImport("__Internal")]
private static extern void NR_logWarning(string message);

[DllImport("__Internal")]
private static extern void NR_logVerbose(string message);

[DllImport("__Internal")]
private static extern void NR_logDebug(string message);

[DllImport("__Internal")]
private static extern void NR_logAttributes(System.IntPtr nSDict);





public void useSSL(bool useSSL)
{
Expand Down Expand Up @@ -486,6 +508,7 @@ override public void recordHandleException(Exception exception)
{
logMessageHandler(exception.Message, exception.StackTrace, LogType.Exception);
}


override public bool recordBreadcrumb(string name, Dictionary<string, object> attributes)
{
Expand Down Expand Up @@ -600,9 +623,9 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp

NR_dictionaryInsertString(attributes, "log", logString);
NR_dictionaryInsertString(attributes, "stacktrace", stackTrace);
NR_dictionaryInsertString(attributes, "logType", type.ToString());
NR_dictionaryInsertString(attributes, "logLevel", type.ToString());

NR_recordCustomEvent("Mobile Unity Logs", attributes);
NR_logAttributes(attributes);

}
}
Expand Down Expand Up @@ -702,6 +725,65 @@ public override void noticeHttpTransaction(string url, string httpMethod, int st
NR_noticeNetworkRequest(url, httpMethod, statusCode, startTime, endTime, bytesSent, bytesReceived, responseBody, NSDict);

}

public override void LogInfo(string message)
{
NR_logInfo(message);

}

public override void LogError(string message)
{
NR_logError(message);
}

public override void LogVerbose(string message)
{
NR_logVerbose(message);
}

public override void LogWarning(string message)
{
NR_logWarning(message);
}

public override void LogDebug(string message)
{
NR_logDebug(message);
}

public override void Log(NewRelicAgent.AgentLogLevel level, string message)
{
String logLevel = "INFO";

if(level == NewRelicAgent.AgentLogLevel.ERROR)
{
logLevel = "ERROR";
}
else if(level == NewRelicAgent.AgentLogLevel.VERBOSE)
{
logLevel = "VERBOSE";
}
else if(level == NewRelicAgent.AgentLogLevel.WARNING)
{
logLevel = "WARNING";
}
else if(level == NewRelicAgent.AgentLogLevel.DEBUG)
{
logLevel = "DEBUG";
}

Dictionary<string,object> attributes = new Dictionary<string, object>();
attributes.Add("logLevel",logLevel);
attributes.Add("message",message);
LogAttributes(attributes);
}

public override void LogAttributes(Dictionary<string, object> attributes)
{
System.IntPtr NSDict = CreateNSDictionaryFromDictionary(attributes);
NR_logAttributes(NSDict);
}
}

internal class StackFrame
Expand Down
12 changes: 12 additions & 0 deletions com.newrelic.agent/Scripts/Native/NewRelicUnityPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ extern "C" {

extern bool NR_setUserId(const char* userId);

extern void NR_logInfo(const char* message);

extern void NR_logError(const char* message);

extern void NR_logWarning(const char* message);

extern void NR_logVerbose(const char* message);

extern void NR_logDebug(const char* message);

extern void NR_logAttributes(NSDictionary* attributes);

extern void NR_NewRelic_crash();
#ifdef __cplusplus
}
Expand Down
30 changes: 27 additions & 3 deletions com.newrelic.agent/Scripts/Native/NewRelicUnityPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,33 @@ extern void NR_recordHandledExceptionWithStackTrace(NSDictionary* attributes){
}


extern bool NR_setUserId(const char* userId){
return [NewRelic setUserId:[NSString stringWithUTF8String:userId]];
}
extern bool NR_setUserId(const char* userId){
return [NewRelic setUserId:[NSString stringWithUTF8String:userId]];
}

extern void NR_logInfo(const char* message){
[NewRelic logInfo:[NSString stringWithUTF8String:message]];
}

extern void NR_logError(const char* message){
[NewRelic logError:[NSString stringWithUTF8String:message]];
}

extern void NR_logWarning(const char* message){
[NewRelic logWarning:[NSString stringWithUTF8String:message]];
}

extern void NR_logVerbose(const char* message){
[NewRelic logVerbose:[NSString stringWithUTF8String:message]];
}

extern void NR_logDebug(const char* message){
[NewRelic logDebug:[NSString stringWithUTF8String:message]];
}

extern void NR_logAttributes(NSDictionary* attributes){
[NewRelic logAttributes:attributes];
}

#ifdef __cplusplus
}
Expand Down
16 changes: 15 additions & 1 deletion com.newrelic.agent/Scripts/NewRelic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ abstract public void noticeNetworkFailure(string url,
abstract public bool removeAllAttributes();

abstract public void recordHandleException(Exception exception);

abstract public bool recordBreadcrumb(string name, Dictionary<string, object> attributes);

abstract public bool recordCustomEvent(string eventName, Dictionary<string, object> attributes);
Expand All @@ -310,6 +310,20 @@ abstract public void noticeNetworkFailure(string url,
abstract public bool setUserId(string userId);

abstract public void setMaxOfflineStorageSize(uint megabytes);

abstract public void LogInfo(String message);

abstract public void LogError(String message);

abstract public void LogVerbose(String message);

abstract public void LogWarning(String message);

abstract public void LogDebug(String message);

abstract public void Log(NewRelicAgent.AgentLogLevel level, String message);

abstract public void LogAttributes(Dictionary<string, object> attributes);



Expand Down
Loading

0 comments on commit f69031e

Please sign in to comment.