/** * Constructor * * @param ip Int representation of ipv4 address. * @param port port on which current process is listening. * @param serviceName Name of the local service being traced. Should be lowercase and not <code>null</code> or empty. */ public ThreadLocalServerClientAndLocalSpanState(int ip, int port, String serviceName) { Util.checkNotBlank(serviceName, "Service name must be specified."); endpoint = Endpoint.create(serviceName, ip, port); }
/** * Constructor * * @param ip InetAddress of current host. If you don't have access to InetAddress you can use InetAddressUtilities#getLocalHostLANAddress() * @param port port on which current process is listening. * @param serviceName Name of the local service being traced. Should be lowercase and not <code>null</code> or empty. * @deprecated Please switch to constructor that takes 'int' for ip. This only does a conversion from the InetAddress to integer anyway * and using InetAddress can result in ns lookup and nasty side effects. */ @Deprecated public ThreadLocalServerClientAndLocalSpanState(InetAddress ip, int port, String serviceName) { Util.checkNotNull(ip, "ip address must be specified."); Util.checkNotBlank(serviceName, "Service name must be specified."); endpoint = Endpoint.create(serviceName, InetAddressUtilities.toInt(ip), port); }
private void endTrace(HttpServletRequest req, Span span, Stopwatch watch) { // ss annotation span.addToAnnotations( Annotation.create(Times.currentMicros(), TraceConstants.ANNO_SS, Endpoint.create(span.getName(), ServerInfo.IP4, req.getLocalPort()))); span.setDuration(watch.stop().elapsed(TimeUnit.MICROSECONDS)); // send trace spans agent.send(TraceContext.getSpans()); }
/** * Internal api for submitting an address. Until a naming function is added, this coerces null * {@code serviceName} to "unknown", as that's zipkin's convention. * * @param ipv4 ipv4 host address as int. Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 * @param port Port for service * @param serviceName Name of service. Should be lowercase and not empty. {@code null} will coerce to "unknown", as that's zipkin's convention. */ void submitAddress(String key, int ipv4, int port, @Nullable String serviceName) { Span span = spanAndEndpoint().span(); if (span != null) { serviceName = serviceName != null ? serviceName : "unknown"; Endpoint endpoint = Endpoint.create(serviceName, ipv4, port); BinaryAnnotation ba = BinaryAnnotation.address(key, endpoint); addBinaryAnnotation(span, ba); } }
@Override public Endpoint serverAddress() { InetSocketAddress inetSocketAddress = RpcContext.getContext().getRemoteAddress(); String ipAddr = RpcContext.getContext().getUrl().getIp(); String serverName = serverNameProvider.resolveServerName(RpcContext.getContext()); return Endpoint.create(serverName, IPConversion.convertToInt(ipAddr),inetSocketAddress.getPort()); }
private void endTrace(Invoker invoker, Result result, Span consumeSpan, Stopwatch watch) { consumeSpan.setDuration(watch.stop().elapsed(TimeUnit.MICROSECONDS)); // cr annotation URL provider = invoker.getUrl(); consumeSpan.addToAnnotations( Annotation.create(Times.currentMicros(), TraceConstants.ANNO_CR, Endpoint.create(consumeSpan.getName(), Networks.ip2Num(provider.getHost()), provider.getPort()))); // exception catch Throwable throwable = result.getException(); if (throwable != null){ // attach exception consumeSpan.addToBinary_annotations(BinaryAnnotation.create( "Exception", Throwables.getStackTraceAsString(throwable), null )); } // collect the span TraceContext.addSpan(consumeSpan); } }
consumeSpan.addToAnnotations( Annotation.create(timestamp, TraceConstants.ANNO_CS, Endpoint.create(serviceName, providerHost, providerPort)));
private Span startTrace(HttpServletRequest req, TracePoint point) { String apiName = req.getRequestURI(); Span apiSpan = new Span(); // span basic data long id = Ids.get(); apiSpan.setId(id); apiSpan.setTrace_id(id); apiSpan.setName(point.getKey()); long timestamp = Times.currentMicros(); apiSpan.setTimestamp(timestamp); // sr annotation apiSpan.addToAnnotations( Annotation.create(timestamp, TraceConstants.ANNO_SR, Endpoint.create(apiName, ServerInfo.IP4, req.getLocalPort()))); // app name apiSpan.addToBinary_annotations(BinaryAnnotation.create( "name", conf.getName(), null )); // app owner apiSpan.addToBinary_annotations(BinaryAnnotation.create( "owner", conf.getOwner(), null )); // trace desc if (!Strings.isNullOrEmpty(point.getDesc())){ apiSpan.addToBinary_annotations(BinaryAnnotation.create( "description", point.getDesc(), null )); } return apiSpan; }