public void setUser(String id, String email, String username) { if (!isSampled()) { return; } getContext().getUser().withId(id).withEmail(email).withUsername(username); }
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); }
@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"); }
.addHeader("content-type", "application/json"); context.getUser() .withId("99") .withUsername("foo")
.addHeader("content-type", "application/json"); context.getUser() .withId("99") .withUsername("foo")