@@ -26,8 +26,9 @@ public class ProfileTracer
2626
2727 private string _transactionID = Guid . NewGuid ( ) . ToString ( ) ;
2828 private string _RequestID = null ;
29+ internal bool IsOperation { get ; set ; }
2930
30- public ProfileTracer ( string methodDisplayText , string requestLevelReportingCategory , string appLevelReportingCategory )
31+ internal ProfileTracer ( string methodDisplayText , string requestLevelReportingCategory , string appLevelReportingCategory )
3132 {
3233 _methodDisplayText = methodDisplayText ;
3334 _requestReportingCategory = requestLevelReportingCategory ;
@@ -82,25 +83,68 @@ public static void SetReportingUrl(string reportingUrl)
8283
8384 }
8485
86+
87+ [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
88+ public static void SetOperationName ( string operationName )
89+ {
90+
91+
92+ }
93+
94+
95+ [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
96+ public static void TraceString ( string logMsg )
97+ {
98+
99+ }
100+
85101 [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
86- public static void TraceString ( string value )
102+ public static void TraceMongoCommand ( string logMsg )
87103 {
88104
89105 }
90106
107+ [ Obsolete ( "Use CreateAsCodeBlock or CreateAsOperation" ) ]
91108 public static ProfileTracer Create ( string methodDisplayText )
92109 {
93110 ProfileTracer tracer = new ProfileTracer ( methodDisplayText , null , null ) ;
94111 return tracer ;
95112 }
96113
114+ [ Obsolete ( "Use CreateAsCodeBlock or CreateAsOperation" ) ]
97115 public static ProfileTracer Create ( string methodDisplayText , string requestLevelReportingCategory , string appLevelReportingCategory = null )
98116 {
99117 ProfileTracer tracer = new ProfileTracer ( methodDisplayText , requestLevelReportingCategory , appLevelReportingCategory ) ;
100118 return tracer ;
101119 }
102120
103121
122+ public static ProfileTracer CreateAsCodeBlock ( string methodDisplayText )
123+ {
124+ ProfileTracer tracer = new ProfileTracer ( methodDisplayText , null , null ) ;
125+ return tracer ;
126+ }
127+
128+ public static ProfileTracer CreateAsOperation ( string operationName , string uniqueOperationID = null )
129+ {
130+ ProfileTracer tracer = new ProfileTracer ( operationName , null , null ) ;
131+ tracer . IsOperation = true ;
132+
133+ if ( ! string . IsNullOrEmpty ( uniqueOperationID ) )
134+ {
135+ tracer . _transactionID = uniqueOperationID ;
136+ }
137+
138+ return tracer ;
139+ }
140+
141+ public static ProfileTracer CreateAsCodeBlock ( string methodDisplayText , string requestLevelReportingCategory , string appLevelReportingCategory = null )
142+ {
143+ ProfileTracer tracer = new ProfileTracer ( methodDisplayText , requestLevelReportingCategory , appLevelReportingCategory ) ;
144+ return tracer ;
145+ }
146+
147+
104148 public ProfileTracer CreateMetric ( string categoryName , string metricName , bool trackCount = true , bool trackTime = true , bool autoReportZeroIfNothingReported = false )
105149 {
106150 _customMetricCategory = categoryName ;
@@ -120,21 +164,31 @@ public ProfileTracer IgnoreChildFrames(bool value = true)
120164
121165 //Method the profiler looks for
122166 [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
123- private void ExecInternal ( string traceDisplay , int suppressChildren , string requestLevelReportingCategory , string appLevelReportingCategory , string actionID , string requestID , Action action )
167+ private void ExecInternal2 ( string values , Action action )
124168 {
125- action ( ) ;
169+ try
170+ {
171+ action ( ) ;
172+ }
173+ finally
174+ {
175+ ExecInternalComplete2 ( _transactionID + "|" + _RequestID + "|0|" + IsOperation ) ;
176+
177+ }
126178 }
127179
128180 [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
129- private Task ExecInternal ( string traceDisplay , int suppressChildren , string requestLevelReportingCategory , string appLevelReportingCategory , string actionID , string requestID , Func < Task > action )
181+ private Task ExecInternal2 ( string values , Func < Task > action )
130182 {
131183 Task t = action ( ) ;
132- ExecInternalTaskStarted ( actionID , t . Id ) ;
184+ ExecInternalTaskStarted2 ( _transactionID + "|" + t . Id + "|" + IsOperation ) ;
133185 return t ;
134186 }
135187
188+
189+
136190 [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
137- private void ExecInternalTaskStarted ( string actionID , int taskID )
191+ private void ExecInternalTaskStarted2 ( string values )
138192 {
139193
140194 }
@@ -145,7 +199,7 @@ public void Exec(Action action)
145199 if ( action == null )
146200 return ;
147201 DateTimeOffset now = DateTimeOffset . UtcNow ;
148- ExecInternal ( _methodDisplayText , ignoreChildFrames ? 1 : 0 , _requestReportingCategory , _appReportingCategory , _transactionID , _RequestID , action ) ;
202+ ExecInternal2 ( _methodDisplayText + "|" + ( ignoreChildFrames ? 1 : 0 ) . ToString ( ) + "|" + _requestReportingCategory + "|" + _appReportingCategory + "|" + _transactionID + "|" + _RequestID + "|" + IsOperation , action ) ;
149203
150204
151205 if ( _customMetricTime )
@@ -159,7 +213,6 @@ public void Exec(Action action)
159213 Metrics . Count ( _customMetricCategory , _customMetricName , 1 , _autoReportZeroIfNothingReported ) ;
160214 }
161215
162- ExecInternalComplete ( _transactionID , _RequestID ) ;
163216 }
164217
165218
@@ -168,15 +221,15 @@ public Task ExecAsync(Func<Task> task)
168221 {
169222 DateTimeOffset now = DateTimeOffset . UtcNow ;
170223
171- var t = ExecInternal ( _methodDisplayText , ignoreChildFrames ? 1 : 0 , _requestReportingCategory , _appReportingCategory , _transactionID , _RequestID , task ) ;
224+ var t = ExecInternal2 ( _methodDisplayText + "|" + ( ignoreChildFrames ? 1 : 0 ) . ToString ( ) + "|" + _requestReportingCategory + "|" + _appReportingCategory + "|" + _transactionID + "|" + _RequestID + "|" + IsOperation , task ) ;
172225
173226 t . ContinueWith ( ( tend ) =>
174227 {
175228 if ( _customMetricTime )
176229 {
177230 Metrics . Time ( _customMetricCategory , _customMetricName + " Time" , now ) ;
178231 }
179- ExecInternalComplete ( _transactionID , _RequestID , tend . Id ) ;
232+ ExecInternalComplete2 ( _transactionID + "|" + _RequestID + "|" + tend . Id + "|" + IsOperation ) ;
180233 } ) ;
181234
182235 if ( _customMetricCount )
@@ -189,17 +242,10 @@ public Task ExecAsync(Func<Task> task)
189242
190243
191244 [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
192- private void ExecInternalComplete ( string actionID , string requestID )
245+ private void ExecInternalComplete2 ( string values )
193246 {
194247
195248 }
196249
197- [ MethodImpl ( MethodImplOptions . PreserveSig | MethodImplOptions . NoInlining | MethodImplOptions . NoOptimization ) ]
198- private void ExecInternalComplete ( string actionID , string requestID , int taskID )
199- {
200-
201- }
202-
203-
204250 }
205251}
0 commit comments