Skip to content

Promise in transport appears to invoke twice #2506

Description

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

5.14.2

Description

I'm working on setting up Sentry in a React application and extending the FetchTransport to add a metric on the response of the request sentry.io. Debugging through the application shows my promise being invoked twice for each sendEvent call of the transport. A simplified version of my transport that still displays this is as follows:

import * as Sentry from '@sentry/browser';

export class WrappedFetchTransport extends Sentry.Transports.FetchTransport {

    public sendEvent(event: Sentry.Event): PromiseLike<Sentry.Response> {
        const promise = super.sendEvent(event);
        promise.then(
            (resp: any) => {
                console.log(resp);
            },
            (reason: any) => {
                console.log("error");
            }
        );

        return promise;
    }
}

Activity

  1. changed the title [-]Promise in Transport appears to invoke twice[/-] [+]Promise in transport appears to invoke twice[/+] on Mar 19, 2020
  2. kamilogorek commented on Mar 19, 2020

    @kamilogorek
    Contributor

    Are you using development environment of React? If so, it triggers errors twice in that mode. Please see Note: https://docs.sentry.io/platforms/javascript/react/#error-boundaries

  3. christopher-taormina-zocdoc commented on Mar 19, 2020

    @christopher-taormina-zocdoc
    Author

    @kamilogorek My component isn't extending from an ErrorBoundary currently. Additionally, it doesn't look like the sendEvent method is being called twice, just the code that I've defined in that promise.then. I've even hooked up to a test project and only see one event logged.

  4. christopher-taormina-zocdoc commented on Mar 20, 2020

    @christopher-taormina-zocdoc
    Author

    @kamilogorek I have an example I've tested in chrome that seems to duplicate this issue. I've been able to pin this down seemingly to being introduced in version 5.8. Running the below with 5.7 correctly calls the promise once, while running it with 5.8 calls it twice.

        <head>
            <script src="https://browser.sentry-cdn.com/5.14.2/bundle.min.js"></script>
            <script type="">
    
                var __extends = (this && this.__extends) || (function () {
                var extendStatics = function (d, b) {
                    extendStatics = Object.setPrototypeOf ||
                        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
                        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
                    return extendStatics(d, b);
                }
                return function (d, b) {
                    extendStatics(d, b);
                    function __() { this.constructor = d; }
                    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
                };
                })();
    
                var WrappedFetchTransport = /** @class */ (function (_super) {
                    __extends(WrappedFetchTransport, _super);
                    function WrappedFetchTransport() {
                        return _super !== null && _super.apply(this, arguments) || this;
                    }
                    /**
                     * @inheritDoc
                     */
                    WrappedFetchTransport.prototype.sendEvent = function (event) {
                        var promise = _super.prototype.sendEvent.call(this, event);
                        promise.then(function () {
                            console.log("success");
                        }, function (response) {
                            console.log("error");
                        });
                        return promise;
                    };
                    return WrappedFetchTransport;
                }(Sentry.Transports.FetchTransport));
    
                Sentry.init({ dsn: '__SENTRY_DSN__', transport: WrappedFetchTransport });
    
                throw Error("its an error");
            </script>
        </head>
        <body>
            <h1>Hi</hi>
        </body>
    </html>
    
  5. christopher-taormina-zocdoc commented on Mar 25, 2020

    @christopher-taormina-zocdoc
    Author

    @kamilogorek will this fix be released soon?

  6. kamilogorek commented on Mar 25, 2020

    @kamilogorek
    Contributor

    @christopher-taormina-zocdoc sometime tomorrow (thursday). I'll ping you.

  7. kamilogorek commented on Mar 26, 2020

    @kamilogorek
    Contributor

    @christopher-taormina-zocdoc released as 5.15.1

  8. christopher-taormina-zocdoc commented on Mar 26, 2020

    @christopher-taormina-zocdoc
    Author

    Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions