@Test public void emit_WhenZipkinTracingIsNotEnabled_ShouldDisableSamplingForTheEntireRequestChain() { Map<String, String> additionalData = Maps.newHashMap(); Map.Entry<String, String> expectedHeader = new AbstractMap.SimpleEntry<>(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); victim = new ZipkinSocketContextEmitter(compoundContextEmitter); when(ctx.traceLoggingEnabled()).thenReturn(false); when(zipkinRequestUUID.isZipkinTracingEnabled()).thenReturn(false); victim.emit(ctx, additionalData, null); assertEquals(1, additionalData.size()); assertTrue(additionalData.containsKey(expectedHeader.getKey())); assertEquals(additionalData.get(expectedHeader.getKey()), expectedHeader.getValue()); }
@Override public void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore) { RequestUUID requestUUID = ctx.getRequestUUID(); if (requestUUID instanceof ZipkinRequestUUID) { ZipkinRequestUUID zipkinRequestUUID = (ZipkinRequestUUID) requestUUID; if (zipkinRequestUUID.isZipkinTracingEnabled()) { ZipkinData zipkinData = zipkinRequestUUID.getZipkinData(); appendZipkinHeaders(additionalData, zipkinData); } else { additionalData.put(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); } } }
ZipkinSocketContextEmitter implements ContextEmitter<Map<String, String>, C> { @Override public void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore) { RequestUUID requestUUID = ctx.getRequestUUID(); if (requestUUID instanceof ZipkinRequestUUID) { ZipkinRequestUUID zipkinRequestUUID = (ZipkinRequestUUID) requestUUID; if (zipkinRequestUUID.isZipkinTracingEnabled()) { ZipkinData zipkinData = zipkinRequestUUID.getZipkinData(); appendZipkinHeaders(additionalData, zipkinData); } else { additionalData.put(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); } } } }
ZipkinSocketContextEmitter implements ContextEmitter<Map<String, String>, C> { @Override public void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore) { RequestUUID requestUUID = ctx.getRequestUUID(); if (requestUUID instanceof ZipkinRequestUUID) { ZipkinRequestUUID zipkinRequestUUID = (ZipkinRequestUUID) requestUUID; if (zipkinRequestUUID.isZipkinTracingEnabled()) { ZipkinData zipkinData = zipkinRequestUUID.getZipkinData(); appendZipkinHeaders(additionalData, zipkinData); } else { additionalData.put(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); } } } ZipkinSocketContextEmitter(CompoundContextEmitter<Map<String, String>, C> compoundContextEmitter); }
ZipkinSocketContextEmitter implements ContextEmitter<Map<String, String>, C> { @Override public void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore) { RequestUUID requestUUID = ctx.getRequestUUID(); if (requestUUID instanceof ZipkinRequestUUID) { ZipkinRequestUUID zipkinRequestUUID = (ZipkinRequestUUID) requestUUID; if (zipkinRequestUUID.isZipkinTracingEnabled()) { ZipkinData zipkinData = zipkinRequestUUID.getZipkinData(); appendZipkinHeaders(additionalData, zipkinData); } else { additionalData.put(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); } } } ZipkinSocketContextEmitter(CompoundContextEmitter<Map<String, String>, C> compoundContextEmitter); @Override void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore); }
ZipkinSocketContextEmitter implements ContextEmitter<Map<String, String>, C> { @Override public void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore) { RequestUUID requestUUID = ctx.getRequestUUID(); if (requestUUID instanceof ZipkinRequestUUID) { ZipkinRequestUUID zipkinRequestUUID = (ZipkinRequestUUID) requestUUID; if (zipkinRequestUUID.isZipkinTracingEnabled()) { ZipkinData zipkinData = zipkinRequestUUID.getZipkinData(); appendZipkinHeaders(additionalData, zipkinData); } else { additionalData.put(ZipkinKeys.SAMPLED, ZipkinKeys.DO_NOT_SAMPLE_VALUE); } } } ZipkinSocketContextEmitter(CompoundContextEmitter<Map<String, String>, C> compoundContextEmitter); @Override void emit(ClientCallContext ctx, @Nonnull Map<String, String> additionalData, @Nullable C ignore);  }