{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Home/issues/3348","repository_url":"https://api.github.com/repos/aspnet/Home","labels_url":"https://api.github.com/repos/aspnet/Home/issues/3348/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Home/issues/3348/comments","events_url":"https://api.github.com/repos/aspnet/Home/issues/3348/events","html_url":"https://github.com/aspnet/Home/issues/3348","id":343380904,"node_id":"MDU6SXNzdWUzNDMzODA5MDQ=","number":3348,"title":"Correctly handling exceptions in middleware","user":{"login":"georgiosd","id":1672054,"node_id":"MDQ6VXNlcjE2NzIwNTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/1672054?v=4","gravatar_id":"","url":"https://api.github.com/users/georgiosd","html_url":"https://github.com/georgiosd","followers_url":"https://api.github.com/users/georgiosd/followers","following_url":"https://api.github.com/users/georgiosd/following{/other_user}","gists_url":"https://api.github.com/users/georgiosd/gists{/gist_id}","starred_url":"https://api.github.com/users/georgiosd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgiosd/subscriptions","organizations_url":"https://api.github.com/users/georgiosd/orgs","repos_url":"https://api.github.com/users/georgiosd/repos","events_url":"https://api.github.com/users/georgiosd/events{/privacy}","received_events_url":"https://api.github.com/users/georgiosd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-07-22T06:17:52Z","updated_at":"2018-07-24T16:47:32Z","closed_at":null,"author_association":"NONE","body":"Hey gents,\r\n\r\nI have a simple middleware class that will write a \"virtual file\" i.e. - if the client requests `/foo.path` it will write a response, otherwise it will pass the request down the pipeline.\r\n\r\nMy problem is that when an exception occurs somewhere along the rest of the pipeline, it is reported to App Insights like coming from my middleware because the `next(context)` call is awaited. And it has to be awaited because `context.Response` only has `Async` methods to write. \r\n\r\nCode:\r\n\r\n```\r\npublic async Task InvokeAsync(HttpContext context)\r\n        {\r\n            if (context.Request.Path == \"/foo.path\")\r\n            {\r\n                    await context.Response.WriteAsync(\"content\");\r\n                    return;\r\n            }\r\n\r\n            await next(context);\r\n        }\r\n```\r\n\r\nHow do I go about cleaning this up??"},"comment":{"url":"https://api.github.com/repos/aspnet/Home/issues/comments/407474527","html_url":"https://github.com/aspnet/Home/issues/3348#issuecomment-407474527","issue_url":"https://api.github.com/repos/aspnet/Home/issues/3348","id":407474527,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzQ3NDUyNw==","user":{"login":"SergeyKanzhelev","id":9950081,"node_id":"MDQ6VXNlcjk5NTAwODE=","avatar_url":"https://avatars2.githubusercontent.com/u/9950081?v=4","gravatar_id":"","url":"https://api.github.com/users/SergeyKanzhelev","html_url":"https://github.com/SergeyKanzhelev","followers_url":"https://api.github.com/users/SergeyKanzhelev/followers","following_url":"https://api.github.com/users/SergeyKanzhelev/following{/other_user}","gists_url":"https://api.github.com/users/SergeyKanzhelev/gists{/gist_id}","starred_url":"https://api.github.com/users/SergeyKanzhelev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SergeyKanzhelev/subscriptions","organizations_url":"https://api.github.com/users/SergeyKanzhelev/orgs","repos_url":"https://api.github.com/users/SergeyKanzhelev/repos","events_url":"https://api.github.com/users/SergeyKanzhelev/events{/privacy}","received_events_url":"https://api.github.com/users/SergeyKanzhelev/received_events","type":"User","site_admin":false},"created_at":"2018-07-24T16:47:32Z","updated_at":"2018-07-24T16:47:32Z","author_association":"NONE","body":"@georgiosd there is a way to merge stacks from task start thread and all continuations. But the current version of Application Insights doesn't use any of those heuristics. It just takes the stack of caught exception.\r\n\r\n@davidfowl in certain cases we will see controller method or something user-defined higher on stack. If mostly MS-provided modules and middlewares are used - it is a problem. Do you have a suggestion how to calculate exception signature better?"}}
{"actor":{"display_login":"SergeyKanzhelev"}}