DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Source-Driven Development in Salesforce: Managing Metadata and API Versions
  • How to Introduce a New API Quickly Using Micronaut
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  • Efficient API Communication With Spring WebClient

Trending

  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Avoid Printing Exception Stack Traces

How to Avoid Printing Exception Stack Traces

Stack traces have been around in the software development world for quite some time now, but it can't be ignored that they can create major issues for Operations teams.

By 
Alagappan Veerappan user avatar
Alagappan Veerappan
·
Feb. 12, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
14.1K Views

Join the DZone community and get the full member experience.

Join For Free

This article explains how to avoid printing exception stack traces when running APIs that are configured with Mule EE runtime and Mule API gateway runtime.

Printing exception stack traces is not a new concept in the software world. However, it's still important to remember that if the stack traces are not handled properly, they will end up accumulating in log files. This can create issues for the Operations team when they want to manage higher environments.

We will discuss here some steps for both Mule EE and API gateway runtimes. The latest Mule EE runtime is 3.8.2. Older versions (< 3.8.X) have Mule EE runtime and API gateway runtime separately.

API gateway runtime is a feature to support the sharing of connectors across the projects deployed in the domain. However, there's a lot more to it than that. To know more about API gateway runtime, check out this documentation from MuleSoft. Mule EE 3.8.2 runtime has unified both API gateway and Mule core runtime.

Avoid Exception Stack Traces With Mule 3.8 Runtime

Configure the logException attribute as false in the catch-exception-strategy block. By default, logException is set as true, which enables Mule to print an exception stack trace. 

Here's an example snippet:

<catch-exception-strategy doc:name="Catch Exception Strategy" logException="false">
 <logger level="ERROR" doc:name="exceptionLogger" message="Exception message is ... #[exception.message]"/>
  <set-variable variableName="exceptionMessage" value="#[exception.message]" doc:name="Set exceptionMessage"/>
  <set-payload value="{  errors: {     errorCode: #[message.inboundProperties.'http.status'],     errorMessage: #[flowVars.exceptionMessage]  }  }" doc:name="Set Exception Payload"/>
</catch-exception-strategy>

Avoid Exception Stack Traces With Mule API Gateway Runtime

Mule API gateway runtime coupled with 3.7.x or Mule runtime (< 3.8.x) does not have the logException attribute defined in its implementation. The solution to avoid stack trace is below.

Define a logger inside the catch-exception-strategy and set the category, along with setting the level to ERROR.

Here's an example snippet:

<catch-exception-strategy doc:name="Catch Exception Strategy">
 <logger level="ERROR" doc:name="exceptionLogger" message="Exception message is ... #[exception.message]" category="com.project.stacktrace"/>
  <set-variable variableName="exceptionMessage" value="#[exception.message]" doc:name="Set exceptionMessage"/>
  <set-payload value="{  errors: {     errorCode: #[message.inboundProperties.'http.status'],     errorMessage: #[flowVars.exceptionMessage]  }  }" doc:name="Set Exception Payload"/>
</catch-exception-strategy>

Configure the below log4j settings in the project's log4j2.xml file as shown below:

<AsyncLogger name="org.mule.exception.CatchMessagingExceptionStrategy" level="FATAL"/>
<AsyncLogger name="com.project.stacktrace" level="ERROR"/>

I have demonstrated the above steps this a video tutorial.

We will continue expanding this example with error handling on Anypoint Studio in the next article.

Printing API

Opinions expressed by DZone contributors are their own.

Related

  • Source-Driven Development in Salesforce: Managing Metadata and API Versions
  • How to Introduce a New API Quickly Using Micronaut
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  • Efficient API Communication With Spring WebClient

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!