-
Notifications
You must be signed in to change notification settings - Fork 322
Add .NET 8.0 and .NET 10.0 support to DurableTask.AzureServiceFabric #1305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||
| // ---------------------------------------------------------------------------------- | ||||||||||||||||
| // Copyright Microsoft Corporation | ||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||
| // limitations under the License. | ||||||||||||||||
| // ---------------------------------------------------------------------------------- | ||||||||||||||||
|
|
||||||||||||||||
| #if !NETFRAMEWORK | ||||||||||||||||
| namespace DurableTask.AzureServiceFabric.Service | ||||||||||||||||
| { | ||||||||||||||||
| using System; | ||||||||||||||||
| using System.Net; | ||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||
|
|
||||||||||||||||
| using DurableTask.AzureServiceFabric.Tracing; | ||||||||||||||||
|
|
||||||||||||||||
| using Microsoft.AspNetCore.Http; | ||||||||||||||||
| using Newtonsoft.Json; | ||||||||||||||||
|
|
||||||||||||||||
| /// <summary> | ||||||||||||||||
| /// ASP.NET Core middleware for activity logging of proxy service requests. | ||||||||||||||||
| /// </summary> | ||||||||||||||||
| internal class ActivityLoggingMiddleware | ||||||||||||||||
| { | ||||||||||||||||
| private readonly RequestDelegate next; | ||||||||||||||||
|
|
||||||||||||||||
| public ActivityLoggingMiddleware(RequestDelegate next) | ||||||||||||||||
| { | ||||||||||||||||
| this.next = next; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public async Task InvokeAsync(HttpContext context) | ||||||||||||||||
| { | ||||||||||||||||
| string requestMethod = context.Request.Method; | ||||||||||||||||
| string requestPath = context.Request.Path.ToString(); | ||||||||||||||||
| string activityId = Guid.NewGuid().ToString("D"); | ||||||||||||||||
|
|
||||||||||||||||
| ServiceFabricProviderEventSource.Tracing.LogProxyServiceRequestInformation( | ||||||||||||||||
| $"{activityId} : Proxy service incoming request {requestPath} with method {requestMethod}"); | ||||||||||||||||
|
|
||||||||||||||||
| try | ||||||||||||||||
| { | ||||||||||||||||
| await this.next(context); | ||||||||||||||||
| ServiceFabricProviderEventSource.Tracing.LogProxyServiceRequestInformation( | ||||||||||||||||
| $"{activityId} : Proxy service responding request {requestPath} with method {requestMethod} with status code {context.Response.StatusCode}"); | ||||||||||||||||
| } | ||||||||||||||||
| catch (Exception exception) | ||||||||||||||||
| { | ||||||||||||||||
| ServiceFabricProviderEventSource.Tracing.LogProxyServiceError(activityId, requestPath, requestMethod, exception); | ||||||||||||||||
| context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | ||||||||||||||||
| context.Response.ContentType = "application/json"; | ||||||||||||||||
| await context.Response.WriteAsync(JsonConvert.SerializeObject(exception)); | ||||||||||||||||
|
||||||||||||||||
| await context.Response.WriteAsync(JsonConvert.SerializeObject(exception)); | |
| var errorResponse = new | |
| { | |
| message = "An internal server error occurred.", | |
| activityId = activityId | |
| }; | |
| await context.Response.WriteAsync(JsonConvert.SerializeObject(errorResponse)); |
Copilot
AI
Feb 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActivityId response header is set after the request pipeline runs. In ASP.NET Core the response may have already started (either in the normal path or after writing the error body), which can throw and/or silently drop the header. Register the header via context.Response.OnStarting(...) (or set it before calling next) so it’s guaranteed to be included.
Check warning
Code scanning / CodeQL
Cross-site scripting Medium