Custom Filter Missing Activity Logs -- Unable to Debug Script

Is there some way to read logs or errors from a custom filter? I can't see any of my Monitor's activity logs.

:computer: Environment
Custom Filters (I want to show Mint events for only the tokenID's ending in "0000").

:memo:Details
My Monitor's activity logs won't show up (the loading wheel just continues to spin) so I don't have any error messages to work through. The Activity Logs page says "Loading monitor logs..." and in my browser's console it says "TypeError: Cannot read properties of undefined (reading 'map')".

My specific issue: my filter script isn't working correctly and I'm hoping to debug the problem. Either I'm unable to access params ("_tokenId") from the matchReasons object of my MonitorConditionRequest, or I'm pulling the param key incorrectly. I'm able to filter out all "Mint" events successfully if I pass matches.push({}), but when I try parsing my smart contract method's function params, my filter's logic starts to break and I can't log the reason why.

:1234: Code to reproduce

exports.handler = async function(payload) {
  const conditionRequest = payload.request.body;
  const matches = [];
  const events = conditionRequest.events;

  function isMintZero(hexStr) {
    const num = parseInt(hexStr, 16);
    return num % 65536 === 0; // Checks if the last four hex digits are "0000"
  }

  for(const evt of events) {
    const eventType = evt.matchReasons[0].type;
    const matchResponse = {
      hash: evt.hash
    };

    if (eventType === "Mint") {
      const tokenId = evt.matchReasons[0].params["_tokenId"]

      if (tokenId && isMintZero(tokenId)) {
        matches.push(matchResponse);
      }
    } else {
      matches.push(matchResponse);
    }
  }
  return { matches };
}

Hi @meck could you post a link to the contract and the event you're monitoring? Also, please let us know your account's tenantId and provide a link to the monitor you're having trouble with so we can see what the issue might be.

Sure thanks @emnul! Here's that info, and just to verify I double-checked my monitor's logs again today and looks like I'm still seeing the same TypeError.

Contract: https://sepolia.etherscan.io/address/0xec5dae4b11213290b2dbe5295093f75920bd2982
Event: Mint(address,uint256)
Tenant ID: 16ec1867-8999-4b9a-be0d-f9232f53d689
Monitor: https://defender.openzeppelin.com/v2/#/monitor/edit/236ac10f-5608-4fa4-bf1d-b6c15b9e6787

Hi @meck we've identified the Monitor Activity issue you're facing to be a bug and are working on a fix for that.

Also, it appears that the matchReasons field is not being populated in the event response, which I think is a bug. I've reached out to the team and will let you know once we look into this further.

Hi @meck at this time we return an empty matchReasons array if a monitor has no tx / function / event filters on it so your code is erroring because it's trying to index an object property "type" in this case that doesn't exist. If you would like to get additional info from the matchReason object you will need to specify some additional filter (event, transaction, func) to get that information in the custom filter request.

Thanks @emnul! Whoops, yes I removed the event filter that I was testing with so that we wouldn't get lots of pings over the weekend.

The good news is my script is working for me so I'm finished with debugging. However I still see the missing activity logs issue - the spinning wheel's disappeared and I see a "No logs" message in my Monitor Activity. My script includes some console.logs and I've validated that I'm receiving alerts and correctly parsing them from matchReason, so just an FYI that either I'm doing something wrong or the activity logs may still be missing.

I see a "No logs" message in my Monitor Activity

Hi @meck this is a known issue that we have a fix for in our staging environment. Once the issue has been tested it should be released within the next week or so. We publish updates to Defender here

1 Like