/** * @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; }
@Override public Endpoint fromJson(JsonReader reader) throws IOException { Endpoint.Builder result = Endpoint.builder().serviceName(""); reader.beginObject(); while (reader.hasNext()) { String nextName = reader.nextName(); if (reader.peek() == JsonReader.Token.NULL) { reader.skipValue(); continue; } switch (nextName) { case "serviceName": result.serviceName(reader.nextString()); break; case "ipv4": case "ipv6": result.parseIp(reader.nextString()); break; case "port": result.port(reader.nextInt()); break; default: reader.skipValue(); } } reader.endObject(); return result.build(); }
/** * 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; }
/** * 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; }
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(); }
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(); }