@Test public void testGetThisAsParentWhenExceedLayer() throws Exception { StringBuilder spanIdBuilder = new StringBuilder("0").append("."); int i = 1; for (; i < 150; i++) { spanIdBuilder.append(i).append("."); } spanIdBuilder.append(i); Map<String, String> baggage = new HashMap<String, String>(); baggage.put("key", "value"); baggage.put("key1", "value1"); baggage.put("key2", "value2"); String traceId = TraceIdGenerator.generate(); SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext(traceId, spanIdBuilder.toString(), ""); sofaTracerSpanContext.addBizBaggage(baggage); SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), "open", sofaTracerSpanContext, null); SofaTracerSpan thisAsParentSpan = sofaTracerSpan.getThisAsParentWhenExceedLayer(); assertEquals("\n" + sofaTracerSpanContext, SofaTracer.ROOT_SPAN_ID, thisAsParentSpan .getSofaTracerSpanContext().getSpanId()); assertNotEquals(traceId, thisAsParentSpan.getSofaTracerSpanContext().getTraceId()); assertEquals(baggage, sofaTracerSpanContext.getBizBaggage()); TestUtil.waitForAsyncLog(); Assert.assertTrue(checkSelfLogContainsError()); }
public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); Map<String, String> baggage = new HashMap<>(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); } else { parent = this; } return parent; }
SofaTracerSpan implements Span { public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); Map<String, String> baggage = new HashMap<>(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); } else { parent = this; } return parent; } }
SofaTracerSpan implements Span { public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); Map<String, String> baggage = new HashMap<>(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); } else { parent = this; } return parent; } SofaTracerSpan(SofaTracer sofaTracer, long startTime, String operationName,
                          SofaTracerSpanContext sofaTracerSpanContext, Map<String, ?> tags);  SofaTracerSpan(SofaTracer sofaTracer, long startTime,
                          List<SofaTracerSpanReferenceRelationship> spanReferences,
                          String operationName, SofaTracerSpanContext sofaTracerSpanContext,
                          Map<String, ?> tags); }
SofaTracerSpan implements Span { public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); Map<String, String> baggage = new HashMap<>(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); } else { parent = this; } return parent; } SofaTracerSpan(SofaTracer sofaTracer, long startTime, String operationName,
                          SofaTracerSpanContext sofaTracerSpanContext, Map<String, ?> tags);  SofaTracerSpan(SofaTracer sofaTracer, long startTime,
                          List<SofaTracerSpanReferenceRelationship> spanReferences,
                          String operationName, SofaTracerSpanContext sofaTracerSpanContext,
                          Map<String, ?> tags); SofaTracerSpan cloneInstance(); @Override SpanContext context(); @Override void finish(); @Override void finish(long endTime); @Override void close(); @Override Span setTag(String key, String value); @Override Span setTag(String key, boolean value); @Override Span setTag(String key, Number number); @Override Span log(String eventValue); @Override Span log(long currentTime, String eventValue); Span log(LogData logData); @Override Span log(long currentTime, Map<String, ?> map); @Override Span log(Map<String, ?> map); @Override Span log(String eventName, /* @Nullable */Object payload); @Override Span log(long currentTime, String eventName, /* @Nullable */Object payload); @Override Span setBaggageItem(String key, String value); @Override String getBaggageItem(String key); @Override Span setOperationName(String operationName); void reportError(String errorType, Map<String, String> context, Throwable e,
                            String errorSourceApp, String... errorSources); void profile(String profileApp, String protocolType, String profileMessage); SofaTracerSpan getThisAsParentWhenExceedLayer(); List<SofaTracerSpanReferenceRelationship> getSpanReferences(); SofaTracer getSofaTracer(); long getStartTime(); void setStartTime(long startTime); long getEndTime(); void setEndTime(long endTime); long getDurationMicroseconds(); Map<String, String> getTagsWithStr(); Map<String, Boolean> getTagsWithBool(); Map<String, Number> getTagsWithNumber(); String getOperationName(); SofaTracerSpanContext getSofaTracerSpanContext(); List<LogData> getLogs(); String getLogType(); void setLogType(String logType); SofaTracerSpan getParentSofaTracerSpan(); void setParentSofaTracerSpan(SofaTracerSpan parentSofaTracerSpan); boolean isServer(); boolean isClient(); @Override String toString(); }
SofaTracerSpan implements Span { public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); Map<String, String> baggage = new HashMap<>(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); } else { parent = this; } return parent; } SofaTracerSpan(SofaTracer sofaTracer, long startTime, String operationName,
                          SofaTracerSpanContext sofaTracerSpanContext, Map<String, ?> tags);  SofaTracerSpan(SofaTracer sofaTracer, long startTime,
                          List<SofaTracerSpanReferenceRelationship> spanReferences,
                          String operationName, SofaTracerSpanContext sofaTracerSpanContext,
                          Map<String, ?> tags); SofaTracerSpan cloneInstance(); @Override SpanContext context(); @Override void finish(); @Override void finish(long endTime); @Override void close(); @Override Span setTag(String key, String value); @Override Span setTag(String key, boolean value); @Override Span setTag(String key, Number number); @Override Span log(String eventValue); @Override Span log(long currentTime, String eventValue); Span log(LogData logData); @Override Span log(long currentTime, Map<String, ?> map); @Override Span log(Map<String, ?> map); @Override Span log(String eventName, /* @Nullable */Object payload); @Override Span log(long currentTime, String eventName, /* @Nullable */Object payload); @Override Span setBaggageItem(String key, String value); @Override String getBaggageItem(String key); @Override Span setOperationName(String operationName); void reportError(String errorType, Map<String, String> context, Throwable e,
                            String errorSourceApp, String... errorSources); void profile(String profileApp, String protocolType, String profileMessage); SofaTracerSpan getThisAsParentWhenExceedLayer(); List<SofaTracerSpanReferenceRelationship> getSpanReferences(); SofaTracer getSofaTracer(); long getStartTime(); void setStartTime(long startTime); long getEndTime(); void setEndTime(long endTime); long getDurationMicroseconds(); Map<String, String> getTagsWithStr(); Map<String, Boolean> getTagsWithBool(); Map<String, Number> getTagsWithNumber(); String getOperationName(); SofaTracerSpanContext getSofaTracerSpanContext(); List<LogData> getLogs(); String getLogType(); void setLogType(String logType); SofaTracerSpan getParentSofaTracerSpan(); void setParentSofaTracerSpan(SofaTracerSpan parentSofaTracerSpan); boolean isServer(); boolean isClient(); @Override String toString(); static final char ARRAY_SEPARATOR; }