/** * @return If this endpoint's ip is 0.0.0.0 or 127.0.0.1 we get the local host and return that. */ static Endpoint boundEndpoint(Endpoint endpoint) { if (endpoint.ipv4 == UNKNOWN.ipv4 || endpoint.ipv4 == LOOPBACK.ipv4) { return endpoint.toBuilder().ipv6(LOCAL.ipv6).ipv4(LOCAL.ipv4).build(); } else { return endpoint; } } }
synchronized Span toSpan() { // fill in the host/service data for all the annotations for (Annotation ann : annotations) { Endpoint ep = Endpoints.boundEndpoint(ann.endpoint); span.addAnnotation( ann.toBuilder().endpoint(ep.toBuilder().serviceName(service).build()).build()); } for (BinaryAnnotation ann : binaryAnnotations) { Endpoint ep = Endpoints.boundEndpoint(ann.endpoint); // TODO: service name for "ca" or "sa" is likely incorrect span.addBinaryAnnotation( ann.toBuilder().endpoint(ep.toBuilder().serviceName(service).build()).build()); } return span.build(); }
@Override public Set<String> partitionKeys(Span span) { return span.serviceNames(); } }
static zipkin.Endpoint toEndpoint(Endpoint input) { zipkin.Endpoint.Builder result = zipkin.Endpoint.builder() .serviceName(input.serviceName() != null ? input.serviceName() : "") .port(input.port() != null ? input.port() : 0); if (input.ipv6() != null) { result.parseIp(input.ipv6()); // parse first in case there's a mapped IP } if (input.ipv4() != null) { result.parseIp(input.ipv4()); } return result.build(); } }
private Endpoint endpoint(Record a) { String serviceName = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); if (serviceName == null) return null; return Endpoint.builder() .serviceName(serviceName) .port(a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT)) .ipv4(a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4)) .ipv6(maybeGet(a, ZIPKIN_ANNOTATIONS.ENDPOINT_IPV6, null)).build(); }
/** * @return If possible, convert from a SocketAddress object to an Endpoint. If not, return Unknown * Endpoint. */ static Endpoint fromSocketAddress(SocketAddress socketAddress) { if (socketAddress instanceof InetSocketAddress) { Endpoint.Builder builder = Endpoint.builder().serviceName(""); InetSocketAddress inet = (InetSocketAddress) socketAddress; builder.parseIp(inet.getAddress()); builder.port(inet.getPort()); return builder.build(); } return UNKNOWN; }
protected void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
/** * Kitchen-sink constructor that lets you set all the options. * * @param serviceName The name of this service. This is used to build the Zipkin {@link Endpoint} that will be used for client/server/local * Zipkin annotations when sending spans to Zipkin. * @param localComponentNamespace The {@link zipkin.Constants#LOCAL_COMPONENT} namespace that should be used when creating certain Zipkin * annotations when the Wingtips span's {@link Span#getSpanPurpose()} is * {@link com.nike.wingtips.Span.SpanPurpose#LOCAL_ONLY}. See the {@link zipkin.Constants#LOCAL_COMPONENT} * javadocs for more information on what this is and how it's used by the Zipkin server, so you know * what value you should send. * @param zipkinSpanConverter The {@link WingtipsToZipkinSpanConverter} that should be used to convert Wingtips spans to Zipkin spans. * @param zipkinSpanSender The {@link ZipkinSpanSender} for collecting and sending Zipkin spans to the Zipkin server. */ public WingtipsToZipkinLifecycleListener(String serviceName, String localComponentNamespace, WingtipsToZipkinSpanConverter zipkinSpanConverter, ZipkinSpanSender zipkinSpanSender) { this.serviceName = serviceName; this.localComponentNamespace = localComponentNamespace; this.zipkinEndpoint = Endpoint.builder().serviceName(serviceName).build(); this.zipkinSpanConverter = zipkinSpanConverter; this.zipkinSpanSender = zipkinSpanSender; }
@Override protected AsyncSpanConsumer compute() { AsyncSpanConsumer result = storage.asyncSpanConsumer(sampler, metrics); return checkNotNull(result, storage + ".asyncSpanConsumer()"); } });
synchronized MutableSpan setName(String n) { span.name(n); return this; }
synchronized MutableSpan addBinaryAnnotation(String key, byte[] value, BinaryAnnotation.Type type) { binaryAnnotations.add(BinaryAnnotation.create(key, value, type, endpoint)); return this; }
/** * Sets the endpoint in the span for any future annotations. Also sets the endpoint in any * previous annotations that lack one. */ synchronized MutableSpan setEndpoint(Endpoint endpoint) { for (int i = 0; i < annotations.size(); i++) { Annotation a = annotations.get(i); if (a.endpoint.equals(Endpoints.UNKNOWN)) { annotations.set(i, a.toBuilder().endpoint(endpoint).build()); } } this.endpoint = endpoint; return this; }
@Override public int compare(List<Span> left, List<Span> right) { return right.get(0).compareTo(left.get(0)); } });
@Override public AsyncSpanConsumer asyncSpanConsumer(CollectorSampler sampler, CollectorMetrics metrics) { return makeSampled(asyncSpanConsumer, sampler, metrics); }
@Override public void onFailure(Throwable throwable) { delegate.onError(throwable); }
@Override public void onSuccess(T t) { delegate.onSuccess(t); }
protected void addAllAnnotationsToBuilder( zipkin.Span.Builder builder, List<TimestampedAnnotation> wingtipsAnnotations, Endpoint zipkinEndpoint ) { for (TimestampedAnnotation wingtipsAnnotation : wingtipsAnnotations) { builder.addAnnotation( Annotation.create( wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue(), zipkinEndpoint ) ); } }
/** * Kitchen-sink constructor that lets you set all the options. * * @param serviceName The name of this service. This is used to build the Zipkin {@link Endpoint} that will be used for client/server/local * Zipkin annotations when sending spans to Zipkin. * @param localComponentNamespace The {@link zipkin.Constants#LOCAL_COMPONENT} namespace that should be used when creating certain Zipkin * annotations when the Wingtips span's {@link Span#getSpanPurpose()} is * {@link com.nike.wingtips.Span.SpanPurpose#LOCAL_ONLY}. See the {@link zipkin.Constants#LOCAL_COMPONENT} * javadocs for more information on what this is and how it's used by the Zipkin server, so you know * what value you should send. * @param zipkinSpanConverter The {@link WingtipsToZipkinSpanConverter} that should be used to convert Wingtips spans to Zipkin spans. * @param zipkinSpanSender The {@link ZipkinSpanSender} for collecting and sending Zipkin spans to the Zipkin server. */ public WingtipsToZipkinLifecycleListener(String serviceName, String localComponentNamespace, WingtipsToZipkinSpanConverter zipkinSpanConverter, ZipkinSpanSender zipkinSpanSender) { this.serviceName = serviceName; this.localComponentNamespace = localComponentNamespace; this.zipkinEndpoint = Endpoint.builder().serviceName(serviceName).build(); this.zipkinSpanConverter = zipkinSpanConverter; this.zipkinSpanSender = zipkinSpanSender; }
@Override protected AsyncSpanConsumer compute() { AsyncSpanConsumer result = storage.asyncSpanConsumer(sampler, metrics); return checkNotNull(result, storage + ".asyncSpanConsumer()"); } });