Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
- Bump Instabug iOS SDK to v14.0.0 ([#1312](https://github.com/Instabug/Instabug-React-Native/pull/1312)). [See release notes](https://github.com/Instabug/Instabug-iOS/releases/tag/14.0.0).
- Bump Instabug Android SDK to v14.0.0 ([#1312](https://github.com/Instabug/Instabug-React-Native/pull/1312)). [See release notes](https://github.com/Instabug/Instabug-Android/releases/tag/v14.0.0).

### Added

- Exclude DEV server from network logs ([#1307](https://github.com/Instabug/Instabug-React-Native/pull/1307)).

### Fixed

- Replace thrown errors with logs ([#1220](https://github.com/Instabug/Instabug-React-Native/pull/1220))
Expand Down
8 changes: 8 additions & 0 deletions src/modules/Instabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { captureUnhandledRejections } from '../utils/UnhandledRejectionTracking'
import type { ReproConfig } from '../models/ReproConfig';
import type { FeatureFlag } from '../models/FeatureFlag';
import InstabugConstants from '../utils/InstabugConstants';
import { InstabugRNConfig } from '../utils/config';

let _currentScreen: string | null = null;
let _lastScreen: string | null = null;
Expand Down Expand Up @@ -633,6 +634,13 @@ export const willRedirectToStore = () => {
NativeInstabug.willRedirectToStore();
};

/**
* This API has be called when changing the default Metro server port (8081) to exclude the DEV URL from network logging.
*/
export const setMetroDevServerPort = (port: number) => {
InstabugRNConfig.metroDevServerPort = port.toString();
};

export const componentDidAppearListener = (event: ComponentDidAppearEvent) => {
if (_isFirstScreen) {
_lastScreen = event.componentName;
Expand Down
14 changes: 13 additions & 1 deletion src/modules/NetworkLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import type { RequestHandler } from '@apollo/client';

import InstabugConstants from '../utils/InstabugConstants';
import xhr, { NetworkData, ProgressCallback } from '../utils/XhrNetworkInterceptor';
import { reportNetworkLog, isContentTypeNotAllowed } from '../utils/InstabugUtils';
import { isContentTypeNotAllowed, reportNetworkLog } from '../utils/InstabugUtils';
import { InstabugRNConfig } from '../utils/config';

export type { NetworkData };

export type NetworkDataObfuscationHandler = (data: NetworkData) => Promise<NetworkData>;
let _networkDataObfuscationHandler: NetworkDataObfuscationHandler | null | undefined;
let _requestFilterExpression = 'false';

function getPortFromUrl(url: string) {
const portMatch = url.match(/:(\d+)(?=\/|$)/);
return portMatch ? portMatch[1] : null;
}

/**
* Sets whether network logs should be sent with bug reports.
* It is enabled by default.
Expand All @@ -27,6 +33,12 @@ export const setEnabled = (isEnabled: boolean) => {
network = await _networkDataObfuscationHandler(network);
}

if (__DEV__) {
const urlPort = getPortFromUrl(network.url);
if (urlPort === InstabugRNConfig.metroDevServerPort) {
return;
}
}
if (network.requestBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) {
network.requestBody = InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE;
console.warn('IBG-RN:', InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE);
Expand Down
1 change: 1 addition & 0 deletions src/utils/InstabugConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const InstabugConstants = {
'IBG-RN: Expected key and value passed to setUserAttribute to be of type string',
REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE:
'IBG-RN: Expected key and value passed to removeUserAttribute to be of type string',
DEFAULT_METRO_PORT: '8081',
};

export default InstabugConstants;
5 changes: 5 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import InstabugConstants from './InstabugConstants';

export const InstabugRNConfig = {
metroDevServerPort: InstabugConstants.DEFAULT_METRO_PORT,
};