1

I'm trying to trace where errors occur in my code using Sentry. To achieve this, I'm uploading source maps to Sentry during the build stage in CodeBuild. In the post_build phase, I use these commands:

sentry-cli sourcemaps inject --org numu-04 --project numu-node-api ./dist
sentry-cli sourcemaps upload --org numu-04 --project numu-node-api ./dist --url-prefix '~/var/app/current/src'

Build artifacts are uploaded to Sentry after the build, and the same code is uploaded to Beanstalk. I verified this by downloading both files.

However, when an error is captured by Sentry, it doesn't show the exact location in the code where the error occurred. although it did show correct line number

Sentry error trace

event JSON

Sentry Uploaded Source Map File

relevant file i downloaded from beanstalk

"use strict";
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="18a58218-****-****-****-9fc9262b7d65")}catch(e){}}();


var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _utils = require("../../utils");
var _base = require("../base/base.service");
var _country = require("../country");
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var SentryService = /*#__PURE__*/function (_BaseService) {
  function SentryService() {
    (0, _classCallCheck2["default"])(this, SentryService);
    return _callSuper(this, SentryService, arguments);
  }
  (0, _inherits2["default"])(SentryService, _BaseService);
  return (0, _createClass2["default"])(SentryService, [{
    key: "fetchSentryCountry",
    value: // this service has error in it
    // so we can throw error on sentry
    // to test its functionality
    function () {
      var _fetchSentryCountry = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
        return _regenerator["default"].wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              _context.prev = 0;
              _context.next = 3;
              return _country.CountryService.findByPk({
                id: 0
              }).then(function (data) {
                data.map(function (country) {
                  return country.name;
                });
              })["catch"](function (error) {
                throw new _utils.AppError({
                  error: error
                });
              });
            case 3:
              _context.next = 8;
              break;
            case 5:
              _context.prev = 5;
              _context.t0 = _context["catch"](0);
              throw new _utils.AppError({
                error: _context.t0
              });
            case 8:
            case "end":
              return _context.stop();
          }
        }, _callee, null, [[0, 5]]);
      }));
      function fetchSentryCountry() {
        return _fetchSentryCountry.apply(this, arguments);
      }
      return fetchSentryCountry;
    }()
  }]);
}(_base.BaseService);
var _default = exports["default"] = new SentryService();
//# sourceMappingURL=sentry.service.js.map
//# debugId=18a58218-****-****-****-9fc9262b7d65

**relevant file i downloaded from uploaded build artefact on sentry **

"use strict";
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="18a58218-****-****-****-9fc9262b7d65")}catch(e){}}();


var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _utils = require("../../utils");
var _base = require("../base/base.service");
var _country = require("../country");
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var SentryService = /*#__PURE__*/function (_BaseService) {
  function SentryService() {
    (0, _classCallCheck2["default"])(this, SentryService);
    return _callSuper(this, SentryService, arguments);
  }
  (0, _inherits2["default"])(SentryService, _BaseService);
  return (0, _createClass2["default"])(SentryService, [{
    key: "fetchSentryCountry",
    value: // this service has error in it
    // so we can throw error on sentry
    // to test its functionality
    function () {
      var _fetchSentryCountry = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
        return _regenerator["default"].wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              _context.prev = 0;
              _context.next = 3;
              return _country.CountryService.findByPk({
                id: 0
              }).then(function (data) {
                data.map(function (country) {
                  return country.name;
                });
              })["catch"](function (error) {
                throw new _utils.AppError({
                  error: error
                });
              });
            case 3:
              _context.next = 8;
              break;
            case 5:
              _context.prev = 5;
              _context.t0 = _context["catch"](0);
              throw new _utils.AppError({
                error: _context.t0
              });
            case 8:
            case "end":
              return _context.stop();
          }
        }, _callee, null, [[0, 5]]);
      }));
      function fetchSentryCountry() {
        return _fetchSentryCountry.apply(this, arguments);
      }
      return fetchSentryCountry;
    }()
  }]);
}(_base.BaseService);
var _default = exports["default"] = new SentryService();
//# sourceMappingURL=sentry.service.js.map
//# debugId=18a58218-****-****-****-9fc9262b7d65

both are same

Yaml file for codeBuild

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 18
    commands:
      - n 18.17.1
  pre_build:
    commands:
      - echo Starting npm install
      - npm install --legacy-peer-deps && npm install --only=dev --legacy-peer-deps
      - npm i -g sequelize-cli
      - npm install -g @sentry/cli
  build:
    commands:
      - echo Starting to run migrations
      - echo Starting npm build
      - npm run build --loglevel verbose
      - npm prune --production
      - sentry-cli sourcemaps inject --org numu-04 --project numu-node-api ./dist
  post_build:
    commands:
      - echo "Uploading source maps to Sentry"
      - sentry-cli sourcemaps upload --org numu-04 --project numu-node-api ./dist --url-prefix '~/var/app/current/src'
artifacts:
  files:
    - package.json
    - package-lock.json
    - dist/**/*
    - node_modules/**/*
    - .ebextensions/**/*
    - .platform/**/*
    - .npmrc

for reference where try to unminify code

I want Sentry to show the exact line of code where an error occurred, including displaying specific code in that line. However, even though Sentry shows the correct line number, it doesn't display corresponding code.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.