2

I have an Azure function that runs a few times a day. I'd like to email myself a daily list of log messages, and wondered if I could use another Azure function for that?

Is it possible to read an Azure function logs from within an Azure function? Or is there another way to achieve the above?

asgerhallas
  • 16,890
  • 6
  • 50
  • 68
  • 2
    Not a direct answer, but what is the use case. If you want to find specific issues using azure monitor alerts might be a better fit. – Peter Bons Sep 02 '22 at 19:55
  • @PeterBons sorry for the delay. This is for a short term hobby project, and it need to as simple as possible to implement. I have an endpoint that is queried a few times a day, and I need to give a daily status report of the results. My idea was to skip handling state within the service and just send the daily logs. Hope that makes sense. – asgerhallas Sep 05 '22 at 12:36
  • @PeterBons important thing here being, that I do queries multiple times a day, but I only want the report daily. – asgerhallas Sep 05 '22 at 12:37
  • Hi @asgerhallas could you please pick on correct answer among the two available. – Farrukh Normuradov Sep 11 '22 at 18:35
  • 1
    Hi @FarrukhNormuradov, I have not yet had a chance to try out the proposed solutions, but I will, and I will provide feedback :) – asgerhallas Sep 12 '22 at 21:33

2 Answers2

2

I would propose two possible solutions in the realm of Azure.
In both cases I would suggest to include application insights.
It is a general recommendation by Microsoft.
Then goes what Peter Bons called "use case".

  1. If it is enough for you get the critical information about recurring issues with N minutes of frequency, then you could make us of alerts. Last time I checked one needed to pay extra for each email, please double-check that.

  2. If for some reason you want to have more control over what logs you want to send and fetch, you can fetch data directly from application insights through the REST API. To complete the idea you could use bindings that allow send emails (see here for practical points). I would say that there variations on how you can achieve fetching data, although the feature will be deprecated in two years.

two solutions

Farrukh Normuradov
  • 1,032
  • 1
  • 11
  • 32
2

Or is there another way to achieve the above?

Yes, you can use Azure Logic apps to get the logs of Function app recurrently. I have created a logic app in Consumption plan, then created a workflow with Recurrence Trigger like below:

enter image description here

Then in next step I have chosen the Azure Applications insights like below:

enter image description here

Then I have opted send an email action and then I got the logs to my email :

enter image description here

enter image description here

Then in email I received logs:

enter image description here

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7
  • Thanks, this works :) I can't seem to change the "traces" query though. If I modify it and save it still sends me the old trace. Do you perhaps know why? – asgerhallas Sep 19 '22 at 12:24