microsoft / applicationinsights-react-native

Microsoft Application Insights React Native Plugin
MIT License
14 stars 5 forks source link

[BUG]Invalid regular expression: invalid group specifier name (V3.0.0) #10

Closed erez-unitronics closed 1 year ago

erez-unitronics commented 1 year ago

Upgrade library from 2.5.6 to 3.0.0 got this error:

Invalid regular expression: invalid group specifier name no stack

(@microsoft/applicationinsights-web version is 2.8.6)

MSNev commented 1 year ago

@erez-unitronics can you provide some more context?

As ApplicationInsights (v2) provides support for es3 runtimes I don't believe that we have defined any group "names" but the SDK does attempt to crack the stack by using these regex's

https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCommon/src/Telemetry/Exception.ts#L581

This one is to try and get the real "custom" error name https://github.com/microsoft/ApplicationInsights-JS/blob/master/shared/AppInsightsCommon/src/Telemetry/Exception.ts#L270

If it is the stack that is not being parsed correctly the if you could provide a couple of examples we should be able to update to support (assuming I'm guessing the issue correctly). Once fixed and released in AI react-native should pick up the newer version without needing a new release.

The actual exception processing was last changed in v2.6.3 as part of fixing issue #363 (in App Insights repo)

erez-unitronics commented 1 year ago

@MSNev thansk for the reply

Here is my code: (Which works perfectly on v2)

import { ApplicationInsights } from '@microsoft/applicationinsights-web'; import { ReactNativePlugin } from '@microsoft/applicationinsights-react-native';

import { AZURE_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY } from '../../../config/Config';

var RNPlugin = new ReactNativePlugin(); var ai = new ApplicationInsights({ config: { instrumentationKey: AZURE_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY, extensions: [RNPlugin] } }); ai.loadAppInsights();

export const trackEvent = (eventPath, message) => { ai.appInsights.trackEvent( { ..... }); };

And this is what i am getting when app is starting: (Android and IOS)

Screen Shot 2022-08-04 at 9 57 35
MSNev commented 1 year ago

Hmm, I've just looked at the changes from 2.5.6 to 3.0.0 and there are no new Regex's added by ApplicationInsights.

The biggest change is that v3 now uses ReactNative v0.69.3 and also properly supports the latest react-native-device-info...

So I don't think this issue is directly coming from the plugin ( and as v2.5.6 uses the same version as ApplicationInsights there either)....

Is there any more details that you can obtain from the "Unhandled Exception" that would help narrow down the source of this regular expression? -- Like a stack trace or if you can repo in an environment where you can set a breakpoint. If it contains the actual "invalid" regex that would also help narrow down the source to see if we have that RegEx in any of the source code that we control...

erez-unitronics commented 1 year ago

here is some logs from logcat:

08-07 16:11:14.745 5567 7028 E unknown:ReactNative: Exception in native call from JS 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: com.facebook.react.devsupport.JSException: Invalid regular expression: invalid group specifier name 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:755) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:95) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:154) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:761) 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: Caused by: com.facebook.jni.CppException: Invalid regular expression: invalid group specifier name 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: no stack 08-07 16:11:14.745 5567 7028 E unknown:ReactNative: ... 7 more

I am using node v16.10.0 if it helps

MSNev commented 1 year ago

I think its probably related to this React Native Issue https://github.com/facebook/react-native/issues/30714

Can you try and confirm to see if you can "see" the actual regular expression (as in the screen dump in the react native issue). As part of trimming, I believe that we have the same regex (which works in a browser).

MSNev commented 1 year ago

Just went searching across the ApplicationInsights code base looking for any "look-behind" instances and there are none in any of the currently released versions (we were going to use this in the upcoming beta's). So it would be really good if you could identify the specific regex that is causing grief.

I searched for ?< (look-behind) and ?= (look-ahead) to try and identify any possible regex that might be causing this.

MSNev commented 1 year ago

After doing some more reading to try and track this down I found another possible related issue https://github.com/facebook/react-native/issues/29271

erez-unitronics commented 1 year ago

I upgraded react native version from 0.69.3 to 0.69.4 (which released yesterday) and the error gone

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.