@@ -47,7 +47,7 @@ public void Trace_Verbose_EmitsExpectedEvent()
47
47
traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
48
48
traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventDetailsKey , details ) ;
49
49
50
- _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Verbose , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , details , traceEvent . Message , null ) ) ;
50
+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Verbose , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , details , traceEvent . Message ) ) ;
51
51
52
52
_traceWriter . Trace ( traceEvent ) ;
53
53
@@ -67,7 +67,34 @@ public void Trace_Error_EmitsExpectedEvent()
67
67
traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventNameKey , eventName ) ;
68
68
traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
69
69
70
- _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , string . Empty , traceEvent . Message , ex ) ) ;
70
+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , ex . ToFormattedString ( ) , traceEvent . Message ) ) ;
71
+
72
+ _traceWriter . Trace ( traceEvent ) ;
73
+
74
+ _mockEventGenerator . VerifyAll ( ) ;
75
+ }
76
+
77
+ [ Fact ]
78
+ public void Trace_Sanitizes ( )
79
+ {
80
+ string secretReplacement = "[Hidden Credential]" ;
81
+ string secretString = "{ \" AzureWebJobsStorage\" : \" DefaultEndpointsProtocol=https;AccountName=testAccount1;AccountKey=mykey1;EndpointSuffix=core.windows.net\" , \" AnotherKey\" : \" AnotherValue\" }" ;
82
+ string sanitizedString = $ "{{ \" AzureWebJobsStorage\" : \" { secretReplacement } \" , \" AnotherKey\" : \" AnotherValue\" }}";
83
+
84
+ 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/;\" " ;
85
+ string sanitizedException = $ "System.InvalidOperationException : Invalid string: \" { secretReplacement } \" ";
86
+
87
+ string functionName = "TestFunction" ;
88
+ string eventName = "TestEvent" ;
89
+
90
+ Exception ex = new InvalidOperationException ( secretException ) ;
91
+
92
+ TraceEvent traceEvent = new TraceEvent ( TraceLevel . Error , secretString , "TestSource" , ex ) ;
93
+
94
+ traceEvent . Properties . Add ( ScriptConstants . TracePropertyEventNameKey , eventName ) ;
95
+ traceEvent . Properties . Add ( ScriptConstants . TracePropertyFunctionNameKey , functionName ) ;
96
+
97
+ _mockEventGenerator . Setup ( p => p . LogFunctionTraceEvent ( TraceLevel . Error , _subscriptionId , _websiteName , functionName , eventName , traceEvent . Source , sanitizedException , sanitizedString ) ) ;
71
98
72
99
_traceWriter . Trace ( traceEvent ) ;
73
100
0 commit comments