How to view actual Azure Event Grid message?

4.4k views Asked by At

I have an Azure Function triggered by EventGridEvents.

  • function.json set accordingly:
{
    "scriptFile": "__init__.py",
    "bindings": [{
        "name": "event",
        "type": "eventGridTrigger",
        "direction": "in"
    }]
}
  • __init__.py dialed in (only snippet shown here):
def main(event: func.EventGridEvent):
        result = json.dumps({
            'id' : event.id,
            'data' : event.get_json(),
            'topic' : event.topic,
            'subject' : event.subject,
            'event_type' : event.event_type
        })
  • Function is successfully deployed
  • EventGrid trigger created successfully
  • I successfully published an EventGrid message here:

enter image description here

  • But the Function never triggered.

I'd like to now see the actual EventGrid message and debug why the Function didn't trigger, but I can't find a place to view the message!

I waited ~30mins, refeshed multiple times and was even watching the AppInsights live logs, no trigger.

enter image description here

  1. Where do I view an EventGrid message after its successfully published
  2. How should I debug this Function?

EDIT 1:

Digging around for a while I found this other "metric" that shows 0 Delivered Events

How is an event "Published" but not "Delivered"?

enter image description here

2

There are 2 answers

1
Cindy Pau On

I have done a test. On my side it seems no problem.

Maybe something different between yours and mine.

Please check:

_init_.py

import json
import logging

import azure.functions as func


def main(event: func.EventGridEvent):
    result = json.dumps({
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    })

    logging.info('Python EventGrid trigger processed an event: %s', result)

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    }
  ]
}

And this is my eventgrid subscription:(I add a blob to the specific container and delete it. Please notice that the metric of the eventgrid subscription may take about 5 minutes to show. But it will trigger your endpoint function immediately.)

enter image description here

This is the filter of my eventgrid subscription:

enter image description here

I want the blob created and deleted in the test container to trigger the endpoint azure function, so I add /blobServices/default/containers/test to the 'Subject Begins With' section.

Then my function works fine:

enter image description here

0
Sam Bera On

The easiest option will be to create an Azure subscription to the event grid topic and write the message to an ALDS storage account storage queue. You can set the settings on the storage queue on how long you want a message persisted.