2222
2323package com .microsoft .azuretools .telemetrywrapper ;
2424
25- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .DURATION ;
26- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .ERROR_CLASSNAME ;
27- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .ERROR_CODE ;
28- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .ERROR_MSG ;
29- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .ERROR_TYPE ;
30- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .OPERATION_ID ;
31- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .OPERATION_NAME ;
32- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .mergeProperties ;
33- import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .sendTelemetry ;
34-
3525import java .util .HashMap ;
3626import java .util .Map ;
3727import java .util .UUID ;
3828
29+ import static com .microsoft .azuretools .telemetrywrapper .CommonUtil .*;
30+
3931public class DefaultOperation implements Operation {
4032
4133 private long timeStart ;
@@ -63,19 +55,15 @@ public void logEvent(EventType eventType, Map<String, String> properties, Map<St
6355 if (eventType == EventType .opStart || eventType == EventType .opEnd ) {
6456 return ;
6557 }
66- if (properties == null ) {
67- properties = new HashMap <>();
68- }
69- if (metrics == null ) {
70- metrics = new HashMap <>();
71- }
72- properties .put (OPERATION_ID , operationId );
73- properties .put (OPERATION_NAME , operationName );
58+ Map <String , String > mutableProps = properties == null ? new HashMap <>() : new HashMap <>(properties );
59+ mutableProps .put (OPERATION_ID , operationId );
60+ mutableProps .put (OPERATION_NAME , operationName );
7461
62+ Map <String , Double > mutableMetrics = properties == null ? new HashMap <>() : new HashMap <>(metrics );
7563 if (eventType == EventType .step ) {
76- metrics .put (DURATION , Double .valueOf (System .currentTimeMillis () - timeStart ));
64+ mutableMetrics .put (DURATION , Double .valueOf (System .currentTimeMillis () - timeStart ));
7765 }
78- sendTelemetry (eventType , serviceName , mergeProperties (properties ), metrics );
66+ sendTelemetry (eventType , serviceName , mergeProperties (mutableProps ), mutableMetrics );
7967 } catch (Exception ignore ) {
8068 }
8169 }
@@ -86,26 +74,23 @@ public synchronized void logError(ErrorType errorType, Throwable e, Map<String,
8674 if (isComplete ) {
8775 return ;
8876 }
89- if (properties == null ) {
90- properties = new HashMap <>();
91- }
92- if (metrics == null ) {
93- metrics = new HashMap <>();
94- }
77+ Map <String , String > mutableProps = properties == null ? new HashMap <>() : new HashMap <>(properties );
78+ Map <String , Double > mutableMetrics = properties == null ? new HashMap <>() : new HashMap <>(metrics );
79+
9580 error = new Error ();
9681 error .errorType = errorType == null ? ErrorType .systemError : errorType ;
9782 error .errMsg = e == null ? "" : e .getMessage ();
9883 error .className = e == null ? "" : e .getClass ().getName ();
9984
100- properties .put (ERROR_CODE , "1" );
101- properties .put (ERROR_MSG , error .errMsg );
102- properties .put (ERROR_TYPE , error .errorType .name ());
103- properties .put (ERROR_CLASSNAME , error .className );
104- properties .put (OPERATION_ID , operationId );
105- properties .put (OPERATION_NAME , operationName );
85+ mutableProps .put (ERROR_CODE , "1" );
86+ mutableProps .put (ERROR_MSG , error .errMsg );
87+ mutableProps .put (ERROR_TYPE , error .errorType .name ());
88+ mutableProps .put (ERROR_CLASSNAME , error .className );
89+ mutableProps .put (OPERATION_ID , operationId );
90+ mutableProps .put (OPERATION_NAME , operationName );
10691
107- metrics .put (DURATION , Double .valueOf (System .currentTimeMillis () - timeStart ));
108- sendTelemetry (EventType .error , serviceName , mergeProperties (properties ), metrics );
92+ mutableMetrics .put (DURATION , Double .valueOf (System .currentTimeMillis () - timeStart ));
93+ sendTelemetry (EventType .error , serviceName , mergeProperties (mutableProps ), mutableMetrics );
10994 } catch (Exception ignore ) {
11095 }
11196 }
0 commit comments