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

Always check if valid span returned from HttpClientTracer.startSpan #904

Closed
trask opened this issue Aug 6, 2020 · 6 comments
Closed

Always check if valid span returned from HttpClientTracer.startSpan #904

trask opened this issue Aug 6, 2020 · 6 comments

Comments

@trask
Copy link
Member

trask commented Aug 6, 2020

We need to check everywhere if the span returned from TRACER.startSpan() is invalid before starting a scope with it.

Tracking issue for #893 (review)

Relates to #465

@anuraaga
Copy link
Contributor

anuraaga commented Aug 6, 2020

Should we automatically return a no-op scope when starting one with invalid span?

@anuraaga
Copy link
Contributor

anuraaga commented Aug 6, 2020

@trask
Copy link
Member Author

trask commented Aug 6, 2020

#893 revealed a few places that complicate things, in particular where we can't(?) do context injection inside of our TRACER.startSpan() (a couple examples below)

i sort of like the idea of having a consistent template (e.g. check isValid everywhere) vs checking isValid in some cases but not in others.

but i'm also concerned about the growing size of our "consistent template"

      callDepth = TRACER.getCallDepth();
      if (callDepth.getAndIncrement() == 0) {
        span = TRACER.startSpan(request);

        Context context = withSpan(span, Context.current());
        if (request != null) {
          AkkaHttpHeaders headers = new AkkaHttpHeaders(request);
          OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, request, headers);
          // Request is immutable, so we have to assign new value once we update headers
          request = headers.getRequest();
        }
        scope = withScopedContext(context);
      }
    Span span = TRACER.startSpan(chain.request());
    Context context = withSpan(span, Context.current());
    Request.Builder requestBuilder = chain.request().newBuilder();
    OpenTelemetry.getPropagators()
        .getHttpTextFormat()
        .inject(context, requestBuilder, RequestBuilderInjectAdapter.SETTER);

    Response response;
    try (Scope scope = withScopedContext(context)) {
      response = chain.proceed(requestBuilder.build());
    } catch (final Exception e) {
      TRACER.endExceptionally(span, e);
      throw e;
    }
    TRACER.end(span, response);
    return response;

@anuraaga
Copy link
Contributor

anuraaga commented Aug 6, 2020

Since injection should also be no-op for an invalid span, it looks like these work OK even if the span is invalid. There's a bit of overhead though due to the execution of the no-op methods but I guess it keeps things simple?

@trask
Copy link
Member Author

trask commented Aug 6, 2020

this is a really good point 👍

@trask
Copy link
Member Author

trask commented Aug 16, 2020

Closing, agree with @anuraaga's point above, and we can optimize as needed (in particular see #1009)

@trask trask closed this as completed Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants