Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing Ws{{Action}}Context.matchedPath() functionality #2217

Open
LoonyRules opened this issue Apr 7, 2024 · 0 comments
Open

Confusing Ws{{Action}}Context.matchedPath() functionality #2217

LoonyRules opened this issue Apr 7, 2024 · 0 comments

Comments

@LoonyRules
Copy link
Contributor

LoonyRules commented Apr 7, 2024

Describe your issue
When I was updating my Request Logger to log WebSockets, I noticed that the Ws{{Action}}Context.matchedPath() was returning * instead of /ws that I would've expected.

For HTTP requests, via the Context class, .matchedPath() would return the endpoint path that you registered via:

config.get("/resource/{resource_id}/`, ctx -> { ... });

when being called from inside of the RequestLogger, meaning, that the Context.matchedPath() result is /resource/{resource_id}/, not *.

The Request Logger is always going to match on ALL requests, it's kind of its point, of which is how it's getting the * value in the first place. So I'm more confused as to why the implementation for WebSockets ever uses * as the matchedPath as it's never useful to the end user in the first place.

To @tipsy, this feels more like an API design flaw in the naming conventions and is something that is up for discussion in Javalin 7 over at #2091, but to me as a user, it sounds more like an implementation flaw that wasn't caught or questioned early on simply due to the fact that not a lot of Javalin users use the WebSockets functionality in the first place. How this issue is determined (api flaw or implementation flaw) isn't all that important, just outlining the confusion is important here.

What I really wanted for my request logging was:

public void onWsConnect(final @NotNull WsConnectContext ctx) {
  String matchedPath = ctx.getUpgradeCtx$javalin().matchedPath();
}

I have raised a separate issue for making this getter method nicer to read for Java developers.

What would be nice, would be to have a Ws{{Action}}Context.path() method, but for metric logging (eg: Prometheus) I need the matched path, so I'm still reliant on the upgrade context for my usage. You typically want the full path .path() for console logging, but then the matchedPath for timeseries.

@LoonyRules LoonyRules changed the title Confusing WsContext.matchedPath() functionality Confusing Ws{{Action}}Context.matchedPath() functionality Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant