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

ObservationProxyExecutionListener + virtual threads = 💥 #149

Open
cfredri4 opened this issue Jul 2, 2024 · 2 comments · May be fixed by #150
Open

ObservationProxyExecutionListener + virtual threads = 💥 #149

cfredri4 opened this issue Jul 2, 2024 · 2 comments · May be fixed by #150

Comments

@cfredri4
Copy link

cfredri4 commented Jul 2, 2024

Thread name is a low cardinality key but with virtual threads there are millions of threads which leads to e.g. prometheus going 💥.

@cfredri4 cfredri4 linked a pull request Jul 2, 2024 that will close this issue
@ttddyy
Copy link
Member

ttddyy commented Jul 5, 2024

Thanks for the report.

To work around this issue, you can create a custom convention that does not record the thread name, or use an observation filter to remove the thread name tag.

Here’s an example of how you can create a custom convention:

public interface SimpleQueryObservationConvention extends QueryObservationConvention {

    @Override
    default KeyValues getLowCardinalityKeyValues(QueryContext context) {
        Set<KeyValue> keyValues = new HashSet<>();
        keyValues.add(KeyValue.of(R2dbcObservationDocumentation.LowCardinalityKeys.CONNECTION, context.getConnectionName()));
        return KeyValues.of(keyValues);
    }

}

And here’s an example of an observation filter:

public class MyObservationFilter implements ObservationFilter {

    @Override
    public Observation.Context map(Observation.Context context) {
        if (context instanceof QueryContext) {
            context.remove(R2dbcObservationDocumentation.LowCardinalityKeys.THREAD.asString());
        }
        return context;
    }
}

I will likely add this custom convention implementation to the library, allowing users to choose between the default or this custom convention.

If you are using Spring Boot, defining a convention or observation filter bean should be automatically picked up, if I remember correctly.

@cfredri4
Copy link
Author

cfredri4 commented Jul 6, 2024

Thank you, this is what I'm doing now.
But I opened the issue as I believe the behavior should be reversed; the safest behavior that will always work would be for thread name to not be included, and then it instead can be added as an option if you know you have a low number of threads.

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

Successfully merging a pull request may close this issue.

2 participants