birschick-bq commented on code in PR #2847: URL: https://github.com/apache/arrow-adbc/pull/2847#discussion_r2130263603
########## csharp/src/Apache.Arrow.Adbc/Tracing/ActivityExtensions.cs: ########## @@ -0,0 +1,106 @@ +/* + * 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.Text; + +namespace Apache.Arrow.Adbc.Tracing +{ + public static class ActivityExtensions + { + /// <summary> + /// Add a new <see cref="ActivityEvent"/> object to the <see cref="Activity.Events" /> list. + /// </summary> + /// <param name="eventName">The name of the event.</param> + /// <param name="tags">The optional list of tags to attach to the event.</param> + /// <returns><see langword="this"/> for convenient chaining.</returns> + public static Activity? AddEvent(this Activity? activity, string eventName, IReadOnlyList<KeyValuePair<string, object?>>? tags = default) + { + if (activity == null) return activity; + ActivityTagsCollection? tagsCollection = tags == null ? null : new ActivityTagsCollection(tags); + return activity?.AddEvent(new ActivityEvent(eventName, tags: tagsCollection)); + } + + /// <summary> + /// Add a new <see cref="ActivityLink"/> to the <see cref="Activity.Links"/> list. + /// </summary> + /// <param name="traceParent">The traceParent id for the associated <see cref="ActivityContext"/>.</param> + /// <param name="tags">The optional list of tags to attach to the event.</param> + /// <returns><see langword="this"/> for convenient chaining.</returns> + public static Activity? AddLink(this Activity? activity, string traceParent, IReadOnlyList<KeyValuePair<string, object?>>? tags = default) + { + if (activity == null) return activity; + ActivityTagsCollection? tagsCollection = tags == null ? null : new ActivityTagsCollection(tags); + return activity?.AddLink(new ActivityLink(ActivityContext.Parse(traceParent, null), tags: tagsCollection)); + } + + /// <summary> + /// Update the Activity to have a tag with an additional 'key' and value 'value'. + /// This shows up in the <see cref="TagObjects"/> enumeration. It is meant for information that + /// is useful to log but not needed for runtime control (for the latter, <see cref="Baggage"/>) + /// </summary> + /// <returns><see langword="this" /> for convenient chaining.</returns> + /// <param name="key">The tag key name as a function</param> + /// <param name="value">The tag value mapped to the input key as a function</param> + public static Activity? AddTag(this Activity? activity, Func<string> key, Func<object?> value) Review Comment: Now marked as sealed. (Previous iterations inherited this class) -- 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]
