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

Working XRayUDPReporter and STORAGE_TYPE xray #56

Merged
merged 1 commit into from
Oct 17, 2017
Merged

Conversation

codefromthecrypt
Copy link
Member

@codefromthecrypt codefromthecrypt commented Oct 11, 2017

from openzipkin/brave#510

This adds XRayUDPReporter which defaults to localhost:2000 or
AWS_XRAY_DAEMON_ADDRESS. This can be used in applications directly or
integrated with a zipkin-server where STORAGE_TYPE=xray

Note: this is experimental and makes assumptions about trace ID format:
See openzipkin/b3-propagation#6

@cemo
Copy link
Contributor

cemo commented Oct 12, 2017

@adriancole Any time to merge this and cut a release? :) We are eager to test it with brave.

@codefromthecrypt
Copy link
Member Author

this needs some work first, and I don't want to release it until openzipkin/brave#514 is in.. likely early next week depending on feedback.

@codefromthecrypt
Copy link
Member Author

Brave 4.9 is going out now, which I've tested this with, but obviously this code needs polish and unit tests etc. I'll work on that tomorrow and meanwhile the impatient can copy/paste their class into their project.

Here's the docs on the propagation part: https://github.com/openzipkin/brave/tree/master/propagation/aws#brave-propagation-aws

@cemo
Copy link
Contributor

cemo commented Oct 16, 2017

@adriancole I am in the process integrating. I was building Xray branch and the only minor issue I have seen so far is that

  XRayUDPReporter() {
    this(InetAddress.getLoopbackAddress(), 2000);
  }

Animal Sniffer is complaining about this which after 1.6. It might be experimental codes? I changed <main.signature.artifact>java17</main.signature.artifact> for a quick fix.

I will let you now for further information.

@cemo
Copy link
Contributor

cemo commented Oct 16, 2017

@adriancole are you using X-Ray daemon? What do you recommend?

@cemo
Copy link
Contributor

cemo commented Oct 16, 2017

By the way :)

image

This adds `XRayUDPReporter` which defaults to localhost:2000 or
AWS_XRAY_DAEMON_ADDRESS. This can be used in applications directly or
integrated with a zipkin-server where `STORAGE_TYPE=xray`

Note: this is experimental and makes assumptions about trace ID format:
See openzipkin/b3-propagation#6
@codefromthecrypt codefromthecrypt changed the title WIP XRay Reporter Working XRayUDPReporter and STORAGE_TYPE xray Oct 17, 2017
@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented Oct 17, 2017

OK I have this working, tested with AWS Lambda and outside as well.

Ex: here's an AWS lambda decorator:

package zipkin.lambda;

import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.aws.AWSPropagation;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import zipkin2.reporter.xray_udp.XRayUDPReporter;

public abstract class TracingRequestHandler<I, O> implements RequestHandler<I, O> {
  final Tracer tracer;

  protected abstract RequestHandler<I, O> delegate();

  TracingRequestHandler(Tracing.Builder builder) {
    this.tracer = builder
        .propagationFactory(AWSPropagation.FACTORY)
        .spanReporter(XRayUDPReporter.create()).build().tracer();
  }

  @Override
  public O handleRequest(I input, Context context) {
    /** Always start lambda functions from the root in the env */
    Span span = tracer.nextSpan(AWSPropagation.extractLambda())
        .name(context.getFunctionName())
        .start();

    try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { // so logging can see trace ID
      return delegate().handleRequest(input, context); // do the actual work
    } catch (RuntimeException | Error e) {
      String message = e.getMessage();
      if (message == null) message = e.getClass().getSimpleName();
      span.tag("error", message); // make sure any error gets into the span before it is finished
      throw e;
    } finally {
      span.finish(); // ensure the span representing this processing completes.
    }
  }
}

Here's spring XML config:

  <bean id="tracing" class="brave.spring.beans.TracingFactoryBean">
    <property name="localServiceName" value="brave-webmvc-example25"/>
    <property name="propagationFactory">
      <util:constant static-field="brave.propagation.aws.AWSPropagation.FACTORY"/>
    </property>
    <property name="spanReporter">
      <bean class="zipkin.reporter.xray_udp.XRayUDPReporter" factory-method="create"/>
    </property>
    <property name="currentTraceContext">
      <bean class="brave.context.log4j12.MDCCurrentTraceContext" factory-method="create"/>
    </property>
  </bean>

I also assembled a server and set STORAGE_TYPE=xray. This allows you to accept spans on zipkin's endpoint and push them to AWS. You need tracers to provision 128-bit epoch prefixed trace IDs for this to work (like Brave 4.9)

@codefromthecrypt
Copy link
Member Author

going to merge and cut a release so folks can try it. tests obviously need backfilling and help appreciated with that

@codefromthecrypt codefromthecrypt merged commit 986d6c1 into master Oct 17, 2017
@cemo
Copy link
Contributor

cemo commented Oct 17, 2017

I tested with new release. It is working. 👍 Thanks for your efforts. This will be a really huge milestone for many people.

Now I will start to integrate into our applications which are running on Kubernetes. I will let you know details.

@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented Oct 17, 2017 via email

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

Successfully merging this pull request may close these issues.

2 participants