Skip to content

Commit 007a4dd

Browse files
authored
Suppress tracing output of Durable Activity functions (#624)
1 parent 8cb72f5 commit 007a4dd

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

src/Durable/DurableController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public bool TryInvokeOrchestrationFunction(out Hashtable result)
109109
return true;
110110
}
111111

112+
public bool ShouldSuppressPipelineTraces()
113+
{
114+
return _durableFunctionInfo.Type == DurableFunctionType.ActivityFunction;
115+
}
116+
112117
private static OrchestrationBindingInfo CreateOrchestrationBindingInfo(IList<ParameterBinding> inputData)
113118
{
114119
// Quote from https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-bindings:

src/Durable/DurableFunctionInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public DurableFunctionInfo(DurableFunctionType type, string durableClientBinding
1919

2020
public string DurableClientBindingName { get; }
2121

22-
public DurableFunctionType Type { get; }
22+
public DurableFunctionType Type
23+
{
24+
get;
25+
internal set; // for testing purposes only
26+
}
2327

2428
public bool ProvidesForcedDollarReturnValue => Type != DurableFunctionType.None;
2529
}

src/PowerShell/PowerShellManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ public Hashtable InvokeFunction(
216216
SetInputBindingParameterValues(functionInfo, inputData, durableController, triggerMetadata, traceContext);
217217
stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InputBindingValuesReady);
218218

219-
_pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject");
219+
if (!durableController.ShouldSuppressPipelineTraces())
220+
{
221+
_pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject");
222+
}
220223

221224
stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InvokingFunctionCode);
222225
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, CreateInvocationPerformanceReportMessage(functionInfo.FuncName, stopwatch));

test/Unit/Durable/DurableControllerTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ internal void AddPipelineOutputIfNecessary_DoesNotAddDollarReturn_ForNonActivity
231231
Assert.False(result.ContainsKey(AzFunctionInfo.DollarReturn));
232232
}
233233

234+
[Theory]
235+
[InlineData(DurableFunctionType.None, false)]
236+
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
237+
[InlineData(DurableFunctionType.ActivityFunction, true)]
238+
internal void SuppressPipelineTracesForActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
239+
{
240+
var durableController = CreateDurableController(durableFunctionType);
241+
Assert.Equal(shouldSuppressPipelineTraces, durableController.ShouldSuppressPipelineTraces());
242+
}
243+
234244
private DurableController CreateDurableController(
235245
DurableFunctionType durableFunctionType,
236246
string durableClientBindingName = null)

test/Unit/PowerShell/PowerShellManagerTests.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Test
1717
{
1818
using System.Collections.ObjectModel;
1919
using System.Management.Automation;
20+
using Microsoft.Azure.Functions.PowerShellWorker.Durable;
21+
using Newtonsoft.Json;
2022

2123
internal class TestUtils
2224
{
@@ -373,6 +375,52 @@ public void LoggerContextIsSet()
373375
powerShellManagerPool.ReclaimUsedWorker(worker);
374376
}
375377

378+
[Theory]
379+
[InlineData(DurableFunctionType.None, false)]
380+
[InlineData(DurableFunctionType.OrchestrationFunction, false)]
381+
[InlineData(DurableFunctionType.ActivityFunction, true)]
382+
internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces)
383+
{
384+
s_testLogger.FullLog.Clear();
385+
386+
var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1");
387+
var (functionInfo, testManager) = PrepareFunction(path, string.Empty);
388+
functionInfo.DurableFunctionInfo.Type = durableFunctionType;
389+
390+
try
391+
{
392+
FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings);
393+
394+
var result = testManager.InvokeFunction(functionInfo, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch());
395+
396+
var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList();
397+
var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" };
398+
Assert.Equal(expected, relevantLogs);
399+
}
400+
finally
401+
{
402+
FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId);
403+
}
404+
}
405+
406+
private static List<ParameterBinding> CreateOrchestratorInputData()
407+
{
408+
var orchestrationContext = new OrchestrationContext
409+
{
410+
History = new[] { new HistoryEvent { EventType = HistoryEventType.OrchestratorStarted } }
411+
};
412+
413+
var testInputData = new List<ParameterBinding>
414+
{
415+
new ParameterBinding
416+
{
417+
Name = TestInputBindingName,
418+
Data = new TypedData { String = JsonConvert.SerializeObject(orchestrationContext) }
419+
}
420+
};
421+
return testInputData;
422+
}
423+
376424
private static Hashtable InvokeFunction(PowerShellManager powerShellManager, AzFunctionInfo functionInfo, Hashtable triggerMetadata = null)
377425
{
378426
return powerShellManager.InvokeFunction(functionInfo, triggerMetadata, null, s_testInputData, new FunctionInvocationPerformanceStopwatch());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
param ($Req)
7+
8+
'Hello'

0 commit comments

Comments
 (0)