Can you check object's state using sleuth? - spring

I am trying to figure out if I can trace some objects fields using sleuth.
I am currently lost in Zipkin's and Sleuth's docs. Does anybody do this?
Can we add an object to span and view its details in logs?

You can only do that just before the span gets reported. You can't check its details at runtime.

Related

How to add same prefix to all LOGS in request in SpringBoot project

I use #Slf4j to add logs in all layers in my SpringBoot project.
I want to use some unque ID for all logs inside onq request.
For example generate UUID at the RestController and automatic add it to every logs in this thread
For example
[..... Some UUID ....] "The real logger message"
How to do this?
It need to have possibility to filter all logs of specific request.
If your application is threaded (or any better word to describe "opposed to a reactive application where it might be possible that everything happens in the main thread"), use the mapped diagnostic context (MDC). The MDC is a thread-bound Key-Value Map, where you can put and retrieve data. Baeldung has a tutorial on logging with the mdc using multiple logging frameworks. Also, there are plenty of examples across the web.
If your application should be reactive, you may wanna check out this project reactor reference.

Disable setting up Audit fields in create/update requests in Spring Data REST

I'm using combination of various Spring components - Boot (2.3), Data, Data REST, Springdoc. In my model objects I use auditing - I annotate some fields with #CreatedBy, #CreatedDate etc. I would like to disable possibility to set value of those audit fields through REST API. At the same time, I want this information to be available when retrieving data.
Seems like quite obvious thing to do, but I'm unable to find a way to do this. By default I can easily provide those values in API calls and see them persisted.
Ideally, such configuration change would be visible also in OpenAPI spec generated by Springdoc (in model of request).
So it turns out that I'm silly :)
So my error was that authentication and authorization was disabled at that time. Once enabled, I wasn't able to provide values for createdBy and other fields as they were just getting overridden with correct values.
When it comes to OpenAPI specification, I had to annotate fields with:
#Schema(accessMode = Schema.AccessMode.READ_ONLY)
from io.swagger.v3.oas.annotations.media.Schema;. This resulted in correct info. See Swagger view:
I guess the problem comes from your bad design. Please consider your design is correct or not. I guess in your design, besides Spring Data REST endpoints (APIs), there are other code which can create and update your object and save to database.
You question has nothing to do with Spring Data REST. Audit fields annotated with #Createdxx and #LastModifiedxx is auto updated by Spring Data repository, and Spring Data REST just calls the Spring Data repository to persist data.
Answer below two questions helps clarify your design.
Question 1:
If you want to keep create (POST) endpoints which are created by Spring Data REST by default, and you don't want audit fields annotated with #Createdxx to be set, then what code is responsible to set those audit fields?
Assume you send a POST request to create an object, do you want createdBy and createdDate to be null? Or would createdBy and createdDate be updated later by other code?
Question 2:
If you want to keep update (PUT/PATCH) endpoints which are created by Spring Data REST by default, and you don't want audit fields annotated with #LastModifiedxx to be updated, then what code is responsible to update those audit fields? And this also results in imcomplete audit (you make update, but lastModified info not updated).

Persisting Spring stateMachine in Database

I understand that this question might be repeated but seems like previous answers are not adequate to provide clarity.
I want to save statemachine into database and rebuild statemachine using previously persisted stage.
My application is in Sprinng boot with JPA.
If I get any sample example that would be great.
There is a JpaStateMachineRuntimePersister that you can use.
Scroll all the way down to the bottom of the reference doc and you will find the link to:
https://docs.spring.io/spring-statemachine/docs/current/reference/

How to add the request info in raven java with logback?

We are using raven with logback in java and sentry for error reporting. We can successfully log errors but how can we add the request info?
I have not found any example on https://docs.getsentry.com/hosted/clients/java/modules/logback/
You can use MDC or marker in slf4j, here's the link of example from sentry: https://docs.sentry.io/clients/java/modules/logback/. Please check Mapped Tags.
You can specify MDC keys to send as tags instead of including them in Additional Data. This allows them to be filtered within Sentry.

How to set disableUISecurity property

I am trying to apply spring security to my web application. I am already familiar on the usage of the security:authorize tag for hiding UI elements in my jsp page. I read that starting from spring security 3.1.x you now have spring.security.disableUISecurity property to disable the security:authorize tag which will really help our testing. I tried searching google on how to set this property but I couldn't find a clear way on how to set this property. Does anyone know how to configure this property?
I asked this question over at spring forums and someone was able to help me. You just need to add -Dspring.security.disableUISecurity=true as a jvm parameter
Link to the post at spring

Resources