ElasticsearchSpanStore implements SpanStore, Traces, ServiceAndSpanNames { @Override public Call<List<Span>> getTrace(String traceId) { traceId = Span.normalizeTraceId(traceId); if (!strictTraceId && traceId.length() == 32) traceId = traceId.substring(16); SearchRequest request = SearchRequest.create(asList(allSpanIndices)).term("traceId", traceId); return search.newCall(request, BodyConverters.SPANS); } ElasticsearchSpanStore(ElasticsearchStorage es); @Override Call<List<List<Span>>> getTraces(QueryRequest request); @Override Call<List<Span>> getTrace(String traceId); @Override Call<List<List<Span>>> getTraces(Iterable<String> traceIds); @Override Call<List<String>> getServiceNames(); @Override Call<List<String>> getRemoteServiceNames(String serviceName); @Override Call<List<String>> getSpanNames(String serviceName); @Override Call<List<DependencyLink>> getDependencies(long endTs, long lookback);  }
@Test void doesntTruncateTraceIdByDefault() throws Exception { server.enqueue(EMPTY_RESPONSE); spanStore.getTrace("48fec942f3e78b893041d36dc43227fd").execute(); assertThat(server.takeRequest().request().contentUtf8()) .contains("\"traceId\":\"48fec942f3e78b893041d36dc43227fd\""); }
@Test void truncatesTraceIdTo16CharsWhenNotStrict() throws Exception { storage.close(); storage = storage.toBuilder().strictTraceId(false).build(); spanStore = new ElasticsearchSpanStore(storage); server.enqueue(EMPTY_RESPONSE); spanStore.getTrace("48fec942f3e78b893041d36dc43227fd").execute(); assertThat(server.takeRequest().request().contentUtf8()) .contains("\"traceId\":\"3041d36dc43227fd\""); }