Skip to content

Implementation of SingleEntityExecution generates false-positives when used with opentelemetry instrumentation #3633

@hanswesterbeek

Description

@hanswesterbeek

Hi,

Spring-data-jpa's use of Hibernate's getSingleResult often causes Hibernate to throw a NoResultException internally, which causes the otel-hibernate intrumentation module to flag the span as a failure, and recording the stacktrace in the Span and flagging it as 'error'.

This leads to false-positives especially when the Spring-data method returns an Optional, eg Optional<Foo> findByBar.

Clearly this issue exists at a crossroads between otel, spring-data and jpa. I think it is best reported here because I can kind of see that alternative Hibernate APIs like Optional<R> uniqueResultOptional() and R getSingleResultOrNull() exist on org.hibernate.query.SelectionQuery interface, which I hope can be used. That wouldn't set off the otel-instrumentation.

A fix doesn't seem trivial to me because jakarta.persistence.Query::getSingleResult doesn't have the right method and that is probably the interface spring-data has to talk to preserve compatibility with other jpa-providers. Happy to provide a PR if your team believes it possible and provide me with a few pointers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions