@@ -532,53 +532,35 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
532532 try
533533 {
534534 TResult result = await task ( trace ) . ConfigureAwait ( false ) ;
535-
535+ // Checks if OpenTelemetry is configured for this operation and either Trace or Metrics are enabled by customer
536536 if ( isOtelCompatibleOperation )
537537 {
538538 // Extracts and records telemetry data from the result of the operation.
539539 OpenTelemetryAttributes otelAttributes = openTelemetry ? . GetAttributes ( result ) ;
540540
541- // Checks if OpenTelemetry is configured for this operation when Trace are enabled by customer
542- if ( ! this . clientOptions . CosmosClientTelemetryOptions . DisableDistributedTracing )
543- {
544- // Records the telemetry attributes for Distributed Tracing (if enabled) and Metrics
545- recorder . Record ( otelAttributes ) ;
546- }
547-
548- // Checks if OpenTelemetry is configured for this operation when Metrics are enabled by customer
549- if ( this . clientOptions . CosmosClientTelemetryOptions . IsClientMetricsEnabled )
550- {
551- RecordMetrics ( getOperationName ,
552- this . client . Endpoint ,
553- containerName ,
554- databaseName ,
555- requestOptions ,
556- attributes : otelAttributes ) ;
557- }
541+ // Records the telemetry attributes for Distributed Tracing (if enabled) and Metrics
542+ recorder . Record ( otelAttributes ) ;
543+ RecordMetrics ( getOperationName ,
544+ this . client . Endpoint ,
545+ containerName ,
546+ databaseName ,
547+ requestOptions ,
548+ attributes : otelAttributes ) ;
558549 }
559-
550+
560551 return result ;
561552 }
562553 catch ( Exception ex ) when ( TryTransformException ( ex , trace , this . client , out Exception cosmosException ) )
563554 {
564555 if ( isOtelCompatibleOperation )
565556 {
566- // Checks if OpenTelemetry is configured for this operation when Trace are enabled by customer
567- if ( ! this . clientOptions . CosmosClientTelemetryOptions . DisableDistributedTracing )
568- {
569- recorder . MarkFailed ( cosmosException ) ;
570- }
571-
572- // Checks if OpenTelemetry is configured for this operation when Metrics are enabled by customer
573- if ( this . clientOptions . CosmosClientTelemetryOptions . IsClientMetricsEnabled )
574- {
575- RecordMetrics ( getOperationName ,
557+ recorder . MarkFailed ( cosmosException ) ;
558+ RecordMetrics ( getOperationName ,
576559 gatewayEndpoint ,
577560 containerName ,
578561 databaseName ,
579562 requestOptions ,
580563 cosmosException : cosmosException ) ;
581- }
582564 }
583565
584566 throw cosmosException ; // Rethrow after recording telemetry
0 commit comments