SofaTracerSpanContext implements SpanContext { @Override public Iterable<Map.Entry<String, String>> baggageItems() { Map<String, String> allBaggage = new HashMap<String, String>(); if (this.bizBaggage != null && this.bizBaggage.size() > 0) { allBaggage.putAll(this.bizBaggage); } if (this.sysBaggage != null && this.sysBaggage.size() > 0) { allBaggage.putAll(this.sysBaggage); } return allBaggage.entrySet(); } SofaTracerSpanContext();  SofaTracerSpanContext(String traceId, String spanId);  SofaTracerSpanContext(String traceId, String spanId, String parentId);  SofaTracerSpanContext(String traceId, String spanId, String parentId, boolean isSampled); SofaTracerSpanContext cloneInstance(); SofaTracerSpanContext addBizBaggage(Map<String, String> bizBaggage); SofaTracerSpanContext addSysBaggage(Map<String, String> sysBaggage); @Override Iterable<Map.Entry<String, String>> baggageItems(); String getBizSerializedBaggage(); String getSysSerializedBaggage(); void deserializeBizBaggage(String bizBaggageAttrs); void deserializeSysBaggage(String sysBaggageAttrs); String serializeSpanContext(); static SofaTracerSpanContext deserializeFromString(String deserializeValue); static SofaTracerSpanContext rootStart(); static SofaTracerSpanContext rootStart(boolean isSampled); void setTraceId(String traceId); void setSpanId(String spanId); SofaTracerSpanContext setBizBaggageItem(String key, String value); String getBizBaggageItem(String key); SofaTracerSpanContext setSysBaggageItem(String key, String value); String getSysBaggageItem(String key); String getTraceId(); String getSpanId(); String getParentId(); Map<String, String> getBizBaggage(); Map<String, String> getSysBaggage(); boolean isSampled(); void setSampled(boolean sampled); AtomicInteger getChildContextIndex(); String nextChildContextId(); String lastChildContextId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final String RPC_ID_SEPARATOR; }
@Test public void testBaggageItems() throws Exception { SofaTracerSpanContext sofaTracerSpanContext1 = new SofaTracerSpanContext("traceId", "spanId", "parentId", false); Map<String, String> expected = new HashMap<String, String>(); sofaTracerSpanContext1.setBizBaggageItem("baggage1", "value1"); sofaTracerSpanContext1.setBizBaggageItem("baggage2", "value2"); sofaTracerSpanContext1.setSysBaggageItem("sys1", "sysvalue1"); sofaTracerSpanContext1.setSysBaggageItem("sys2", "sysvalue2"); expected.put("baggage1", "value1"); expected.put("baggage2", "value2"); expected.put("sys1", "sysvalue1"); expected.put("sys2", "sysvalue2"); Iterable<Map.Entry<String, String>> entrySet = sofaTracerSpanContext1.baggageItems(); Map<String, String> map = new HashMap<String, String>(); for (Map.Entry<String, String> entry : entrySet) { map.put(entry.getKey(), entry.getValue()); } assertEquals(4, map.size()); assertEquals(expected, map); }