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

TracerProviderHelper#currentSpan() throws NPE in some situations #8254

Closed
tjquinno opened this issue Jan 17, 2024 · 0 comments · Fixed by #8257
Closed

TracerProviderHelper#currentSpan() throws NPE in some situations #8254

tjquinno opened this issue Jan 17, 2024 · 0 comments · Fixed by #8257
Assignees
Labels
3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working P2 tracing
Milestone

Comments

@tjquinno
Copy link
Member

tjquinno commented Jan 17, 2024

Environment Details

  • Helidon Version: 4.x
  • Helidon SE or Helidon MP
  • JDK version:
  • OS:
  • Docker version (if applicable):

Problem Description

In some limited cases, the TracerProviderHelper#currentSpan method throws a NPE because TRACER_PROVIDER is null when currentSpan is invoked.

In at least two situations, customer code uses a custom TracerProvider. The static initializer in Helidon's TracerProviderHelper class uses service loading to locate and load such implementations, select one, and store a reference to it in the TRACER_PROVIDER static field.

During its own initialization, that custom TracerProvider uses logging, and there is a custom logger in place which attempts to get the current span (if any) to add to log messages. And the attempt to get the current span ultimately invokes TracerProviderHelper.currentSpan() which depends on TRACER_PROVIDER being non-null.

In this scenario, though, TRACER_PROVIDER is still null because the static initializer has not yet finished. That triggers the NPE.

Although one could argue that the custom TracerProvider should not, even indirectly, invoke code that relies on TRACER_PROVIDER being non-null, this use case (and ones like it) would be difficult to untangle. Helidon could be of help to users in these situations by anticipating and dealing with this edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working P2 tracing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant