private void serializeUser(final User user) { writeFieldName("user"); jw.writeByte(OBJECT_START); writeField("id", user.getId()); writeField("email", user.getEmail()); writeLastField("username", user.getUsername()); jw.writeByte(OBJECT_END); }
public void setUser(String id, String email, String username) { if (!isSampled()) { return; } getContext().getUser().withId(id).withEmail(email).withUsername(username); }
public void copyFrom(TransactionContext other) { response.copyFrom(other.response); request.copyFrom(other.request); user.copyFrom(other.user); }
@Test void testSamplingNone() throws IOException { config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); Transaction transaction = tracerImpl.startTransaction().withType("request"); try (Scope scope = transaction.activateInScope()) { transaction.setUser("1", "jon.doe@example.com", "jondoe"); Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } transaction.end(); } // we do report non-sampled transactions (without the context) assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(0); assertThat(reporter.getFirstTransaction().getContext().getUser().getEmail()).isNull(); assertThat(reporter.getFirstTransaction().getType()).isEqualTo("request"); }
@Override public void resetState() { super.resetState(); custom.clear(); response.resetState(); request.resetState(); user.resetState(); } }
private void serializeContext(final TransactionContext context) { writeFieldName("context"); jw.writeByte(OBJECT_START); if (context.getUser().hasContent()) { serializeUser(context.getUser()); jw.writeByte(COMMA); } serializeRequest(context.getRequest()); serializeResponse(context.getResponse()); // TODO custom context writeFieldName("tags"); final Map<String, String> value = context.getTags(); serializeTags(value); jw.writeByte(OBJECT_END); jw.writeByte(COMMA); }
.withId("99") .withUsername("foo") .withEmail("foo@example.com");
.withId("99") .withUsername("foo") .withEmail("foo@example.com"); return context;