Skip to content

Provide target host/port info in ObservationExecChainHandler when HttpHostConnectException is thrown #5615

@fseebach

Description

@fseebach

Describe the bug
ObservationExecChainHandler does not report "target.host", "target.port",.... in case of HttpHostConnectException

Environment

  • Micrometer version 1.13.6
  • Java version: 21
  • Apache httpclient5 version 5.3.1

To Reproduce
How to reproduce the bug:

public class Main {
    public static void main(String[] args) throws IOException {
        SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry();
        ObservationRegistry registry = ObservationRegistry.create();
        registry.observationConfig().observationHandler(new DefaultMeterObservationHandler(meterRegistry));
        CloseableHttpClient client = HttpClientBuilder.create()
                .addExecInterceptorAfter(ChainElement.PROTOCOL.name(), "micrometer", new ObservationExecChainHandler(registry))
                .build();

        ClassicHttpRequest request = new HttpGet("http://localhost:777/123");
        try {
            client.execute(request, response -> {
                return null;
            });
        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println(meterRegistry.getMetersAsString());
    }
}

Output:

httpcomponents.httpclient.request(TIMER)[error='HttpHostConnectException', exception='HttpHostConnectException', method='GET', outcome='UNKNOWN', status='IO_ERROR', target.host='UNKNOWN', target.port='UNKNOWN', target.scheme='UNKNOWN', uri='UNKNOWN']; count=1.0, total_time=0.0480618 seconds, max=0.0480618 seconds

httpcomponents.httpclient.request.active(LONG_TASK_TIMER)[exception='none', method='GET', outcome='UNKNOWN', status='CLIENT_ERROR', target.host='UNKNOWN', target.port='UNKNOWN', target.scheme='UNKNOWN', uri='UNKNOWN']; active_tasks=0.0, duration=0.0 seconds

Expected behavior
"target.host", "target.port",.... should be reported correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementA general enhancementinstrumentationAn issue that is related to instrumenting a componentmodule: micrometer-coreAn issue that is related to our core module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions