Logging of function key for calls to Azure Function

Alex 21 Reputation points
2021-04-16T04:56:09.86+00:00

Hello,

I have an Azure Function that I configured with a number of function keys (API keys). This all works very well and allows access only to those users that provide the key I gave them.

Now I was trying to find out which of the keys was used for a specific call to my API, but wasn't able to find it in the logs. I've looked all over the internet but haven't found anything about this topic.

Could anybody point me to the location in the logs where I could identify which API key was used?

Thanks!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,941 Reputation points
    2021-04-16T05:44:19.077+00:00

    Hi @ak-3792

    Welcome to Microsoft Q&A! Thanks for posting the question.

    By default, this information will not be logged. You need to customize your code to log this information and in the Traces table of application insight, you can get this information.

        const string key_Claim = "http://schemas.microsoft.com/2017/07/functions/claims/keyid";  
        var claim = req.HttpContext.User.Claims.FirstOrDefault(c => c.Type == key_Claim);  
        if(claim != null)  
        {  
            log.LogInformation( "The call was made using {0} named key", claim.Value);  
        }  
    

    88511-image.png

    In Application Insights:

    88521-image.png

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful