CurtHagenlocher commented on code in PR #2847:
URL: https://github.com/apache/arrow-adbc/pull/2847#discussion_r2157643009


##########
csharp/src/Apache.Arrow.Adbc/Tracing/ActivityTrace.cs:
##########
@@ -0,0 +1,325 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace Apache.Arrow.Adbc.Tracing
+{
+    /// <summary>
+    /// Provides the implementation for a tracing source. If drivers want to 
enable tracing,
+    /// they need to add a trace listener (e.g., <see 
cref="FileExporter.FileExporter"/>).
+    /// </summary>
+    public sealed class ActivityTrace
+    {
+        internal const string ProductVersionDefault = "1.0.0";
+        private bool _isDisposed;
+
+        /// <summary>
+        /// Constructs a new <see cref="ActivityTrace"/> object. If <paramref 
name="activitySourceName"/> is set, it provides the
+        /// activity source name, otherwise the current assembly name is used 
as the activity source name.
+        /// </summary>
+        /// <param name="activitySourceName"></param>
+        public ActivityTrace(string? activitySourceName = default, string? 
activitySourceVersion = default, string? traceParent = default)
+        {
+            activitySourceName ??= GetType().Assembly.GetName().Name!;
+            if (string.IsNullOrWhiteSpace(activitySourceName))
+            {
+                throw new ArgumentNullException(nameof(activitySourceName));
+            }
+
+            TraceParent = traceParent;
+            // This is required to be disposed
+            ActivitySource = new(activitySourceName, activitySourceVersion);
+        }
+
+        /// <summary>
+        /// Gets the <see cref="System.Diagnostics.ActivitySource"/>.
+        /// </summary>
+        public ActivitySource ActivitySource { get; }
+
+        /// <summary>
+        /// Gets the name of the <see 
cref="System.Diagnostics.ActivitySource"/>
+        /// </summary>
+        public string ActivitySourceName => ActivitySource.Name;
+
+        /// <summary>
+        /// Invokes the delegate within the context of a new started <see 
cref="Activity"/>.
+        /// </summary>
+        /// <param name="call">The delegate to call within the context of a 
newly started <see cref="Activity"/></param>
+        /// <param name="methodName">The name of the method for the 
activity.</param>
+        /// <returns>Returns a new <see cref="Activity"/> object if there is 
any listener to the Activity, returns null otherwise</returns>
+        /// <remarks>
+        /// Creates and starts a new <see cref="Activity"/> object if there is 
any listener for the ActivitySource.
+        /// Passes the Activity to the delegate and invokes the delegate. If 
there are no exceptions thrown by the delegate the
+        /// Activity status is set to <see cref="ActivityStatusCode.Ok"/>. If 
an exception is thrown by the delegate, the Activity
+        /// status is set to <see cref="ActivityStatusCode.Error"/> and an 
Activity <see cref="ActivityEvent"/> is added to the actitity
+        /// and finally the exception is rethrown.
+        /// </remarks>
+        public void TraceActivity(Action<Activity?> call, [CallerMemberName] 
string? activityName = default, string? traceParent = default)
+        {
+            using Activity? activity = StartActivityInternal(activityName, 
ActivitySource, traceParent ?? TraceParent);

Review Comment:
   Apparently, my brain hasn't yet learned to pattern-match on `using` 
statements :/.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to