public void onStart()

in evcache-zipkin-tracing/src/main/java/com/netflix/evcache/EVCacheTracingEventListener.java [35:112]


  public void onStart(EVCacheEvent e) {
    try {
      Span clientSpan =
          this.tracer.nextSpan().kind(Span.Kind.CLIENT).name(EVCACHE_SPAN_NAME).start();

      // Return if tracing has been disabled
      if(clientSpan.isNoop()){
        return;
      }

      String appName = e.getAppName();
      this.safeTag(clientSpan, EVCacheTracingTags.APP_NAME, appName);

      String cacheNamePrefix = e.getCacheName();
      this.safeTag(clientSpan, EVCacheTracingTags.CACHE_NAME_PREFIX, cacheNamePrefix);

      String call = e.getCall().name();
      this.safeTag(clientSpan, EVCacheTracingTags.CALL, call);

      /**
       * Note - e.getClients() returns a list of clients associated with the EVCacheEvent.
       *
       * <p>Read operation will have only 1 EVCacheClient as reading from just 1 instance of cache
       * is sufficient. Write operations will have appropriate number of clients as each client will
       * attempt to write to its cache instance.
       */
      String serverGroup;
      List<String> serverGroups = new ArrayList<>();
      for (EVCacheClient client : e.getClients()) {
        serverGroup = client.getServerGroupName();
        if (StringUtils.isNotBlank(serverGroup)) {
          serverGroups.add("\"" + serverGroup + "\"");
        }
      }
      clientSpan.tag(EVCacheTracingTags.SERVER_GROUPS, serverGroups.stream().collect(Collectors.joining(",", "[", "]")));

      /**
       * Note - EVCache client creates a hash key if the given canonical key size exceeds 255
       * characters.
       *
       * <p>There have been cases where canonical key size exceeded few megabytes. As caching client
       * creates a hash of such canonical keys and optimizes the storage in the cache servers, it is
       * safe to annotate hash key instead of canonical key in such cases.
       */
      String hashKey;
      List<String> hashKeys = new ArrayList<>();
      List<String> canonicalKeys = new ArrayList<>();
      for (EVCacheKey keyObj : e.getEVCacheKeys()) {
        hashKey = keyObj.getHashKey();
        if (StringUtils.isNotBlank(hashKey)) {
          hashKeys.add("\"" + hashKey + "\"");
        } else {
          canonicalKeys.add("\"" + keyObj.getCanonicalKey() + "\"");
        }
      }

      if(hashKeys.size() > 0) {
        this.safeTag(clientSpan, EVCacheTracingTags.HASH_KEYS,
                hashKeys.stream().collect(Collectors.joining(",", "[", "]")));
      }

      if(canonicalKeys.size() > 0) {
        this.safeTag(clientSpan, EVCacheTracingTags.CANONICAL_KEYS,
                canonicalKeys.stream().collect(Collectors.joining(",", "[", "]")));
      }

      /**
       * Note - tracer.spanInScope(...) method stores Spans in the thread local object.
       *
       * <p>As EVCache write operations are asynchronous and quorum based, we are avoiding attaching
       * clientSpan with tracer.spanInScope(...) method. Instead, we are storing the clientSpan as
       * an object in the EVCacheEvent's attributes.
       */
      e.setAttribute(CLIENT_SPAN_ATTRIBUTE_KEY, clientSpan);
    } catch (Exception exception) {
      logger.error("onStart exception", exception);
    }
  }