birschick-bq commented on code in PR #3157:
URL: https://github.com/apache/arrow-adbc/pull/3157#discussion_r2211077207


##########
csharp/src/Apache.Arrow.Adbc/Tracing/ActivityWithPii.cs:
##########
@@ -0,0 +1,277 @@
+/*
+ * 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.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+
+namespace Apache.Arrow.Adbc.Tracing
+{
+    public sealed class ActivityWithPii : IDisposable
+    {
+        private readonly Activity _activity;
+
+        internal ActivityWithPii(Activity activity)
+        {
+            _activity = activity;
+        }
+
+        /// <summary>
+        /// Update the Activity to have baggage with an additional 'key' and 
value 'value'.
+        /// This shows up in the <see cref="Baggage"/> enumeration as well as 
the <see cref="GetBaggageItem(string)"/>
+        /// method.
+        /// Baggage is meant for information that is needed for runtime 
control.   For information
+        /// that is simply useful to show up in the log with the activity use 
<see cref="Tags"/>.
+        /// Returns 'this' for convenient chaining.
+        /// </summary>
+        /// <returns><see langword="this" /> for convenient chaining.</returns>
+        public ActivityWithPii AddBaggage(string key, RedactedValue value)
+        {
+            _activity.AddBaggage(key, value.ToString());
+            return this;
+        }
+
+        /// <summary>
+        /// Update the Activity to have baggage with an additional 'key' and 
value 'value'. Use parameter 'isPii' to indicate
+        /// whether the value is PII (Personally Identifiable Information).
+        /// This shows up in the <see cref="Baggage"/> enumeration as well as 
the <see cref="GetBaggageItem(string)"/>
+        /// method.
+        /// Baggage is meant for information that is needed for runtime 
control.   For information
+        /// that is simply useful to show up in the log with the activity use 
<see cref="Tags"/>.
+        /// Returns 'this' for convenient chaining.
+        /// </summary>
+        /// <returns><see langword="this" /> for convenient chaining.</returns>
+        public ActivityWithPii AddBaggage(string key, object? value, bool 
isPii = true)
+        {
+            _activity.AddBaggage(key, ToRedactedValue(value, 
isPii).ToString());
+            return this;
+        }
+
+        /// <summary>
+        /// Add <see cref="ActivityEvent" /> object to the <see cref="Events" 
/> list.
+        /// </summary>
+        /// <param name="e"> object of <see cref="ActivityEvent"/> to add to 
the attached events list.</param>
+        /// <returns><see langword="this" /> for convenient chaining.</returns>
+        public ActivityWithPii AddEvent(string eventName, 
IReadOnlyList<KeyValuePair<string, RedactedValue?>>? tags)
+        {
+            ActivityTagsCollection? tagsCollection = 
ToActivityTagsCollection(tags);
+            _activity.AddEvent(new ActivityEvent(eventName, tags: 
tagsCollection));
+            return this;
+        }
+
+        /// <summary>
+        /// Add <see cref="ActivityEvent" /> object to the <see cref="Events" 
/> list. Use parameter 'isPii' to indicate
+        /// whether the tags contain PII (Personally Identifiable Information).
+        /// </summary>
+        /// <param name="e"> object of <see cref="ActivityEvent"/> to add to 
the attached events list.</param>
+        /// <returns><see langword="this" /> for convenient chaining.</returns>
+        public ActivityWithPii AddEvent(string eventName, 
IReadOnlyList<KeyValuePair<string, object?>>? tags = default, bool isPii = true)
+        {
+            ActivityTagsCollection? tagsCollection = 
ToActivityTagsCollection(tags, isPii);
+            _activity.AddEvent(new ActivityEvent(eventName, tags: 
tagsCollection));
+            return this;
+        }
+
+        /// <summary>
+        /// Add an <see cref="ActivityEvent" /> object containing the 
exception information to the <see cref="Events" /> list.
+        /// </summary>
+        /// <param name="exception">The exception to add to the attached 
events list.</param>
+        /// <param name="isPii">Indicates whether the exception message 
contain PII (Personally Identifiable Information).</param>
+        /// <returns><see langword="this" /> for convenient chaining.</returns>
+        /// <remarks>
+        /// <para>- The name of the event will be "exception", and it will 
include the tags "exception.message", "exception.stacktrace", and 
"exception.type".</para>
+        /// <para>- Any registered <see cref="ActivityListener"/> with the 
<see cref="ActivityListener.ExceptionRecorder"/> callback will be notified 
about this exception addition
+        /// before the <see cref="ActivityEvent" /> object is added to the 
<see cref="Events" /> list.</para>
+        /// <para>- Any registered <see cref="ActivityListener"/> with the 
<see cref="ActivityListener.ExceptionRecorder"/> callback that adds 
"exception.message", "exception.stacktrace", or "exception.type" tags
+        /// will not have these tags overwritten, except by any subsequent 
<see cref="ActivityListener"/> that explicitly overwrites them.</para>
+        /// </remarks>
+        public ActivityWithPii AddException(Exception exception, bool isPii = 
true)
+        {
+            const string ExceptionMessageTag = "exception.message";
+            TagList tagList = new();
+            if (isPii)
+            {
+                tagList.Add(new KeyValuePair<string, 
object?>(ExceptionMessageTag, new RedactedValue(exception.Message)));
+            }

Review Comment:
   It is not clear, but the `AddException` method will add the exception 
message if it does not exist in the passed `tagList`.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to