Middleware for Azure Functions
Features
- Logs requests redacted (With "api" in route)
- Logs responses redacted and status codes (With "api" in route)
- Adds Telemetry
- Handles Auth
- Handles correlation Ids
- Catch all uncaught exceptions and log them redacted
[FunctionName(FUNCTION_NAME)]
public async Task<ContentResult> RunAsync
(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "SampleFunctionWithAuth")] HttpRequest req
)
{
return await _middlewareService.InvokeWithJWTAuthAsync
(
req.HttpContext,
async () =>
{
await Task.CompletedTask.ConfigureAwait(false);
return new ContentResult
{
StatusCode = 200,
Content = "{}",
ContentType = "application/json"
};
},
USER
).ConfigureAwait(false);
}
+ GET http://localhost:7071/api/SampleFunctionWithAuth
Path: /api/SampleFunctionWithAuth
Method: GET
Scheme: http
Prams: {}
Body:
Role: User
NameIdentifier: 1924
CorrelationId: 5b2213dd-8a93-4f73-9d54-fd84e93069ef
Response GET http://localhost:7071/api/SampleFunctionWithAuth
ContentType: application/json
Body: {}
StatusCode: 200
CorrelationId: 5b2213dd-8a93-4f73-9d54-fd84e93069ef
- GET http://localhost:7071/api/SampleFunctionWithAuth
ElapsedMilliseconds: 29
CorrelationId: 5b2213dd-8a93-4f73-9d54-fd84e93069ef