reckface
reckface

Reputation: 5878

How to troubleshoot Flaky Azure function app behaviour?

I am trying out Azure Function Apps.

The first one following the example in a tutorial with Open Weather map, stopped working after I used log.WriteLine(), which correctly threw a compiler error. I changed to log.Info() and it kept complaining about TraceWriter not containing a definition for WriteLine.

After a lengthy troubleshooting session, I created a new function, copying all the content of the broken one, and it worked immediately.

Created a new function, as before, and began making changes to the Run() method, and running this function yields:

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Bearing in mind, the function URL is based on the default key Azure generates when the function is created: https://.azurewebsites.net/api/WeatherWhereYouAre?code=my1really2RAndom3defauLT4Key5from6Azure==

Created yet another function, with no changes from the default "Hello Azure" sample, and it yields a 500 error with:

"Exception while executing function: Functions.HttpTriggerCSharp2 -> One or more errors occurred. -> Exception binding parameter 'req' -> Input string was not in a correct format."

This is the content of the project.json file:

{
    "frameworks": {
        "net46": {
            "dependencies": {
                "Microsoft.IdentityModel.Clients.ActiveDirectory": "3.16.0",
                "Microsoft.Azure.KeyVault": "2.3.2",
                "Microsoft.AspNet.WebApi.Client": "5.2.3"
            }
        }
    }
}

And the run.csx:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    name = name ?? data?.name;

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

EDIT

Completely inconsistent behaviour In the above image, note that this is httpTriggerFSharp1, but the exception is HttpTriggerCSharp2 (which is the only one that works!)

Is there a way I can properly troubleshoot these?

Upvotes: 2

Views: 657

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18465

For the default HttpTrigger template for C#, you could call it as follows:

Get https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?name=bruce&code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==

Or

Post https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==
Content-type: application/json
{"name": "bruce"}

For more details about Azure Functions C# script, you could refer to here.

Is there a way I can properly troubleshoot these?

Per my understanding, you could leverage Precompiled functions and use Visual Studio 2017 Tools for Azure Functions for creating, local debugging, and publishing to Azure.

Upvotes: 1

Related Questions