Skip to content

Conversation

@geoand
Copy link
Contributor

@geoand geoand commented May 15, 2025

@geoand geoand requested a review from cescoffier May 15, 2025 14:50
@quarkus-bot
Copy link

quarkus-bot bot commented May 15, 2025

/cc @brunobat (micrometer), @ebullient (micrometer)

Copy link
Contributor

@adutra adutra left a comment

Choose a reason for hiding this comment

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

Thank you for the quick implementation!

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

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

I'm not a big fan of reading duplicated content after requests, but we can find a better way later.

@geoand
Copy link
Contributor Author

geoand commented May 15, 2025

Yeah, we will likely need a better solution in the future. The good thing with this, is that the use of DC is not exposed to the user

@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label May 15, 2025
@quarkus-bot

This comment has been minimized.

```
- Refactor context local data handling across Micrometer integration to improve type safety with generics.
- Simplify and clean up code by removing unnecessary type casts in `ContextLocalTag`.
```
@geoand
Copy link
Contributor Author

geoand commented May 15, 2025

@gastaldi actually now that I think of it we don't want that because it ties the type of the key and the type of value.

@gastaldi
Copy link
Contributor

gastaldi commented May 15, 2025

@gastaldi actually now that I think of it we don't want that because it ties the type of the key and the type of value.

No, they are totally unrelated. I can write Integer myInt = context.requestContextLocalData("context-local") and the code will still compile

@geoand
Copy link
Contributor Author

geoand commented May 15, 2025

👌

@quarkus-bot
Copy link

quarkus-bot bot commented May 15, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit c9509a5.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@geoand geoand merged commit b0ccf1e into quarkusio:main May 15, 2025
34 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.24 - main milestone May 15, 2025
@quarkus-bot quarkus-bot bot added kind/enhancement New feature or request and removed triage/waiting-for-ci Ready to merge when CI successfully finishes labels May 15, 2025
@gastaldi gastaldi deleted the #47886 branch May 15, 2025 16:19
public class PathTemplateResource {
@GET
public String get(@PathParam("value") String value) {
ContextLocals.put("context-local", "val-" + value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bad practice. We should not encourage ppl to add tags from path params. Even if they think the nr of different values are limited, they cannot really control it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be bad practice, but people shouldn't be limited by accidental technically reasons from doing it.

ThreadLocals should not be used generally, but that doesn't mean we should prevent their use.

Copy link
Contributor

@brunobat brunobat May 15, 2025

Choose a reason for hiding this comment

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

Fair, but this should come with a big warning that they will shoot themselves in the foot if they don't consider cardinatility.
See for example: #users > Are you using path parameters? (metrics)

I think a warning should be placed in the docs and a in the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because in the end, ppl will complain and we will spend time debugging this stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would add we should also place a warning in the Javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want to add something in the various places, I'll gladly approve

Copy link
Contributor

@adutra adutra May 15, 2025

Choose a reason for hiding this comment

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

For context: my initial use case is not related to path params, it's related to capturing the tenant ID associated with the request. And tenant IDs are guaranteed to form a finite set, although they could be like a thousand or so. Are you saying that even this use case is bad practice?

Copy link
Contributor

@brunobat brunobat May 15, 2025

Choose a reason for hiding this comment

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

Yes. It must not be used like that.
It will blow the dimensions exponentially. Remember that for each tenant id you will have also different metrics per endpoint, response status and method.
Place that data in the span and later query the APM's span attributes and/or correlate with exemplars.

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

Labels

area/metrics kind/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow access to context locals from HttpServerMetricsTagsContributor

5 participants