Refine search
/** * 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; }
static Endpoint endpoint(Record a) { String serviceName = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); if (serviceName == null) { return null; } Short port = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT); return port != null ? Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4), port.intValue()) : Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4)); }
final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer(); Session session = webSocketContainer.connectToServer(new Endpoint() { @Override public void onOpen(Session session, EndpointConfig config) { // session.addMessageHandler( ... ); } }, URI.create("ws://some.uri"));
@Test public void convertWingtipsSpanToZipkinSpan_works_as_expected_for_128_bit_trace_id() { // given String high64Bits = "463ac35c9f6413ad"; String low64Bits = "48485a3953bb6124"; String hex128Bits = high64Bits + low64Bits; String spanName = UUID.randomUUID().toString(); String traceId = hex128Bits; String spanId = low64Bits; long startTimeEpochMicros = Math.abs(random.nextLong()); long durationNanos = Math.abs(random.nextLong()); Endpoint zipkinEndpoint = Endpoint.create(UUID.randomUUID().toString(), 42); String localComponentNamespace = UUID.randomUUID().toString(); Map<String,String> tags = createSingleTagMap(); List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList(); Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null, durationNanos, tags, annotations ); // when zipkin.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint, localComponentNamespace); // then assertThat(zipkinSpan.traceIdHigh).isEqualTo(unsignedLowerHexStringToLong(high64Bits)); assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(low64Bits)); }
/** * @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; } } }
/** * 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; }
long startTimeEpochMicros = Math.abs(random.nextLong()); long durationNanos = Math.abs(random.nextLong()); final Endpoint zipkinEndpoint = Endpoint.create(UUID.randomUUID().toString(), 42); final String localComponentNamespace = UUID.randomUUID().toString(); Map<String,String> tags = createSingleTagMap(); assertThat(ex).isInstanceOf(NumberFormatException.class);
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(); }
/** * @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; }
static Endpoint endpoint(Record a) { String serviceName = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); if (serviceName == null) { return null; } Short port = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT); return port != null ? Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4), port.intValue()) : Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4)); }
final WebSocketContainer client = ContainerProvider.getWebSocketContainer(); final Session session = client.connectToServer(new Endpoint() { @Override public void onOpen(Session session, EndpointConfig EndpointConfig) { try { session.addMessageHandler(new MessageHandler.Whole<String>() { @Override public void onMessage(String message) { System.out.println("### Received: " + message); } }); session.getBasicRemote().sendText("Do or do not, there is no try."); } catch (IOException e) { // do nothing } } @Override public void onClose(Session session, CloseReason closeReason) { System.out.println("### Client session closed: " + closeReason); } }, ClientEndpointConfig.Builder.create().build(), URI.create("ws://echo.websocket.org"));
/** * 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; }
static Endpoint endpoint(Record a) { String serviceName = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); if (serviceName == null) { return null; } Short port = a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_PORT); return port != null ? Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4), port.intValue()) : Endpoint.create(serviceName, a.getValue(ZIPKIN_ANNOTATIONS.ENDPOINT_IPV4)); }
); ClientManager client = ClientManager.createClient(); try (Session session = client.connectToServer(new Endpoint() {
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(); }
client.connectToServer(new Endpoint() {
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(); } }
@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(); }