@@ -46,7 +46,7 @@ public void Trace_Verbose_EmitsExpectedEvent()
4646 traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
4747 traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventDetailsKey , details ) ;
4848
49- _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Verbose , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , details , traceEvent . Message , null ) ) ;
49+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Verbose , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , details , traceEvent . Message ) ) ;
5050
5151 _traceWriter . Trace ( traceEvent ) ;
5252
@@ -66,7 +66,34 @@ public void Trace_Error_EmitsExpectedEvent()
6666 traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventNameKey , eventName ) ;
6767 traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
6868
69- _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , string . Empty , traceEvent . Message , ex ) ) ;
69+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , ex . ToFormattedString ( ) , traceEvent . Message ) ) ;
70+
71+ _traceWriter . Trace ( traceEvent ) ;
72+
73+ _mockEventGenerator . VerifyAll ( ) ;
74+ }
75+
76+ [ Fact ]
77+ public void Trace_Sanitizes ( )
78+ {
79+ string secretReplacement = "[Hidden Credential]" ;
80+ string secretString = "{ \" AzureWebJobsStorage\" : \" DefaultEndpointsProtocol=https;AccountName=testAccount1;AccountKey=mykey1;EndpointSuffix=core.windows.net\" , \" AnotherKey\" : \" AnotherValue\" }" ;
81+ string sanitizedString = $ "{{ \" AzureWebJobsStorage\" : \" { secretReplacement } \" , \" AnotherKey\" : \" AnotherValue\" }}";
82+
83+ string secretException = "Invalid string: \" DefaultEndpointsProtocol=https;AccountName=testaccount;AccountKey=testkey;BlobEndpoint=https://testaccount.blob.core.windows.net/;QueueEndpoint=https://testaccount.queue.core.windows.net/;TableEndpoint=https://testaccount.table.core.windows.net/;FileEndpoint=https://testaccount.file.core.windows.net/;\" " ;
84+ string sanitizedException = $ "System.InvalidOperationException : Invalid string: \" { secretReplacement } \" ";
85+
86+ string functionName = "TestFunction" ;
87+ string eventName = "TestEvent" ;
88+
89+ Exception ex = new InvalidOperationException ( secretException ) ;
90+
91+ TraceEvent traceEvent = new TraceEvent ( TraceLevel . Error , secretString , "TestSource" , ex ) ;
92+
93+ traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventNameKey , eventName ) ;
94+ traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
95+
96+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , sanitizedException , sanitizedString ) ) ;
7097
7198 _traceWriter . Trace ( traceEvent ) ;
7299
0 commit comments