Skip to content

Treat OkHttp Request as non-nullable - #7388

Merged
shakuzen merged 7 commits into
micrometer-metrics:mainfrom
jonatan-ivanov:okhttp-nullable-rq
Apr 9, 2026
Merged

shakuzen merged 7 commits into
micrometer-metrics:mainfrom
jonatan-ivanov:okhttp-nullable-rq

Conversation

@jonatan-ivanov

@jonatan-ivanov jonatan-ivanov commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

The return type and the parameter type of the getState/setState methods are OkHttpObservationInterceptor$CallState which is package-private so they are not really usable for the users.

See gh-7373
See gh-7375

TODO:

  • Add more tests
  • I still don't like these being part of the context, they belong to the convention but this probably should be another PR:
Function<Request, String> urlMapper;
Iterable<KeyValue> extraTags;
Iterable<BiFunction<Request, @Nullable Response, KeyValue>> contextSpecificTags;
boolean includeHostTag;

I think reviewing commit-by-commit might be easier than reviewing the whole.

The return type and the parameter type of these methods are
OkHttpObservationInterceptor$CallState which is package-private so this
method is not really usable for the users.
@jonatan-ivanov jonatan-ivanov added this to the 1.x milestone Apr 8, 2026
@jonatan-ivanov

Copy link
Copy Markdown
Member Author

/cc @jckoenen

…rceptor

Previously a new DefaultOkHttpObservationConvention was created
for each request.
@jonatan-ivanov jonatan-ivanov changed the title Treat OkHttp Request nullable Treat OkHttp Request non-nullable Apr 8, 2026

@shakuzen shakuzen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I agree more tests would be nice to ensure something subtle hasn't broken. It will also be good to get some testing by users with these changes before GA.

if (request == null) {
return unknownRequestTags;
}
private Iterable<KeyValue> getRequestTags(Request request) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it looks like the return type could be more specifically typed as KeyValues. Feel free to ignore in this PR since it's the same as before these changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to ignore this but I think this might be better fixed in a different PR given that the return type here is Iterable because of List<KeyValue> tagsToKeyValues and also there is this TODO comment:

// TODO: Tags to key values and back - maybe we can improve this?

So I would fix this with the underlying issue (tags-keyvalues conversions).

@jonatan-ivanov jonatan-ivanov modified the milestones: 1.x, 1.17.0-RC1 Apr 9, 2026
@shakuzen shakuzen changed the title Treat OkHttp Request non-nullable Treat OkHttp Request as non-nullable Apr 9, 2026
@shakuzen
shakuzen merged commit 367a12b into micrometer-metrics:main Apr 9, 2026
12 checks passed
@shakuzen

shakuzen commented Apr 9, 2026

Copy link
Copy Markdown
Member

@jckoenen could you try out 1.17.0 snapshots and let us know if you have any problems with these changes?

@jonatan-ivanov
jonatan-ivanov deleted the okhttp-nullable-rq branch April 9, 2026 17:33
@jckoenen

Copy link
Copy Markdown

@shakuzen Sorry, it took a bit to get to it. Using 1.17.0-SNAPSHOT in our tests I didn't encounter any issues. I can try running it in production next week, but since our usage is rather trivial I don't expect anything to come up.

Thank you all for your work!

@shakuzen

Copy link
Copy Markdown
Member

Thanks for trying it out and letting us know. We should have an RC1 release out on Monday for further testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants