Skip to content

DURABLE0010 false positive when ILogger is passed to a helper method called from an orchestrator #717

@Meir017

Description

@Meir017

Summary

The DURABLE0010 analyzer (LoggerOrchestrationAnalyzer) flags an ILogger parameter on a private helper method invoked from an orchestrator's RunAsync, even when the logger originates from context.CreateReplaySafeLogger(...) — which is the recommended replay-safe pattern.

The diagnostic should only fire when a non-replay-safe ILogger is actually used inside orchestration code. A logger created via CreateReplaySafeLogger and passed through to a helper is safe and idiomatic, so this is a false positive.

introduced in #553

Repro

using Microsoft.DurableTask;
using Microsoft.Extensions.Logging;

public record DemoInput(string Value);
public record DemoResult(string Value);

public class DemoOrchestrator : TaskOrchestrator<DemoInput, DemoResult>
{
    public override async Task<DemoResult> RunAsync(TaskOrchestrationContext context, DemoInput input)
    {
        var logger = context.CreateReplaySafeLogger(nameof(DemoOrchestrator));

        LogData(logger);

        return new DemoResult($"Processed: {input.Value}");
    }

    private static void LogData(ILogger logger)
    {
        logger.LogInformation("Logging some data for demonstration purposes.");
    }
}

Expected

No DURABLE0010 diagnostic. The logger was obtained via CreateReplaySafeLogger and passed to a helper — this is the documented, replay-safe pattern.

Actual

DURABLE0010 is reported on the ILogger logger parameter of LogData, with a message indicating that a non-contextual ILogger is used in orchestration code reachable from DemoOrchestrator.

Analysis

LoggerOrchestrationAnalyzer.LoggerOrchestrationVisitor.VisitMethod (in src/Analyzers/Orchestration/LoggerOrchestrationAnalyzer.cs) walks every method reachable from an orchestrator (via MethodProbeOrchestrationVisitor) and reports on any ILogger parameter, field, or property reference it encounters. It has no notion of whether the ILogger value flowing into that parameter came from TaskOrchestrationContext.CreateReplaySafeLogger.

This means any helper method that accepts ILogger as a parameter — even when callers always pass a replay-safe logger — produces a false positive.

Suggested fix

The analyzer should track the source of the ILogger value, not just its type. Some options:

  1. Suppress the diagnostic on parameters/locals/fields whose value can be traced back to a TaskOrchestrationContext.CreateReplaySafeLogger(...) invocation (data-flow / call-site analysis).
  2. At minimum, do not flag ILogger parameters of helper methods; instead only flag direct usages (field/property/local references and direct injection into the orchestrator entry point) where the source is known to be unsafe.
  3. Provide an opt-out attribute (e.g. [ReplaySafeLogger]) for helper-method parameters to silence the warning when the developer has verified the call sites.

Environment

  • Package: Microsoft.DurableTask.Analyzers
  • Diagnostic: DURABLE0010Non-contextual ILogger usage in orchestration

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions