@Override
    public Optional<SpanEvent> onSpanError(Throwable throwable) {
        if (!isTracing) {
            return Optional.empty();
        }
        SpanEventContext spanEventContext = threadLocal.get();
        if (spanEventContext == null) {
            return Optional.empty();
        }
        SpanEvent spanEvent = spanEventContext.getSpanEvent();
        spanEvent.setError(true);
        spanEvent.setErrorInfo(throwable.getMessage());
        return Optional.of(spanEvent);
    }
@Test
    public void onSpanError() {
        try (MockedStatic<ServiceManager> mockedStatic = Mockito.mockStatic(ServiceManager.class)) {
            mockedStatic.when(() -> ServiceManager.getService(GatewayClient.class))
                    .thenReturn(new NettyGatewayClient());
            TracingServiceImpl tracingService = new TracingServiceImpl();

            // Service is stopped.
            tracingService.stop();
            Assert.assertFalse(tracingService.onSpanError(new Throwable(SPAN_ERROR_MESSAGE)).isPresent());

            // SpanEventContext is null.
            tracingService.start();
            Assert.assertFalse(tracingService.onSpanError(new Throwable(SPAN_ERROR_MESSAGE)).isPresent());

            // The normal condition.
            String traceId = TracingUtils.generateTraceId();
            header.put(TRACE_ID, traceId);
            header.put(PARENT_SPAN_ID, INIT_PARENT_SPAN_ID);
            header.put(SPAN_ID_PREFIX, INIT_SPAN_ID_PREFIX);
            TracingRequest tracingRequest = new TracingRequest("", "", "", "", "");
            tracingService.onProviderSpanStart(tracingRequest, extractService, header);
            Optional<SpanEvent> spanEventOptional = tracingService.onSpanError(new Throwable(SPAN_ERROR_MESSAGE));
            Assert.assertTrue(spanEventOptional.isPresent());
            Assert.assertTrue(spanEventOptional.get().isError());
            Assert.assertEquals(SPAN_ERROR_MESSAGE, spanEventOptional.get().getErrorInfo());
            tracingService.onSpanFinally();
            tracingService.stop();
        }
    }