# How to add a Sentry breadcrumb to every node?

**URL:** <https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614>\
**Category:** General\
**Created:** [2 February 2023 16:34 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614 "2023-02-02T16:34:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 16:34 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/1 "2023-02-02T16:34:25Z")

</div>

I want to add a Sentry breadcrumb with the node ID so when an error occurs I know what path was taken. For example,

`Sentry.addBreadcrumb({ nodeId, flowId })`

Is there some kind of node middleware that I can add this code to? So that this code runs onStart for every node?

 ![Screen Shot 2023-02-02 at 11.33.28 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/599279d8f43692fa4ec210d861c5b300248456e8.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 February 2023 16:45 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/2 "2023-02-02T16:45:11Z")

</div>

Hi @watadarkstar

A search on [https://flows.nodered.org](https://flows.nodered.org) reveals a node that may help.  
use this along with the built in `catch` node?

> **[node-red-contrib-sentrynode](https://flows.nodered.org/node/node-red-contrib-sentrynode)**
>
> A sentry node for node-red

Disclaimer : I dont use sentry

EDIT.  
Oh hang on - you already using it - my bad 😅

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 February 2023 16:47 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/3 "2023-02-02T16:47:57Z")

</div>

Have a look at the messaging hooks api: [Messaging Hooks : Node-RED](https://nodered.org/docs/api/hooks/messaging/)

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 16:48 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/4 "2023-02-02T16:48:37Z")

</div>

Yeah I'm already using that. It only shows me the last node where the error occurred. I want to see every node that was "visited" to lead up to the error so I have more context.

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 16:51 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/5 "2023-02-02T16:51:00Z")

</div>

Thank you! That's what I was looking for, awesome!

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 February 2023 16:51 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/6 "2023-02-02T16:51:57Z")

</div>

Is this for a node your developing?

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 16:53 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/7 "2023-02-02T16:53:16Z")

</div>

Nope but may potentially add this to that package you mentioned.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 February 2023 16:56 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/8 "2023-02-02T16:56:59Z")

</div>

Ok, unless @knolleary can correct me?  
The Hooks API is only for custom node development.

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 17:42 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/9 "2023-02-02T17:42:48Z")

</div>

I'm using [patch-package - npm](https://www.npmjs.com/package/patch-package) to patch the [sentry library](https://github.com/ibraheem-ghazi/node-red-contrib-sentrynode).

Here is the patch for future readers:

```auto
diff --git a/node_modules/node-red-contrib-sentrynode/sentry/sentry.js b/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
index cb8508f..5a1ca07 100644
--- a/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
+++ b/node_modules/node-red-contrib-sentrynode/sentry/sentry.js
@@ -110,11 +110,12 @@ module.exports = function(RED) {
     function SentryNode(config) {	
         RED.nodes.createNode(this, config);
         var node = this;
+ var ENVIRONMENT = RED.util.getSetting(node, 'ENVIRONMENT')
 		
 		/**
 		* init the sentry only on deployment
 		*/
- Sentry.init({ dsn: config.dsn, environment: config.environment || 'debug' });
+ Sentry.init({ dsn: config.dsn, environment: ENVIRONMENT || config.environment || 'debug' });
         
 		node.on('input', function(msg, send, done) {
 			
@@ -157,4 +158,11 @@ module.exports = function(RED) {
         });
     }
     RED.nodes.registerType("sentry", SentryNode);
+	RED.hooks.add("postReceive", (receiveEvent) => {
+ Sentry.addBreadcrumb({
+ category: 'node-red', 
+ level: 'info', 
+ message: `Message received for Node ID: ${receiveEvent.destination.id}`
+ });
+	});
 }
\ No newline at end of file

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 February 2023 18:09 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/10 "2023-02-02T18:09:43Z")

</div>

> [@watadarkstar](#):
>
> Here is the patch for future readers:

Or, PR the enhancement with the developer/fork and update it 😉  
Patching nodes (I feel) shouldn't be required, and an update will benefit all users who install such node.

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 18:20 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/11 "2023-02-02T18:20:48Z")

</div>

Ok, boss! 😉

---

<div class="post-metadata">

**Author:** ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)\
**Post date:** [2 February 2023 21:43 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/12 "2023-02-02T21:43:10Z")

</div>

> [@marcus-j-davies](#):
>
> > [@watadarkstar](#):
> >
> > Here is the patch for future readers:
> 
> Or, PR the enhancement with the developer/fork and update it 😉  
> Patching nodes (I feel) shouldn't be required, and an update will benefit all users who install such node.

Done, boss! [feat: adds sentry breadcrumb for each node visited by watadarkstar · Pull Request #5 · ibraheem-ghazi/node-red-contrib-sentrynode · GitHub](https://github.com/ibraheem-ghazi/node-red-contrib-sentrynode/pull/5)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 February 2023 21:43 UTC](https://discourse.nodered.org/t/how-to-add-a-sentry-breadcrumb-to-every-node/74614/13 "2023-02-16T21:43:49Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
