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

Incompatibility with loopback-connector-rest #8549

Closed
3 tasks done
Ojvar opened this issue Jul 17, 2023 · 8 comments
Closed
3 tasks done

Incompatibility with loopback-connector-rest #8549

Ojvar opened this issue Jul 17, 2023 · 8 comments

Comments

@Ojvar
Copy link

Ojvar commented Jul 17, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

23.6.2

Framework Version

^7.58.1

Link to Sentry event

No response

SDK Setup

 Sentry.init({
    dsn: "MY DSN :) ",
    tracesSampleRate: 1.0,
  });

Steps to Reproduce

Today, I've faced with a strange problem while using sentry in loopback framework
I defined a datasource (Rest Datasource), with a POST method on it

  {
        template: {
          method: 'POST',
          url: `${baseURL}/realms/{realm}/protocol/openid-connect/token`,
          headers: {
            accept: 'text/plain',
            'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
          },
          form: {
            username: '{username}',
            password: '{password}',
            grant_type: 'password',
            client_id: '{clientId}',
            scope: '{scopes}',
          },
        },
        functions: {
          getToken: ['realm', 'username', 'password', 'clientId', 'scopes'],
        },
      },

Without using this snippet, I can call the getToken api correctly, and I get keycloak (my remote service) data of authenticated user,

I think Sentry inner HttpWarpper module, modified original request and can't send it as it was
Is there anybody help me to solve this?
thanks ;)

Expected Result

I expect, by using Loopback-Connector-Rest in my loopback application, while using Sentry module, I could call my remote functions (with all methods GET, POST, PUSH,PUT, ...) correctly, and I receive data in json or other format

Actual Result

but, after adding that snippet, every thing was go wrong with POST, PUT, PATCH (else GET) requests
and I just receive this error:

{"error":{"statusCode":406,"name":"Error","message":"{\"error\":\"RESTEASY003635: No match for accept header\"}"}}
@Ojvar
Copy link
Author

Ojvar commented Jul 17, 2023

I create an example of loopback app

https://github.com/Ojvar/sentry-bug-in-loopback4

in the index.ts, by calling initSentry() function, we faced with unexpected behavior :(

in this example after enabling sentry
by calling this route

curl -X 'GET' \
  'http://localhost:3000/ping-get' \
  -H 'accept: application/json'

I received this output

{
  "error": {
    "statusCode": 404,
    "name": "Error",
    "message": "{\"error\":{\"statusCode\":404,\"name\":\"NotFoundError\",\"message\":\"Endpoint \\\"POST /\\\" not found.\"}}"
  }
}

but, by disabling sentry,
I receive the correct output

{
  "greeting": "Hello from LoopBack",
  "date": "2023-07-17T10:38:05.352Z",
  "url": "/ping",
  "headers": {
    "host": "localhost:3000",
    "accept": "application/json",
    "content-length": "0",
    "connection": "keep-alive"
  }
}

@Ojvar
Copy link
Author

Ojvar commented Jul 18, 2023

After a day of code reviewing of loopback-connector-rest package, if found that there is a incompatibility between sentry and request npm package that is used by loopback-connector-rest
;(

@mydea
Copy link
Member

mydea commented Jul 19, 2023

Hello, thanks for writing in.

I've just checked out your reproduction, run yarn install && yarn start, and run the GET curl you provided, and I got the correct response? So not sure if you changed something in the repro, but I cannot reproduce any problem?

To rule out any difference, what node version are you using? I am running Node 16, fwiw.

@Ojvar
Copy link
Author

Ojvar commented Jul 20, 2023 via email

@Ojvar
Copy link
Author

Ojvar commented Jul 20, 2023 via email

@mydea
Copy link
Member

mydea commented Jul 20, 2023

OK, that seems to be it, I can reproduce it on node 20. It works in Node 18, but not 20 for me.

Now, I wonder if that is a problem on our side or in one of the dependencies... 🤔 It does seem to be related to the Http integration.

While we try to figure out what's going on, you can disable the HTTP integrations like this:

 Sentry.init({
    dsn: 'xxx',
    tracesSampleRate: 1.0,
     integrations: function (integrations) {
      // integrations will be all default integrations
      return integrations.filter(integration => integration.name !== 'Http');
    }, 
  });

That should make it run at least (but it will miss http traces/breadcrumbs - but better than nothing!)

@Ojvar
Copy link
Author

Ojvar commented Jul 22, 2023

Thank you
Your solution was worked for me too (I changed node version to 18)
I will wait for fixed version :)))

@mydea
Copy link
Member

mydea commented Jul 26, 2023

FYI I will close this in favor of #8552, which describes the same issue (request & node 20 & sentry = fail). It seems the problem is in Node 20 (or can/should be fixed there), see: nodejs/node#48921

Thank you for opening this, I suggest you watch #8552, we will keep this updated!

@mydea mydea closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants