File tree Expand file tree Collapse file tree
sdk-platform-java/gax-java/gax/src
main/java/com/google/api/gax/tracing
test/java/com/google/api/gax/tracing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535import io .opentelemetry .api .trace .Span ;
3636import io .opentelemetry .api .trace .SpanBuilder ;
3737import io .opentelemetry .api .trace .SpanKind ;
38+ import io .opentelemetry .api .trace .StatusCode ;
3839import io .opentelemetry .api .trace .Tracer ;
3940import java .util .HashMap ;
4041import java .util .Map ;
@@ -238,9 +239,12 @@ private void recordErrorAndEndOperation(@Nullable Throwable error) {
238239 localOperationSpan .setAllAttributes (ObservabilityUtils .toOtelAttributes (responseAttributes ));
239240 }
240241
241- if (error != null && !Strings .isNullOrEmpty (error .getMessage ())) {
242- localOperationSpan .setAttribute (
243- ObservabilityAttributes .STATUS_MESSAGE_ATTRIBUTE , error .getMessage ());
242+ if (error != null ) {
243+ localOperationSpan .setStatus (StatusCode .ERROR );
244+ if (!Strings .isNullOrEmpty (error .getMessage ())) {
245+ localOperationSpan .setAttribute (
246+ ObservabilityAttributes .STATUS_MESSAGE_ATTRIBUTE , error .getMessage ());
247+ }
244248 }
245249
246250 localOperationSpan .end ();
Original file line number Diff line number Diff line change @@ -751,6 +751,7 @@ public Object getTransportCode() {
751751 verify (operationSpan ).setAllAttributes (attrsCaptor .capture ());
752752 verify (operationSpan )
753753 .setAttribute (ObservabilityAttributes .STATUS_MESSAGE_ATTRIBUTE , "custom failure" );
754+ verify (operationSpan ).setStatus (io .opentelemetry .api .trace .StatusCode .ERROR );
754755 verify (operationSpan ).end ();
755756
756757 Map <AttributeKey <?>, Object > captured = attrsCaptor .getValue ().asMap ();
@@ -769,6 +770,7 @@ void testOperationCancelled_endsOperationSpanWithCancelledStatus() {
769770
770771 ArgumentCaptor <Attributes > attrsCaptor = ArgumentCaptor .forClass (Attributes .class );
771772 verify (operationSpan ).setAllAttributes (attrsCaptor .capture ());
773+ verify (operationSpan ).setStatus (io .opentelemetry .api .trace .StatusCode .ERROR );
772774 verify (operationSpan ).end ();
773775
774776 assertThat (attrsCaptor .getValue ().asMap ())
@@ -829,6 +831,7 @@ void testOperationFailed_endsActiveAttemptSpan() {
829831
830832 verify (span ).setAttribute (ObservabilityAttributes .STATUS_MESSAGE_ATTRIBUTE , "operation failed" );
831833 verify (span ).end ();
834+ verify (operationSpan ).setStatus (io .opentelemetry .api .trace .StatusCode .ERROR );
832835 verify (operationSpan ).end ();
833836 }
834837}
You can’t perform that action at this time.
0 commit comments