@@ -46,7 +46,7 @@ public void Trace_Verbose_EmitsExpectedEvent()
46
46
traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
47
47
traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventDetailsKey , details ) ;
48
48
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 ) ) ;
50
50
51
51
_traceWriter . Trace ( traceEvent ) ;
52
52
@@ -66,7 +66,34 @@ public void Trace_Error_EmitsExpectedEvent()
66
66
traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventNameKey , eventName ) ;
67
67
traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
68
68
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 ) ) ;
70
97
71
98
_traceWriter . Trace ( traceEvent ) ;
72
99
0 commit comments