Open nikb1tamerfdp opened 6 days ago
Thanks for the report.
I ran the code with ObservationTextPublisher
, and here are the trimmed outputs for the observation lifecycle:
With spring.jpa.open-in-view=true
(default)
START - name='http.server.requests'
OPEN - name='http.server.requests'
START - name='graphql.request'
START - name='graphql.datafetcher'
OPEN - name='graphql.datafetcher'
... my.issue.controllers.BooksController : Trying to retrieve book with ID 'book-1'.
START - name='jdbc.connection'
OPEN - name='jdbc.connection'
EVENT - CONNECTION_ACQUIRED
START - name='jdbc.query'
OPEN - name='jdbc.query'
STOP - name='jdbc.query'
CLOSE - name='jdbc.query'
START - name='jdbc.result-set'
OPEN - name='jdbc.result-set'
STOP - name='jdbc.result-set'
CLOSE - name='jdbc.result-set'
EVENT - CONNECTION_COMMIT
... Observation <name=http.server.requests(null),... <=== WARNING
CLOSE - name='jdbc.connection'
STOP - name='graphql.datafetcher'
STOP - name='graphql.request'
STOP - name='jdbc.connection'
CLOSE - name='jdbc.connection'
CLOSE - name='http.server.requests'
STOP - name='http.server.requests'
With spring.jpa.open-in-view=false
:
START - name='http.server.requests'
OPEN - name='http.server.requests'
START - name='graphql.request'
START - name='graphql.datafetcher'
OPEN - name='graphql.datafetcher'
... my.issue.controllers.BooksController : Trying to retrieve book with ID 'book
START - name='jdbc.connection'
OPEN - name='jdbc.connection'
EVENT - CONNECTION_ACQUIRED
START - name='jdbc.query'
OPEN - name='jdbc.query'
STOP - name='jdbc.query'
CLOSE - name='jdbc.query'
START - name='jdbc.result-set'
OPEN - name='jdbc.result-set'
STOP - name='jdbc.result-set'
CLOSE - name='jdbc.result-set'
EVENT - CONNECTION_COMMIT
STOP - name='jdbc.connection'
CLOSE - name='jdbc.connection'
CLOSE - name='graphql.datafetcher'
STOP - name='graphql.datafetcher'
STOP - name='graphql.request'
CLOSE - name='http.server.requests'
STOP - name='http.server.requests'
With spring.jpa.open-in-view=true
(default), it delays closing the entity manager, which means the JDBC connection remains open for lazy-loading entities in the view.
As the output shows, observations start in the order of http.server.requests
-> graphql.request
-> graphql.datafetcher
-> jdbc.connection
-> ...
The observations should stop in the reverse order, but due to the open session in view pattern, jdbc.connection
stops after graphql.datafetcher
and graphql.request
.
I think this may be causing the ObservationThreadLocalAccessor
to print out the WARN log.
Though, I'm not sure what would be a solution here. At DataSource
level observation is started/stopped when JDBC connection is acquired and closed. At spring controller level, an observation is started/closed based on the http request lifecycle. The open-session/entity-manger-in-view pattern kinds of breaking the way they are invoked.
@bclozel I also noticed from the output that the graphql.datafetcher
observation is not CLOSED
when open-in-view is enabled. Could it be related?
@ttddyy I'm not familiar with the difference between CLOSE
and STOP
. From an instrumentation perspective, GraphQlObservationInstrumentation
is always calling observation.stop()
and the context decorator is always wrapping the execution as it should for context propagation.
The context
In my application (Spring Boot
3.2.6
), I'm using the GraphQL, Web and JPA starters. I have created a GraphQL controller, in which I interact with a JPA repository. I have also enabled observability with Micrometer.The issue
When I query my controller, everything executes successfully, but I can find this log line (formatted for clarity purpose) :
When I connect my application to an Open Telemetry with a Jaeger backend, just to check if everything is ok in terms of trace and spans, it seems that yeah, everything is ok :![Issue - Jaeger](https://github.com/spring-projects/spring-boot/assets/15066513/daecce37-a5f0-4cc7-a3ba-6fc8deb80374)
This log is not generated if I remove interaction with my JPA repository. It's also not generated if I annotate the method of my controller (the one annotated with
@QueryMapping
) with@Observed
, or if I set the propertyspring.jpa.open-in-view
tofalse
(something I prefer not to do).How to reproduce
You can find a sample application right here.
You can query the controller with these information :
http://localhost:8080/graphql
Additional comments
In the original ticket that I've created on Spring Boot project side, @bclozel added this comment, maybe it can give more info :