Skip to content
Skills Library
Programming · Tool integration

jeffrey-traces-http-client

/jeffrey-traces-http-client

Instrument outbound HTTP calls with Jeffrey JFR events — a ClientHttpRequestInterceptor (RestTemplate, or any HTTP client with an interception point) emitting HttpClientExchangeEvent as a leaf span nested under the request being served. Use when the application calls other services over HTTP and those calls should appear in Jeffrey's HTTP Client dashboard and Traces. Requires the jeffrey-traces-core skill for the data model, emit rules, recording setup, and verification; inbound requests are covered by jeffrey-traces-spring-rest-server.

Repository
jeffrey ↗
Licence
Apache-2.0
Last repository change
27.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Instrument outbound HTTP calls with Jeffrey JFR events — a ClientHttpRequestInterceptor (RestTemplate, or any HTTP client with an interception point) emitting HttpClientExchangeEvent as a leaf span nested under the request being served. Use when the application calls other services over HTTP and those calls should appear in Jeffrey's HTTP Client dashboard and Traces. Requires the jeffrey-traces-core skill for the data model, emit rules, recording setup, and verification; inbound requests are covered by jeffrey-traces-spring-rest-server.

Original author description

Instrument outbound HTTP calls with Jeffrey JFR events — a ClientHttpRequestInterceptor (RestTemplate, or any HTTP client with an interception point) emitting HttpClientExchangeEvent as a leaf span nested under the request being served. Use when the application calls other services over HTTP and those calls should appear in Jeffrey's HTTP Client dashboard and Traces. Requires the jeffrey-traces-core skill for the data model, emit rules, recording setup, and verification; inbound requests are covered by jeffrey-traces-spring-rest-server.

How it works

  1. 1. The shipped interceptor (Spring)
  2. 2. Writing it yourself: RestTemplate interceptor
  3. 3. Registration
  4. 4. Async clients (WebClient, async HttpClient)
  5. 5. Client-side pitfalls
Original SKILL.md headings · 123 lines, 788 words
SKILL.md preview
---
name: jeffrey-traces-http-client
description: Instrument outbound HTTP calls with Jeffrey JFR events — a ClientHttpRequestInterceptor (RestTemplate, or any HTTP client with an interception point) emitting HttpClientExchangeEvent as a leaf span nested under the request being served. Use when the application calls other services over HTTP and those calls should appear in Jeffrey's HTTP Client dashboard and Traces. Requires the jeffrey-traces-core skill for the data model, emit rules, recording setup, and verification; inbound requests are covered by jeffrey-traces-spring-rest-server.
---

# Jeffrey Traces — Outbound HTTP Client Instrumentation

Read **`jeffrey-traces-core`** first — it defines the data model, the emit
rules, the dependency, recording configuration, and verification. This skill
applies those rules to outbound HTTP calls. Inbound request handling is the
companion skill **`jeffrey-traces-spring-rest-server`**.

The client exchange is a **leaf span**: the downstream work happens in another
process this recording cannot see, so the event is committed with
`commitSpan()` — nesting it under the span in progress (usually the server
exchange of the request being served) — never with `Tracer.inSpanOf`.

Rules recap (from the core skill) that this code embodies:

- Leaf events commit with `commitSpan()`; a bare `commit()` silently drops
  the call from every trace. `TracedEvents.emit` below commits that way for
  you.
- `uri` must be low-cardinality: the URI template you expanded, or host + path
  with variable segments collapsed — never a URL containing an entity id.
- `statusCode` drives span status automatically: `describeSpan()` marks
  `>= 400` as `ERROR` — never set `name`/`status` yourself. A transport
  failure that produced no status code is recorded with `event.failed(e)`,
  which the derived verdict never paints over.

---

## 1. The shipped interceptor (Spring)

`jeffrey-tracing-spring` ships this interceptor, so on Spring you do not write it. Adding
`jeffrey-tracing-spring-boot-starter` (or `@Import(JeffreyTracingConfiguration.class)` on plain
Spring) gives you a `JfrClientHttpRequestInterceptor` bean; attach it where you build the client:

```java
RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add(interceptor);   // the bean from the configuration
```

It is only a bean, not attached automatically: Spring Boot 4 removed `RestTemplateCustomizer`, and
applications build clients in too many ways for a starter to guess. By default it records host and
path with the query string dropped — that is where ids and tokens live — and you can pass a
`Function<URI, String>` to collapse variable path segments into a template instead.

The rest of this section shows what that interceptor does, for a client with no Spring involved.

## 2. Writing it yourself: RestTemplate interceptor

For `RestTemplate` (a `ClientHttpRequestInterceptor`); the same shape applies
to any HTTP client with an interception point:

```java
public class JeffreyJfrRestTemplateInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(
            HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {

        // TracedEvents.emit is the whole leaf lifecycle: guard, begin, end on
        // success, failed(e) on the exception path (a transport failure that
        // never produced a status code shows red), commitSpan() stamping the
        // event under the span in progress — usually the server exchange of
        // the request being served. The IOException propagates through typed.
        HttpClientExchangeEvent event = new HttpClientExchangeEvent();
        return TracedEvents.emit(event,
                () -> execution.execute(request, body),
                (e, response) -> {
                    e.method = request.getMethod().name();
                    // Low-cardinality: host + path with variable segments
                    // collapsed, ideally the URI template you expanded. Never a
                    // URL containing an entity id — one distinct name per
                    // endpoint, not per call.
                    e.uri = request.getURI().getHost() + normalizePath(request.getURI().getPath());
                    e.remoteHost = request.getURI().getHost();
                    e.remotePort = request.getURI().getPort();
                    e.requestLength = body.length;
                    // response is null when the call threw before answering.
                    e.statusCode = response != null ? response.getStatusCode().value() : 0;
                });
    }
}
```

Where `TracedEvents` does not fit, write the expanded shape from the core
skill's §4 rule 3 instead (guard, `begin()`, `end()` on success, `commitSpan()`
in the `finally`).

## 3. Registration

```java
restTemplate.getInterceptors().add(new JeffreyJfrRestTemplateInterceptor());
```

Or, in Spring Boot, via a `RestTemplateCustomizer`/`RestTemplateBuilder` bean
so every built `RestTemplate` carries it:

```java
@Bean
public RestTemplateCustomizer jeffreyJfrRestTemplateCustomizer() {
    return restTemplate ->
            restTemplate.getInterceptors().add(new JeffreyJfrRestTemplateInterceptor());
}
```

## 4. Async clients (WebClient, async HttpClient)

A blocking interceptor shape does not fit a client whose response arrives via
callbacks on threads you don't control. Use the callback pattern from the core
skill instead: `Tracer.openSpanOf(event)` when the call starts (on
the thread whose span it belongs to), `Tracer.reenter(ctx, ...)` around each
callback, and `event.commitSpan()` at completion. `openSpanOf` stamps the ids
eagerly, so a completion running after the enclosing binding is gone still
carries the right identity.

## 5. Client-side pitfalls

| Symptom | Cause | Fix |
|---|---|---|
| Calls in the HTTP Client dashboard but not in Traces | committed with `commit()` | `TracedEvents.emit`, or `commitSpan()` in the `finally` |
| Client calls are roots of their own one-span traces | call ran outside a bound span (no server filter, `@Async`, scheduled job) | register the root-span filter (`jeffrey-traces-spring-rest-server`); wrap background work with `Tracer.fork`/`continueIn` |
| One "endpoint" per entity id | raw expanded URL recorded as `uri` | record the template / normalized path |
| Connection failures look green | exception path missing `failed(e)` | `TracedEvents.emit` records it; by hand, catch the transport exception, call `event.failed(e)`, rethrow |
| Async call measured as ~0 ms | event ended when the request was *sent*, not when the response arrived | complete the event from the response callback (deferred-commit pattern, §3) |

Versions

The database has no other skills named jeffrey-traces-http-client.

Database snapshot: 13.11.2026 · package version 63aa16660056 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100advise-jfr
    Turns a Jeffrey profile into concrete code changes in the current repository — maps the hottest CPU, wall-clock, allocation and blocking frames, the slowest traces, the waiting on locks and I/O, and the database and HTTP work to real source, recommends minimal…
  • 90help
    Explains what a running Jeffrey Microscope can investigate and how to get there — the areas a JFR recording or a heap dump can answer (CPU, wall-clock, allocation, locks, requests and outbound calls, the database, I/O, exceptions, GC and pauses, JIT, threads, native memory, the…
  • 100spring-testing-http-client
    Test outbound HTTP client code in Spring Boot apps - RestClient, HTTP interface clients (@HttpExchange), RestTemplate - with MockRestServiceServer, @RestClientTest, or a stub HTTP server. Use when testing code that calls a third-party or remote API: the request it sends, how it…
  • 100http-client-config
    Configure http client config operations. Auto-activating skill for API Integration. Triggers on: http client config, http client config Part of the API Integration skill category. Use when configuring systems or services. Trigger with phrases like "http client config", "http config", "http".
  • 100laravel-rest-api
    REST API and HTTP-edge rules for Laravel — authorization before the domain runs, validation and DTO construction in Form Requests, scoped route model binding for nested resources, JSON output through Resources, thin controllers, and domain exceptions mapped to status codes…
  • 87snowbank-betterhttp
    How to make outbound HTTP calls with BetterHttpClient (SnowBank.Networking.Http) in an ASP.NET Core or generic-host .NET application - the DI story and the request API. Covers the one-policy-plane model where a client NAME maps to one effective policy that lives in the pooled…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.