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

Properly return Optional.empty() for current span if there is no current OTel span #8583

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Mar 28, 2024

Description

Resolves #8575

Basically a forward-port of the 3.x fix for the same problem; see the comment there for details. #8574 (comment)

Documentation

But fix; no doc impact

…ent OTel span

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
@tjquinno tjquinno self-assigned this Mar 28, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 28, 2024
@@ -90,10 +97,17 @@ public static Tracer globalTracer() {
* @return optional of the current span
*/
public static Optional<Span> activeSpan() {
// OTel returns a no-op span if there is no current one.
io.opentelemetry.api.trace.Span otelSpan = io.opentelemetry.api.trace.Span.current();
io.opentelemetry.context.Context otelContext = io.opentelemetry.context.Context.current();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this entire method can be just:

return Optional.ofNullable(io.opentelemetry.api.trace.Span.fromContextOrNull(io.opentelemetry.context.Context.current()))
  .map(otelSpan -> HelidonOpenTelemetry.create(otelSpan, io.opentelemetry.api.baggage.Baggage.current());

(Some static imports would make this a little easier, maybe.) What do you think?

@tjquinno tjquinno merged commit 59bde42 into helidon-io:main Mar 28, 2024
12 checks passed
@tjquinno tjquinno deleted the 4.x-otel-current-span branch March 28, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
2 participants