private void serializeSpanContext(SpanContext context) { writeFieldName("context"); jw.writeByte(OBJECT_START); boolean spanContextWritten = false; Db db = context.getDb(); if (db.hasContent()) { serializeDbContext(db); spanContextWritten = true; } Http http = context.getHttp(); if (http.hasContent()) { if (spanContextWritten) { jw.writeByte(COMMA); } serializeHttpContext(http); spanContextWritten = true; } Map<String, String> tags = context.getTags(); if (!tags.isEmpty()) { if (spanContextWritten) { jw.writeByte(COMMA); } writeFieldName("tags"); serializeTags(tags); } jw.writeByte(OBJECT_END); jw.writeByte(COMMA); }
@Test void resetState() { Span span = new Span(mock(ElasticApmTracer.class)) .withName("SELECT FROM product_types") .withType("db") .withSubtype("postgresql") .withAction("query"); span.getContext().getDb() .withInstance("customers") .withStatement("SELECT * FROM product_types WHERE user_id=?") .withType("sql") .withUser("readonly_user"); span.resetState(); assertThat(span.getContext().hasContent()).isFalse(); assertThat((CharSequence) span.getName()).isNullOrEmpty(); assertThat(span.getType()).isNull(); assertThat(span.getSubtype()).isNull(); assertThat(span.getAction()).isNull(); } }
.withSubtype("postgresql") .withAction("query"); span.getContext().getDb() .withInstance("customers") .withStatement("SELECT * FROM product_types WHERE user_id=?")