We faced Issues during Migration to Isolated Worker Process

Sefa Teyek 0 Reputation points
2025-04-16T09:33:25.3066667+00:00

Dear Microsoft Support Team,

We are in the process of migrating our application from the in-process model to Azure Functions Isolated Worker, following all official Microsoft guidelines.

While we have updated the configuration as suggested, we are currently facing two major issues:

  1. [Singleton] Attribute No Longer Supported

Our application logic heavily relies on the [Singleton] attribute, which is no longer supported in the isolated worker model.

This poses a significant challenge in terms of:

Ensuring single-instance execution for certain critical operations

Preserving the same behavior without major architectural overhaul

We are exploring alternatives like:

Service Bus sessions for message ordering and instance locking

Distributed locking

We’d appreciate it if you could provide Microsoft-recommended patterns or best practices to safely replace the [Singleton] attribute and maintain the original singleton behavior within the isolated worker model.

  1. Logging Gaps in Isolated Worker Model

We are also experiencing serious gaps in telemetry (Application Insights) since the migration:

operation_name is missing for many traces, exceptions, dependencies, and custom events

Custom dimensions are intermittently dropped or missing entirely

These issues were not present in the in-process model

This telemetry is critical to our business for monitoring, debugging, and custom workbook dashboards.

Could you advise on:

How to preserve full log fidelity (including operation_name and custom dimensions) in the isolated worker model?

Whether there's a recommended approach or configuration for bridging this telemetry gap?

We’d really appreciate your guidance on these issues, as they’re essential for ensuring feature parity and observability in the new hosting model.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,932 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andrew Baran 0 Reputation points
    2025-04-22T10:41:45.04+00:00

    Hello!

    @Sai Prabhu Naveen Parimi we are working with @Sefa Teyek and trying to resolve above issues together.

    So we've tried to implement a custom approach to enforce writing operation_name in our appinsights logs.

    We added custom middleware to start new operation and explicitly add "CustomOperationName" for current activity on every function invocation.

    public class TelemetryCorrelationMiddleware : IFunctionsWorkerMiddleware
        {
            private readonly TelemetryClient _telemetryClient;
    
            public TelemetryCorrelationMiddleware(TelemetryClient telemetryClient)
            {
                _telemetryClient = telemetryClient.VerifyNotNull(nameof(telemetryClient));
            }
    
            public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
            {
                var functionName = context.FunctionDefinition.Name;
    
                using var activity = new Activity(functionName);
    
                activity.AddTag("CustomOperationName", functionName);
                activity.AddBaggage("CustomOperationName", functionName);
    
                using (var operation = _telemetryClient.StartOperation<RequestTelemetry>(activity))
                {
                    await next(context);
                }
            }
        }
    

    on the other side we've added custom TelemetryInitializer where we manually check for "CustomOperationName" and try to set it explicitly if possible

    public class CustomTelemetryInitializer : ITelemetryInitializer
        {
            private const string CustomOperationName = "CustomOperationName";
            public void Initialize(ITelemetry telemetry)
            {
                if (telemetry is TraceTelemetry traceTelemetry && string.IsNullOrEmpty(traceTelemetry.Context.Operation.Name))
                {
                    if (traceTelemetry.Properties.TryGetValue(CustomOperationName, out var operationName))
                    {
                        traceTelemetry.Context.Operation.Name = operationName;
                    }
                }
    
                if (telemetry is DependencyTelemetry dependencyTelemetry && string.IsNullOrEmpty(dependencyTelemetry.Context.Operation.Name))
                {
                    if (dependencyTelemetry.Properties.TryGetValue(CustomOperationName, out var operationName))
                    {
                        dependencyTelemetry.Context.Operation.Name = operationName;
                    }
                }
    
                if (telemetry is EventTelemetry eventTelemetry && string.IsNullOrEmpty(eventTelemetry.Context.Operation.Name))
                {
                    if (eventTelemetry.Properties.TryGetValue(CustomOperationName, out var operationName))
                    {
                        eventTelemetry.Context.Operation.Name = operationName;
                    }
                }
    
                if (telemetry is ExceptionTelemetry exceptionTelemetry && string.IsNullOrEmpty(exceptionTelemetry.Context.Operation.Name))
                {
                    if (exceptionTelemetry.Properties.TryGetValue(CustomOperationName, out var operationName))
                    {
                        exceptionTelemetry.Context.Operation.Name = operationName;
                    }
                }
            }
        }
    

    As a result:

    1. Traces -> inside functions call are written with operation name
    2. Dependencies -> OK
    3. Custom Events -> OK
    4. Exceptions -> OK
    5. Requests -> No operation name but there is a column "Name" that basically has the same value.

    As for [Singleton] we will try to implement solution to this issue in nearest future. I will share a feedback here.

    We are considering two major approaches:

    1. Message Sessions
    2. Blob lease distributed lock

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.