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

Custom metadata in transaction #2964

Open
abccbaandy opened this issue Nov 6, 2024 · 6 comments
Open

Custom metadata in transaction #2964

abccbaandy opened this issue Nov 6, 2024 · 6 comments
Assignees
Labels
status: feedback-provided Feedback has been provided

Comments

@abccbaandy
Copy link

Now it's hard code the UserAgent only

.withMetadata(Collections.singletonMap("app", UserAgent.INSTANCE.toString()))

It will be more useful have some convent way to add custom info.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 6, 2024
@meistermeier meistermeier self-assigned this Nov 8, 2024
@meistermeier
Copy link
Collaborator

Thanks for the suggestion. Do you really mean to add custom info and not to overwrite the app value?
I would like to know first the use case and how you intend to provide those informations. Although it is technical possible to provide this information (at least my assumption after having a glance), I don't know yet why this might be useful.
The only place where you can see this is the query log on the server side. Also, please keep in mind that this can only be achieved via some kind of callback to a transaction manager metadata source that would get invoked for every transaction.

@meistermeier meistermeier added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 8, 2024
@abccbaandy
Copy link
Author

abccbaandy commented Nov 9, 2024

Thanks for quick reply.

My use case is : Audit log via Change data capture (CDC).
I want put some user metadata there, so I can track who did the change/where the change happen.
For the user metadata, field will have user ip, user name, user client app version...etc, those will get from request header/body in our api. I think this part will be fine if the metadata implement allow us to access spring bean.

Do you really mean to add custom info and not to overwrite the app value?

About add or overwrite, I think we are fine with some spring way via a provider interface with a default impl to let user to choose if they want overwrite the metadata totally or just add some custom info.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 9, 2024
@meistermeier
Copy link
Collaborator

This makes sense. But I want to add that overriding the app fields will be something that we don't want to enable.
It's important for us to keep this the way it is. Mostly because we see customers/users approaching us with their problems/questions and we need those information to be present. Even if we would warn them, they would change it nevertheless and than we are missing important bits.

@abccbaandy
Copy link
Author

I get it, we want add those metadata for the same reason.

But I have to say, as a lib/framework, there is no way to prevent the developer to do anything.
I can call tx.setMetaData to override the app field without any issue.

Anyways, you can provide a way to add metadata only, it can prevent misuse this feature.

@meistermeier
Copy link
Collaborator

But for this you would need to get a handle on the transaction object that is currently in use by the Spring transaction. Which is by far less convenient than having a supplier that allows the overwrite of the app field. Just want to ensure that there is no way this might happen accidentally.

@abccbaandy
Copy link
Author

Ya, this is why I open this issue.

Hope we can have a convenient and reliable way to ADD metadata soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

3 participants