switchon@lavalamp.biz
australia flag +61(0) 42 420 8911
south africa flag +27(0) 21 036 1165
Application & software development
Get A Quote

  • Home
  • Services
    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI / UX design & consulting
    • Recruitment services
    • Lease an expert
  • About
    • NBConsult Group
    • Partners
    • Lightbox Digital
  • Blog
  • Join us
  • Contact

  • Home
  • Services
    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI / UX design & consulting
    • Recruitment services
    • Lease an expert
  • About
    • NBConsult Group
    • Partners
    • Lightbox Digital
  • Blog
  • Join us
  • Contact

  • Home
  • Services
    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI / UX design & consulting
    • Recruitment services
    • Lease an expert
  • About
    • NBConsult Group
    • Partners
    • Lightbox Digital
  • Blog
  • Join us
  • Contact
switchon@lavalamp.biz
Get A Quote

  • Home
  • Services
    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI / UX design & consulting
    • Recruitment services
    • Lease an expert
  • About
    • NBConsult Group
    • Partners
    • Lightbox Digital
  • Blog
  • Join us
  • Contact

  • Home
  • Services
    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI / UX design & consulting
    • Recruitment services
    • Lease an expert
  • About
    • NBConsult Group
    • Partners
    • Lightbox Digital
  • Blog
  • Join us
  • Contact
kill scripts
A Kill Script For Processes That Are Using TCP/UDP Ports
April 24, 2020
embedding website links into your android app
Embedding Website Links Into Your Android App
June 25, 2020

Unhandled Promises Sent Through To App Insights In Node JS

errors in app insights
errors in app insights

App Insights is great for monitoring services, logging metrics and analysing traces and exceptions. However I recently came across an issue where unhandle promises rejections showed up in App Insights as [object Promise]. Which is fine however the stack trace was not very helpful, showing that the error was thrown in the appinsights package itself.

The auto exception tracking feature of the appinsights node module catches unhandled Promise rejections which is great, but it doesn’t extract the message from them. In fact it checks whether the object it receives for tracking is an Error and when it finds out that it is not error, it throws an internal Error which is where the stack trace comes from.

To show the info inside a promise rejection, I made a wrapper around the trackException function on the defaultClient:

appInsights = require("applicationinsights");
let exceptionTrack = appInsights.defaultClient.trackException;
appInsights.defaultClient.trackException = function myExceptionTracker(telemetry) {
let exception = telemetry.exception
//How to test for a Promise
if (Promise.resolve(exception) == exception) {
exception.then(res => {
telemetry.exception = res;
exceptionTrack.call(appInsights.defaultClient, telemetry);
}, err => {
telemetry.exception = err;
exceptionTrack.call(appInsights.defaultClient, telemetry);
}).catch(error => {
telemetry.exception = error;
exceptionTrack.call(appInsights.defaultClient, telemetry);
})
} else {
exceptionTrack.call(appInsights.defaultClient, telemetry);
}
}
view raw trackExceptionWrapper.js hosted with ❤ by GitHub


The trackException wrapper function receives the object in telemetry.exception and tests whether it is a Promise and handles it accordingly, extracting the message from the Promise and changing the telemetry object before passing it on to the original trackException function.

Contact us


    Related posts:

    how to send a tweet from within your angular app via node jsHow To Send A Tweet From Within Your Angular App Via Node Js laravel livewireLaravel Livewire implementing laravel echoImplementing Laravel Echo And Socket.io With A Laravel API And Ionic Vue App how to deploy a backend api to azureHow To Deploy A Backend API To Azure
    Share
    82
    Tielman Janse van Vuuren
    Tielman Janse van Vuuren
    Tielman is an experienced mobile and backend developer. Quality is his motto, no matter what programming language or platform.

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    lava lamp lab secondary logo white

    Like technology, a lava lamp constantly changes form, producing new conditions with every passing moment


    lava lamp lab facebook   lava lamp lab twitter   lava lamp lab linkedin   lava lamp lab instgram

    Services

    • Application & software development
    • Outsourced software development
    • Project based resourcing
    • Digital marketing & consulting
    • Graphic design & consulting
    • UI/UX design & consulting
    • Recruitment services
    • Lease an expert

    Contact Us

    south africa+27(0) 83 419 4851

    south africa+27(0) 21 036 1165

    australia+61(0) 42 420 8911


    switchon@lavalamp.biz


    Lava Lamp Lab,
    Unit 1 Monaco Square, 14 Church Street, Durbanville, Cape Town, 7550

    NBConsult Group

    nbconsult
    designer needed
    © 2023 Lava Lamp Lab (Pty) Ltd | All Rights Reserved | Privacy Policy
        Business Automation

        Business-specific workflows assist our clients with Disaster recovery, time tracking and invoice generation, to mention a few. If you choose to outsource your enterprise app development, we work with you to understand your business and assist to deliver automation for great business efficiency.

        eCommerce Solutions

        We are industry experts in Fintech and eCommerce, Lava Lamp Lab will help you with custom software development to provide you with the quality software services for creating online shops, Fintech mobile apps and web presence for your business of any size, allowing you to engage, sell, support and collect payments.

        Startup & Innovation

        Lava Lamp Lab believes in helping you grow your idea into a business. Our team has provided outsourced services to multiple tech start-ups and investors over the last decade, delivering innovative solutions. We have been trusted over other software development companies to build their entire technology stack.

        Data Mining

        Key to any business is the processing of websites and social network APIs, aligning the information gathered to information collected from internal enterprise systems. This big data can be rendered on reporting dashboards to create Business Intelligence. You can entrust Lava Lamp Lab to reliably deliver on this.

        Contact us now

          Application & software development

            Outsourced software development

              Project based resourcing

                Digital marketing & consulting

                  Graphic design & consulting

                    UI/UX design & consulting

                      Lease an expert

                        Recruitment services

                          We are using cookies to give you the best experience on our website.

                          You can find out more about which cookies we are using or switch them off in .

                          Lava Lamp Lab
                          Powered by  GDPR Cookie Compliance
                          Privacy Overview

                          This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

                          Strictly Necessary Cookies

                          Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

                          If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

                          3rd Party Cookies

                          This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

                          Keeping this cookie enabled helps us to improve our website.

                          Please enable Strictly Necessary Cookies first so that we can save your preferences!

                          Cookie Policy

                          More information about our Cookie Policy