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

Console debug issue #185

Merged
merged 5 commits into from
Aug 21, 2024
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 1.4.2

## New Features

1. **Distributed Tracing Control**
- Introducing a new feature flag: `distributedTracingEnabled`, providing the ability to enable or disable distributed tracing functionality.

## Bug Fixes

- Addressed an issue where console debug logs were incorrectly displayed as console errors.


## 1.4.1
## New Features

Expand Down
74 changes: 47 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ import {Platform} from 'react-native';

// iOS Specific
// Optional: Enable or disable to use our new, more stable, event system for iOS agent.
newEventSystemEnabled:false
newEventSystemEnabled:false,

// Optional: Enable or disable distributed tracing.
distributedTracingEnabled: true,
};


Expand All @@ -126,33 +129,50 @@ AppToken is platform-specific. You need to generate the seprate token for Androi

### Android Setup
1. Install the New Relic native Android agent ([instructions here](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-android/install-configure/install-android-apps-gradle-android-studio)).
2. Update `build.gradle`:
```groovy
buildscript {
...
repositories {
...
mavenCentral()
}
dependencies {
...
classpath "com.newrelic.agent.android:agent-gradle-plugin:7.5.0"
}
}
```

3. Update `app/build.gradle`:
```groovy
plugins {
id 'newrelic'
}
```
For legacy plugin application:
```groovy
apply plugin: 'newrelic'
```

4. Make sure your app requests INTERNET and ACCESS_NETWORK_STATE permissions by adding these lines to your `AndroidManifest.xml`
2. Add the following changes to Apply Gradle Plugin:

If you are using Plugins DSL to Apply the NewRelic Gradle Plugin, make the following changes:

In android/settings.gradle:
```groovy
plugins {
id "com.android.application" version "7.4.2" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.newrelic.agent.android" version "7.5.1" apply false // <-- include this
}
```

In android/app/build.gradle:
```groovy
plugins {
id "com.android.application"
id "kotlin-android"
id "com.newrelic.agent.android" //<-- include this
}
```

Or, if you are using the traditional way to apply the plugin:
```groovy
buildscript {
...
repositories {
...
mavenCentral()
}
dependencies {
...
classpath "com.newrelic.agent.android:agent-gradle-plugin:7.5.1"
}
}
```

Apply the NewRelic plugin to the top of the android/app/build.gradle file:
```groovy
apply plugin: "com.android.application"
apply plugin: 'newrelic' // <-- include this
```
3. Make sure your app requests INTERNET and ACCESS_NETWORK_STATE permissions by adding these lines to your `AndroidManifest.xml`
```
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/com/NewRelic/NRMModularAgentModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ public void startAgent(String appKey, String agentVersion, String reactNativeVer
NewRelic.disableFeature(FeatureFlag.BackgroundReporting);
}

if ((Boolean) agentConfig.get("distributedTracingEnabled")) {
NewRelic.enableFeature(FeatureFlag.DistributedTracing);
} else {
NewRelic.disableFeature(FeatureFlag.DistributedTracing);
}

Map<String, Integer> strToLogLevel = new HashMap<>();
strToLogLevel.put("ERROR", AgentLog.ERROR);
strToLogLevel.put("WARNING", AgentLog.WARN);
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class NewRelic {
fedRampEnabled: false,
offlineStorageEnabled: true,
backgroundReportingEnabled: false,
newEventSystemEnabled: true
newEventSystemEnabled: false,
distributedTracingEnabled: true,
};
}

Expand Down Expand Up @@ -638,6 +639,7 @@ class NewRelic {
const defaultLog = console.log;
const defaultWarn = console.warn;
const defaultError = console.error;
const defaultDebug = console.debug;
const self = this;

console.log = function () {
Expand All @@ -655,7 +657,7 @@ class NewRelic {

console.debug = function () {
self.sendConsole('debug', arguments);
defaultError.apply(console, arguments);
defaultDebug.apply(console, arguments);
}


Expand All @@ -675,7 +677,7 @@ class NewRelic {
}else {
this.logInfo("[CONSOLE][LOG]" +argsStr);
}

}

}
Expand Down
4 changes: 4 additions & 0 deletions ios/bridge/NRMModularAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ - (dispatch_queue_t)methodQueue{
if ([[agentConfig objectForKey:@"newEventSystemEnabled"]boolValue] == YES) {
[NewRelic enableFeatures:NRFeatureFlag_NewEventSystem];
}

if ([[agentConfig objectForKey:@"distributedTracingEnabled"]boolValue] == NO) {
[NewRelic enableFeatures:NRFeatureFlag_DistributedTracing];
}

//Default is NRLogLevelWarning
NRLogLevels logLevel = NRLogLevelWarning;
Expand Down
9 changes: 5 additions & 4 deletions new-relic/__tests__/new-relic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ describe('New Relic', () => {
expect(NewRelic.agentConfiguration.fedRampEnabled).toBe(false);
expect(NewRelic.agentConfiguration.nativeCrashReportingEnabled).toBe(true);
expect(NewRelic.agentConfiguration.offlineStorageEnabled).toBe(true);
expect(NewRelic.agentConfiguration.newEventSystemEnabled).toBe(true);
expect(NewRelic.agentConfiguration.newEventSystemEnabled).toBe(false);
expect(NewRelic.agentConfiguration.backgroundReportingEnabled).toBe(false);

expect(NewRelic.agentConfiguration.distributedTracingEnabled).toBe(true);
});

it('should change default agent configuration when configuration is passed into the start call', () => {
Expand All @@ -107,7 +107,8 @@ describe('New Relic', () => {
nativeCrashReportingEnabled:false,
offlineStorageEnabled:false,
newEventSystemEnabled:false,
backgroundReportingEnabled:true
backgroundReportingEnabled:true,
distributedTracingEnabled: false
};

NewRelic.startAgent("12345", customerConfiguration);
Expand All @@ -128,7 +129,7 @@ describe('New Relic', () => {
expect(NewRelic.agentConfiguration.nativeCrashReportingEnabled).toBe(false);
expect(NewRelic.agentConfiguration.newEventSystemEnabled).toBe(false);
expect(NewRelic.agentConfiguration.backgroundReportingEnabled).toBe(true);

expect(NewRelic.agentConfiguration.distributedTracingEnabled).toBe(false);
});

it('should set the analytics event flag', () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newrelic-react-native-agent",
"version": "1.4.1",
"version": "1.4.2",
"description": "A New Relic Mobile Agent for React Native",
"main": "./index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -92,7 +92,7 @@
},
"sdkVersions": {
"ios": {
"newrelic": "7.5.0"
"newrelic": "~>7.5.1"
},
"android": {
"newrelic": "7.5.+",
Expand Down
Loading