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

v7 collectUserIP missing? #844

Closed
derduher opened this issue May 8, 2020 · 9 comments · Fixed by #847
Closed

v7 collectUserIP missing? #844

derduher opened this issue May 8, 2020 · 9 comments · Fixed by #847
Labels
bug Confirmed bug released This feature/bug fix has been released

Comments

@derduher
Copy link

derduher commented May 8, 2020

I'm upgrading to v7 and I'm getting a type error on collectUserIP

import Bugsnag from '@bugsnag/js';
import BugsnagPluginReact from '@bugsnag/plugin-react';
Bugsnag.start({
  appType: 'client',
  appVersion: GIT_SHA,
  apiKey: BUGSNAG_KEY,
  autoDetectErrors: true,
  releaseStage: ENVIRONMENT,
  enabledReleaseStages: ['prod', 'qa', 'active'],
  collectUserIp: false,
  redactedKeys: [/token/i, /password/i, /name/i, /email/i, /phone/i],
  plugins: [new BugsnagPluginReact(React)],
});
Argument of type '{ appType: string; appVersion: string; apiKey: string; autoDetectErrors: true; releaseStage: string; enabledReleaseStages: string[]; collectUserIp: boolean; redactedKeys: RegExp[]; plugins: BugsnagPluginReact[]; }' is not assignable to parameter of type 'string | Config'.
  Object literal may only specify known properties, and 'collectUserIp' does not exist in type 'Config'.ts(2345)

The Definition for config appears to be at node_modules/@bugsnag/browser/dist/types/bugsnag-core/common.d.ts

Was collectUserIP removed as an option? if so is there a suggested way to migrate?

@abigailbramble
Copy link

Hi @derduher

collectUserIP is still a config option available to be set as part of your config:
https://github.com/bugsnag/bugsnag-js/blob/v7.0.0/packages/browser/types/bugsnag.d.ts#L5

Using your Bugsnag.start method above in our React example app works fine:
https://github.com/bugsnag/bugsnag-js/tree/v7.0.0/examples/react

Are you able to get this example working?
Is this a purely React app you are building?

@abigailbramble abigailbramble added the awaiting feedback Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks. label May 8, 2020
@derduher
Copy link
Author

derduher commented May 8, 2020

I'll try and paste a CRA sample repo. If you say that the option still exists, then it may just be a type definition bug (or documentation).

@derduher
Copy link
Author

@phillipsam Here is a sample repo created using npx create-react-app cra --use-npm --typescript. I committed the bugsnag additions separate from the initial generations so you can see what I added.

After cloning the repo. npm install then npm run build

You'll see the above pasted type error.

@abigailbramble abigailbramble removed the awaiting feedback Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks. label May 11, 2020
@abigailbramble
Copy link

abigailbramble commented May 11, 2020

Hi @derduher thanks for the reproduction example!

It looks like you are using the wrong method of including Bugsnag for your module system:
https://docs.bugsnag.com/platforms/javascript/react/#basic-configuration

Currently the example is using:

import Bugsnag from '@bugsnag/js'
import BugsnagPluginReact from '@bugsnag/plugin-react'

If you remove these two lines and replace with:

var Bugsnag = require('@bugsnag/js')
var BugsnagPluginReact = require('@bugsnag/plugin-react')

This then compiles correctly.

@derduher
Copy link
Author

@phillipsam Although they compile they lose all type safety as they now register as type 'any'. I've updated my example to point this out. The option 'asdf' is not valid and should not compile.

import is the correct method in create react app and require is generally frowned upon. As create react app is one of the most popular ways to create a react app you are likely to encounter this issue being filed by users again.

I think the right thing to do here would be to fix the typedef.

@derduher
Copy link
Author

Bugsnag is of type UniversalBugsnagStatic https://github.com/bugsnag/bugsnag-js/blob/next/packages/js/types.d.ts#L9
Your dist code appears to be including the typedef at https://github.com/bugsnag/bugsnag-js/blob/next/packages/core/types/bugsnag.d.ts#L4
instead of the typedef here
https://github.com/bugsnag/bugsnag-js/blob/next/packages/browser/types/bugsnag.d.ts#L9

note the different acceptable config types

@abigailbramble
Copy link

@derduher thanks! Looks like we have missed an update in our changes for v7. This should be start instead of init:

init(apiKeyOrOpts: string | BrowserConfig | NodeConfig): Client

We will look at getting this fixed.

@abigailbramble abigailbramble added backlog We hope to fix this feature/bug in the future bug Confirmed bug labels May 11, 2020
@bugsnagbot bugsnagbot added scheduled Work is starting on this feature/bug and removed backlog We hope to fix this feature/bug in the future labels May 12, 2020
@mattdyoung
Copy link
Contributor

Fixed in v7.0.2

@mattdyoung mattdyoung added released This feature/bug fix has been released and removed scheduled Work is starting on this feature/bug labels May 12, 2020
@derduher
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug released This feature/bug fix has been released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants