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


##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs:
##########
@@ -294,6 +301,31 @@ internal HiveServer2Connection(IReadOnlyDictionary<string, 
string> properties)
             }
         }
 
+        private void TryInitTracerProvider(out FileActivityListener? 
fileActivityListener)
+        {
+            Properties.TryGetValue(ListenersOptions.Exporter, out string? 
exporterOption);
+            // This listener will only listen for activity from this specific 
connection instance.
+            bool shouldListenTo(ActivitySource source) => source.Tags?.Any(t 
=> t.Key == _traceInstanceId) == true;
+            FileActivityListener.TryActivateFileListener(AssemblyName, 
exporterOption, out fileActivityListener, shouldListenTo: shouldListenTo);

Review Comment:
   returning `bool`



##########
csharp/src/Telemetry/Traces/Exporters/ExportersBuilder.cs:
##########
@@ -94,32 +94,63 @@ public static Builder Build(string sourceName, string? 
sourceVersion = default,
             out string? exporterName,
             string environmentName = ExportersOptions.Environment.Exporter)
         {
-            TracerProvider? tracerProvider = null;
-            exporterName = null;
-
-            if (string.IsNullOrWhiteSpace(exporterOption))
+            if (TryActivate(exporterOption, out exporterName, out 
TracerProvider? tracerProvider, environmentName))
             {
-                // Fall back to check the environment variable
-                exporterOption = 
Environment.GetEnvironmentVariable(environmentName);
+                return tracerProvider;
             }
-            if (string.IsNullOrWhiteSpace(exporterOption))
+            if (!string.IsNullOrEmpty(exporterName) && exporterName != 
ExportersOptions.Exporters.None)
             {
-                // Neither option or environment variable is set - no tracer 
provider will be activated.
-                return null;
+                // Requested option has not been added via the builder
+                throw AdbcException.NotImplemented($"Exporter option 
'{exporterName}' is not implemented.");
             }
+            return null;
+        }
+
+        /// <summary>
+        /// Tries to activate an exporter based on the dictionary of <see 
cref="TracerProvider"/> factories.
+        /// </summary>
+        /// <param name="exporterOption">The value (name) of the exporter 
option, typically passed as option <see 
cref="ExportersOptions.Exporter"/>.</param>
+        /// <param name="exporterName">The actual exporter name when 
successfully activated.</param>
+        /// <param name="tracerProvider">A non-null <see 
cref="TracerProvider"/> when successfully activated. Returns null if not 
successful. Note: this object must be explicitly disposed when no longer 
necessary.</param>
+        /// <param name="environmentName">The (optional) name of the 
environment variable to test for the exporter name. Default: <see 
cref="ExportersOptions.Environment.Exporter"/></param>
+        /// <returns>Returns true if the exporter was successfully activated. 
Returns false, otherwise.</returns>
+        public bool TryActivate(
+            string? exporterOption,
+            out string? exporterName,
+            out TracerProvider? tracerProvider,
+            string environmentName = ExportersOptions.Environment.Exporter)
+        {
+            tracerProvider = null;
+            exporterName = null;
 
-            if (!_tracerProviderFactories.TryGetValue(exporterOption!, out 
Func<string, string?, TracerProvider?>? factory))
+            if (!TryGetExporterName(exporterOption, environmentName, out 
exporterName)
+                || !_tracerProviderFactories.TryGetValue(exporterName!, out 
Func<string, string?, TracerProvider?>? factory))
             {
-                // Requested option has not been added via the builder
-                throw AdbcException.NotImplemented($"Exporter option 
'{exporterOption}' is not implemented.");
+                return false;
             }
 
             tracerProvider = factory.Invoke(_sourceName, _sourceVersion);
-            if (tracerProvider != null)
+            if (tracerProvider == null)
             {
-                exporterName = exporterOption;
+                return false;
             }
-            return tracerProvider;
+
+            return true;
+        }
+
+        /// <summary>
+        /// Determines whether the specified exporter option would activate an 
exporter.
+        /// </summary>
+        /// <param name="exporterOption">The value (name) of the exporter 
option, typically passed as option <see 
cref="ExportersOptions.Exporter"/>.</param>
+        /// <param name="exporterName">The actual exporter name when 
successfully activated.</param>
+        /// <returns></returns>
+        public bool WouldActivate(string? exporterOption, string 
environmentName = ExportersOptions.Environment.Exporter)

Review Comment:
   removed



-- 
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