diff --git a/apm-network/src/main/proto/TraceSegmentService.proto b/apm-network/src/main/proto/TraceSegmentService.proto
index bc6f75817cd4..95eb1de6bc3a 100644
--- a/apm-network/src/main/proto/TraceSegmentService.proto
+++ b/apm-network/src/main/proto/TraceSegmentService.proto
@@ -26,6 +26,7 @@ message TraceSegmentObject {
repeated SpanObject spans = 3;
int32 applicationId = 4;
int32 applicationInstanceId = 5;
+ bool isSizeLimited = 6;
}
message TraceSegmentReference {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
index 55e58942f1ba..f2903d5300b5 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/conf/Config.java
@@ -31,22 +31,27 @@ public class Config {
public static class Agent {
/**
- * Application code is showed in sky-walking-ui.
- * Suggestion: set an unique name for each application, one application's nodes share the same code.
+ * Application code is showed in sky-walking-ui. Suggestion: set an unique name for each application, one
+ * application's nodes share the same code.
*/
public static String APPLICATION_CODE = "";
/**
- * Negative or zero means off, by default.
- * {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in 10 seconds tops.
+ * Negative or zero means off, by default. {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in
+ * 10 seconds tops.
*/
public static int SAMPLE_N_PER_3_SECS = -1;
/**
- * If the operation name of the first span is included in this set,
- * this segment should be ignored.
+ * If the operation name of the first span is included in this set, this segment should be ignored.
*/
public static String IGNORE_SUFFIX = ".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg";
+
+ /**
+ * The max number of spans in a single segment. Through this config item, skywalking keep your application
+ * memory cost estimated.
+ */
+ public static int SPAN_LIMIT_PER_SEGMENT = 300;
}
public static class Collector {
@@ -63,9 +68,7 @@ public static class Collector {
*/
public static long DISCOVERY_CHECK_INTERVAL = 60;
/**
- * Collector REST-Service address.
- * e.g.
- * SERVERS="127.0.0.1:8080" for single collector node.
+ * Collector REST-Service address. e.g. SERVERS="127.0.0.1:8080" for single collector node.
* SERVERS="10.2.45.126:8080,10.2.45.127:7600" for multi collector nodes.
*/
public static String SERVERS = "";
@@ -105,16 +108,15 @@ public static class Logging {
public static String FILE_NAME = "skywalking-api.log";
/**
- * Log files directory.
- * Default is blank string, means, use "system.out" to output logs.
+ * Log files directory. Default is blank string, means, use "system.out" to output logs.
*
* @see {@link WriterFactory#getLogWriter()}
*/
public static String DIR = "";
/**
- * The max size of log file.
- * If the size is bigger than this, archive the current file, and write into a new file.
+ * The max size of log file. If the size is bigger than this, archive the current file, and write into a new
+ * file.
*/
public static int MAX_FILE_SIZE = 300 * 1024 * 1024;
@@ -129,8 +131,7 @@ public static class Logging {
public static class Plugin {
public static class MongoDB {
/**
- * If true, trace all the parameters, default is false.
- * Only trace the operation, not include parameters.
+ * If true, trace all the parameters, default is false. Only trace the operation, not include parameters.
*/
public static boolean TRACE_PARAM = false;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
index bde4d7c723f5..39d06c4496a2 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/TracingContext.java
@@ -21,30 +21,32 @@
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.agent.core.boot.ServiceManager;
+import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.skywalking.apm.agent.core.context.trace.EntrySpan;
import org.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.skywalking.apm.agent.core.context.trace.LocalSpan;
+import org.skywalking.apm.agent.core.context.trace.NoopExitSpan;
+import org.skywalking.apm.agent.core.context.trace.NoopSpan;
import org.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef;
+import org.skywalking.apm.agent.core.context.trace.WithPeerInfo;
import org.skywalking.apm.agent.core.dictionary.DictionaryManager;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.agent.core.dictionary.PossibleFound;
import org.skywalking.apm.agent.core.sampling.SamplingService;
/**
- * The TracingContext
represents a core tracing logic controller.
- * It build the final {@link TracingContext}, by the stack mechanism,
- * which is similar with the codes work.
+ * The TracingContext
represents a core tracing logic controller. It build the final {@link
+ * TracingContext}, by the stack mechanism, which is similar with the codes work.
*
- * In opentracing concept, it means, all spans in a segment tracing context(thread)
- * are CHILD_OF relationship, but no FOLLOW_OF.
+ * In opentracing concept, it means, all spans in a segment tracing context(thread) are CHILD_OF relationship, but no
+ * FOLLOW_OF.
*
- * In skywalking core concept, FOLLOW_OF is an abstract concept
- * when cross-process MQ or cross-thread async/batch tasks happen,
- * we used {@link TraceSegmentRef} for these scenarios.
- * Check {@link TraceSegmentRef} which is from {@link ContextCarrier} or {@link ContextSnapshot}.
+ * In skywalking core concept, FOLLOW_OF is an abstract concept when cross-process MQ or cross-thread async/batch tasks
+ * happen, we used {@link TraceSegmentRef} for these scenarios. Check {@link TraceSegmentRef} which is from {@link
+ * ContextCarrier} or {@link ContextSnapshot}.
*
* @author wusheng
*/
@@ -60,13 +62,11 @@ public class TracingContext implements AbstractTracerContext {
private TraceSegment segment;
/**
- * Active spans stored in a Stack, usually called 'ActiveSpanStack'.
- * This {@link LinkedList} is the in-memory storage-structure.
- *
- * I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link LinkedList#last} instead of - * {@link #pop()}, {@link #push(AbstractTracingSpan)}, {@link #peek()} + * Active spans stored in a Stack, usually called 'ActiveSpanStack'. This {@link LinkedList} is the in-memory + * storage-structure.
I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link
+ * LinkedList#last} instead of {@link #pop()}, {@link #push(AbstractSpan)}, {@link #peek()}
*/
- private LinkedList
- * {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
+ * Log is a concept from OpenTracing spec. {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
*/
protected List
+ * {@link TraceSegment} is a segment or fragment of the distributed trace. {@see https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model}
+ * A {@link TraceSegment} means the segment, which exists in current {@link Thread}. And the distributed trace is formed
+ * by multi {@link TraceSegment}s, because the distributed trace crosses multi-processes, multi-threads.
*
* @author wusheng
*/
public class TraceSegment {
- private static final ILog logger = LogManager.getLogger(TraceSegment.class);
-
- private static final String ID_TYPE = "S";
-
/**
- * The id of this trace segment.
- * Every segment has its unique-global-id.
+ * The id of this trace segment. Every segment has its unique-global-id.
*/
private ID traceSegmentId;
/**
- * The refs of parent trace segments, except the primary one.
- * For most RPC call, {@link #refs} contains only one element,
- * but if this segment is a start span of batch process, the segment faces multi parents,
- * at this moment, we use this {@link #refs} to link them.
+ * The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one
+ * element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment,
+ * we use this {@link #refs} to link them.
*/
private List
- * The difference between
- * and
- *
- * The difference between
+ * and
- * return this, for chaining
+ * Finish this {@link TraceSegment}. return this, for chaining
*/
- public TraceSegment finish() {
+ public TraceSegment finish(boolean isSizeLimited) {
+ this.isSizeLimited = isSizeLimited;
return this;
}
@@ -195,6 +177,7 @@ public UpstreamSegment transform() {
}
traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
+ traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited);
upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString());
return upstreamBuilder.build();
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java
new file mode 100644
index 000000000000..4c6a30f7461d
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/WithPeerInfo.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.agent.core.context.trace;
+
+/**
+ * @author wusheng
+ */
+public interface WithPeerInfo {
+ int getPeerId();
+
+ String getPeer();
+}
diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config
index a81175845663..d85abb433c60 100644
--- a/apm-sniffer/config/agent.config
+++ b/apm-sniffer/config/agent.config
@@ -5,6 +5,10 @@ agent.application_code=Your_ApplicationName
# Negative number means sample traces as many as possible, most likely 100%
# agent.sample_n_per_3_secs=-1
+# The max amount of spans in a single segment.
+# Through this config item, skywalking keep your application memory cost estimated.
+# agent.span_limit_per_segment=300
+
# Ignore the segments if their operation names start with these suffix.
# agent.ignore_suffix=.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg
AbstractSpan
represents the span's skeleton,
- * which contains all open methods.
+ * The AbstractSpan
represents the span's skeleton, which contains all open methods.
*
* @author wusheng
*/
@@ -37,8 +36,8 @@ public interface AbstractSpan {
AbstractSpan setComponent(Component component);
/**
- * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge.
- * It it higher recommend don't use this for performance consideration.
+ * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. It it higher recommend
+ * don't use this for performance consideration.
*
* @param componentName
* @return the span for chaining.
@@ -89,4 +88,24 @@ public interface AbstractSpan {
* @return this Span instance, for chaining
*/
AbstractSpan setOperationName(String operationName);
+
+ /**
+ * Start a span.
+ *
+ * @return this Span instance, for chaining
+ */
+ AbstractSpan start();
+
+ /**
+ * Get the id of span
+ *
+ * @return id value.
+ */
+ int getSpanId();
+
+ int getOperationId();
+
+ String getOperationName();
+
+ AbstractSpan setOperationId(int operationId);
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
index 41920a1998b0..8ef9ea275016 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java
@@ -29,8 +29,8 @@
import org.skywalking.apm.network.trace.component.Component;
/**
- * The AbstractTracingSpan
represents a group of {@link AbstractSpan} implementations,
- * which belongs a real distributed trace.
+ * The AbstractTracingSpan
represents a group of {@link AbstractSpan} implementations, which belongs a real
+ * distributed trace.
*
* @author wusheng
*/
@@ -59,9 +59,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
protected String componentName;
/**
- * Log is a concept from OpenTracing spec.
- * relatedGlobalTraces
represent a set of all related trace. Most time it contains only one
* element, because only one parent {@link TraceSegment} exists, but, in batch scenario, the num becomes greater
- * than 1, also meaning multi-parents {@link TraceSegment}.
- * relatedGlobalTraces
and {@link #refs} is:
- * {@link #refs} targets this {@link TraceSegment}'s direct parent,
- * relatedGlobalTraces
targets this {@link TraceSegment}'s related call chain, a call chain contains
- * multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui.
+ * than 1, also meaning multi-parents {@link TraceSegment}. relatedGlobalTraces
and {@link #refs} is: {@link #refs} targets this {@link TraceSegment}'s direct
+ * parent, relatedGlobalTraces
targets this {@link TraceSegment}'s related call chain, a
+ * call chain contains multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui.
*/
private DistributedTraceIds relatedGlobalTraces;
private boolean ignore = false;
+ private boolean isSizeLimited = false;
+
/**
- * Create a default/empty trace segment,
- * with current time as start time,
- * and generate a new segment id.
+ * Create a default/empty trace segment, with current time as start time, and generate a new segment id.
*/
public TraceSegment() {
this.traceSegmentId = GlobalIdGenerator.generate();
@@ -118,8 +101,8 @@ public void relatedGlobalTraces(DistributedTraceId distributedTraceId) {
}
/**
- * After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module,
- * notify the {@link TraceSegment} to archive it.
+ * After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module, notify the {@link
+ * TraceSegment} to archive it.
*
* @param finishedSpan
*/
@@ -128,11 +111,10 @@ public void archive(AbstractTracingSpan finishedSpan) {
}
/**
- * Finish this {@link TraceSegment}.
- *