Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Durable/DurableController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public bool TryInvokeOrchestrationFunction(out Hashtable result)
return true;
}

public bool ShouldSuppressPipelineTraces()
{
return _durableFunctionInfo.Type == DurableFunctionType.ActivityFunction;
}

private static OrchestrationBindingInfo CreateOrchestrationBindingInfo(IList<ParameterBinding> inputData)
{
// Quote from https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-bindings:
Expand Down
6 changes: 5 additions & 1 deletion src/Durable/DurableFunctionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public DurableFunctionInfo(DurableFunctionType type, string durableClientBinding

public string DurableClientBindingName { get; }

public DurableFunctionType Type { get; }
public DurableFunctionType Type
{
get;
internal set; // for testing purposes only
}

public bool ProvidesForcedDollarReturnValue => Type != DurableFunctionType.None;
}
Expand Down
5 changes: 4 additions & 1 deletion src/PowerShell/PowerShellManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ public Hashtable InvokeFunction(
SetInputBindingParameterValues(functionInfo, inputData, durableController, triggerMetadata, traceContext);
stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InputBindingValuesReady);

_pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject");
if (!durableController.ShouldSuppressPipelineTraces())
{
_pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject");
}

stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InvokingFunctionCode);
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, CreateInvocationPerformanceReportMessage(functionInfo.FuncName, stopwatch));
Expand Down
10 changes: 10 additions & 0 deletions test/Unit/Durable/DurableControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ internal void AddPipelineOutputIfNecessary_DoesNotAddDollarReturn_ForNonActivity
Assert.False(result.ContainsKey(AzFunctionInfo.DollarReturn));
}

[Theory]
[InlineData(DurableFunctionType.None, false)]
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
[InlineData(DurableFunctionType.ActivityFunction, true)]
internal void SuppressPipelineTracesForActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
{
var durableController = CreateDurableController(durableFunctionType);
Assert.Equal(shouldSuppressPipelineTraces, durableController.ShouldSuppressPipelineTraces());
}

private DurableController CreateDurableController(
DurableFunctionType durableFunctionType,
string durableClientBindingName = null)
Expand Down
48 changes: 48 additions & 0 deletions test/Unit/PowerShell/PowerShellManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Test
{
using System.Collections.ObjectModel;
using System.Management.Automation;
using Microsoft.Azure.Functions.PowerShellWorker.Durable;
using Newtonsoft.Json;

internal class TestUtils
{
Expand Down Expand Up @@ -373,6 +375,52 @@ public void LoggerContextIsSet()
powerShellManagerPool.ReclaimUsedWorker(worker);
}

[Theory]
[InlineData(DurableFunctionType.None, false)]
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
[InlineData(DurableFunctionType.ActivityFunction, true)]
internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
{
s_testLogger.FullLog.Clear();

var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1");
var (functionInfo, testManager) = PrepareFunction(path, string.Empty);
functionInfo.DurableFunctionInfo.Type = durableFunctionType;

try
{
FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings);

var result = testManager.InvokeFunction(functionInfo, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch());

var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList();
var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" };
Assert.Equal(expected, relevantLogs);
}
finally
{
FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId);
}
}

private static List<ParameterBinding> CreateOrchestratorInputData()
{
var orchestrationContext = new OrchestrationContext
{
History = new[] { new HistoryEvent { EventType = HistoryEventType.OrchestratorStarted } }
};

var testInputData = new List<ParameterBinding>
{
new ParameterBinding
{
Name = TestInputBindingName,
Data = new TypedData { String = JsonConvert.SerializeObject(orchestrationContext) }
}
};
return testInputData;
}

private static Hashtable InvokeFunction(PowerShellManager powerShellManager, AzFunctionInfo functionInfo, Hashtable triggerMetadata = null)
{
return powerShellManager.InvokeFunction(functionInfo, triggerMetadata, null, s_testInputData, new FunctionInvocationPerformanceStopwatch());
Expand Down
8 changes: 8 additions & 0 deletions test/Unit/PowerShell/TestScripts/testFunctionWithOutput.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

param ($Req)

'Hello'