提交 e0e9ba03 编写于 作者: P peng-yongsheng

Merge branch 'feature/collector-modelization' of...

Merge branch 'feature/collector-modelization' of https://github.com/OpenSkywalking/skywalking into feature/collector-modelization
/* /*
* Copyright 2017, OpenSkywalking Organization All rights rH2erved. * Copyright 2017, OpenSkywalking Organization All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licensH2/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* UnlH2s required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIH2 OR CONDITIONS OF ANY KIND, either exprH2s or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* Project repository: https://github.com/OpenSkywalking/skywalking * Project repository: https://github.com/OpenSkywalking/skywalking
*/ */
package org.skywalking.apm.collector.storage.h2; package org.skywalking.apm.collector.storage.h2;
import java.util.Properties; import java.util.Properties;
......
...@@ -26,6 +26,7 @@ message TraceSegmentObject { ...@@ -26,6 +26,7 @@ message TraceSegmentObject {
repeated SpanObject spans = 3; repeated SpanObject spans = 3;
int32 applicationId = 4; int32 applicationId = 4;
int32 applicationInstanceId = 5; int32 applicationInstanceId = 5;
bool isSizeLimited = 6;
} }
message TraceSegmentReference { message TraceSegmentReference {
......
...@@ -31,22 +31,27 @@ public class Config { ...@@ -31,22 +31,27 @@ public class Config {
public static class Agent { public static class Agent {
/** /**
* Application code is showed in sky-walking-ui. * Application code is showed in sky-walking-ui. Suggestion: set an unique name for each application, one
* Suggestion: set an unique name for each application, one application's nodes share the same code. * application's nodes share the same code.
*/ */
public static String APPLICATION_CODE = ""; public static String APPLICATION_CODE = "";
/** /**
* Negative or zero means off, by default. * Negative or zero means off, by default. {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in
* {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in 10 seconds tops. * 10 seconds tops.
*/ */
public static int SAMPLE_N_PER_3_SECS = -1; public static int SAMPLE_N_PER_3_SECS = -1;
/** /**
* If the operation name of the first span is included in this set, * If the operation name of the first span is included in this set, this segment should be ignored.
* this segment should be ignored.
*/ */
public static String IGNORE_SUFFIX = ".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg"; 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 { public static class Collector {
...@@ -63,9 +68,7 @@ public class Config { ...@@ -63,9 +68,7 @@ public class Config {
*/ */
public static long DISCOVERY_CHECK_INTERVAL = 60; public static long DISCOVERY_CHECK_INTERVAL = 60;
/** /**
* Collector REST-Service address. * Collector REST-Service address. e.g. SERVERS="127.0.0.1:8080" for single collector node.
* 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. * SERVERS="10.2.45.126:8080,10.2.45.127:7600" for multi collector nodes.
*/ */
public static String SERVERS = ""; public static String SERVERS = "";
...@@ -105,16 +108,15 @@ public class Config { ...@@ -105,16 +108,15 @@ public class Config {
public static String FILE_NAME = "skywalking-api.log"; public static String FILE_NAME = "skywalking-api.log";
/** /**
* Log files directory. * Log files directory. Default is blank string, means, use "system.out" to output logs.
* Default is blank string, means, use "system.out" to output logs.
* *
* @see {@link WriterFactory#getLogWriter()} * @see {@link WriterFactory#getLogWriter()}
*/ */
public static String DIR = ""; public static String DIR = "";
/** /**
* The max size of log file. * The max size of log file. If the size is bigger than this, archive the current file, and write into a new
* If the size is bigger than this, archive the current file, and write into a new file. * file.
*/ */
public static int MAX_FILE_SIZE = 300 * 1024 * 1024; public static int MAX_FILE_SIZE = 300 * 1024 * 1024;
...@@ -129,8 +131,7 @@ public class Config { ...@@ -129,8 +131,7 @@ public class Config {
public static class Plugin { public static class Plugin {
public static class MongoDB { public static class MongoDB {
/** /**
* If true, trace all the parameters, default is false. * If true, trace all the parameters, default is false. Only trace the operation, not include parameters.
* Only trace the operation, not include parameters.
*/ */
public static boolean TRACE_PARAM = false; public static boolean TRACE_PARAM = false;
} }
......
...@@ -21,30 +21,32 @@ package org.skywalking.apm.agent.core.context; ...@@ -21,30 +21,32 @@ package org.skywalking.apm.agent.core.context;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.skywalking.apm.agent.core.boot.ServiceManager; 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.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; 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.EntrySpan;
import org.skywalking.apm.agent.core.context.trace.ExitSpan; 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.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.TraceSegment;
import org.skywalking.apm.agent.core.context.trace.TraceSegmentRef; 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.DictionaryManager;
import org.skywalking.apm.agent.core.dictionary.DictionaryUtil; import org.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.skywalking.apm.agent.core.dictionary.PossibleFound; import org.skywalking.apm.agent.core.dictionary.PossibleFound;
import org.skywalking.apm.agent.core.sampling.SamplingService; import org.skywalking.apm.agent.core.sampling.SamplingService;
/** /**
* The <code>TracingContext</code> represents a core tracing logic controller. * The <code>TracingContext</code> represents a core tracing logic controller. It build the final {@link
* It build the final {@link TracingContext}, by the stack mechanism, * TracingContext}, by the stack mechanism, which is similar with the codes work.
* which is similar with the codes work.
* *
* In opentracing concept, it means, all spans in a segment tracing context(thread) * In opentracing concept, it means, all spans in a segment tracing context(thread) are CHILD_OF relationship, but no
* are CHILD_OF relationship, but no FOLLOW_OF. * FOLLOW_OF.
* *
* In skywalking core concept, FOLLOW_OF is an abstract concept * In skywalking core concept, FOLLOW_OF is an abstract concept when cross-process MQ or cross-thread async/batch tasks
* when cross-process MQ or cross-thread async/batch tasks happen, * happen, we used {@link TraceSegmentRef} for these scenarios. Check {@link TraceSegmentRef} which is from {@link
* we used {@link TraceSegmentRef} for these scenarios. * ContextCarrier} or {@link ContextSnapshot}.
* Check {@link TraceSegmentRef} which is from {@link ContextCarrier} or {@link ContextSnapshot}.
* *
* @author wusheng * @author wusheng
*/ */
...@@ -60,13 +62,11 @@ public class TracingContext implements AbstractTracerContext { ...@@ -60,13 +62,11 @@ public class TracingContext implements AbstractTracerContext {
private TraceSegment segment; private TraceSegment segment;
/** /**
* Active spans stored in a Stack, usually called 'ActiveSpanStack'. * Active spans stored in a Stack, usually called 'ActiveSpanStack'. This {@link LinkedList} is the in-memory
* This {@link LinkedList} is the in-memory storage-structure. * storage-structure. <p> I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link
* <p> * LinkedList#last} instead of {@link #pop()}, {@link #push(AbstractSpan)}, {@link #peek()}
* I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link LinkedList#last} instead of
* {@link #pop()}, {@link #push(AbstractTracingSpan)}, {@link #peek()}
*/ */
private LinkedList<AbstractTracingSpan> activeSpanStack = new LinkedList<AbstractTracingSpan>(); private LinkedList<AbstractSpan> activeSpanStack = new LinkedList<AbstractSpan>();
/** /**
* A counter for the next span. * A counter for the next span.
...@@ -93,21 +93,24 @@ public class TracingContext implements AbstractTracerContext { ...@@ -93,21 +93,24 @@ public class TracingContext implements AbstractTracerContext {
*/ */
@Override @Override
public void inject(ContextCarrier carrier) { public void inject(ContextCarrier carrier) {
AbstractTracingSpan span = this.activeSpan(); AbstractSpan span = this.activeSpan();
if (!span.isExit()) { if (!span.isExit()) {
throw new IllegalStateException("Inject can be done only in Exit Span"); throw new IllegalStateException("Inject can be done only in Exit Span");
} }
ExitSpan exitSpan = (ExitSpan)span;
WithPeerInfo spanWithPeer = (WithPeerInfo)span;
String peer = spanWithPeer.getPeer();
int peerId = spanWithPeer.getPeerId();
carrier.setTraceSegmentId(this.segment.getTraceSegmentId()); carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(span.getSpanId()); carrier.setSpanId(span.getSpanId());
carrier.setParentApplicationInstanceId(segment.getApplicationInstanceId()); carrier.setParentApplicationInstanceId(segment.getApplicationInstanceId());
if (DictionaryUtil.isNull(exitSpan.getPeerId())) { if (DictionaryUtil.isNull(peerId)) {
carrier.setPeerHost(exitSpan.getPeer()); carrier.setPeerHost(peer);
} else { } else {
carrier.setPeerId(exitSpan.getPeerId()); carrier.setPeerId(peerId);
} }
List<TraceSegmentRef> refs = this.segment.getRefs(); List<TraceSegmentRef> refs = this.segment.getRefs();
int operationId; int operationId;
...@@ -119,7 +122,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -119,7 +122,7 @@ public class TracingContext implements AbstractTracerContext {
operationName = ref.getEntryOperationName(); operationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId(); entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
} else { } else {
AbstractTracingSpan firstSpan = first(); AbstractSpan firstSpan = first();
operationId = firstSpan.getOperationId(); operationId = firstSpan.getOperationId();
operationName = firstSpan.getOperationName(); operationName = firstSpan.getOperationName();
entryApplicationInstanceId = this.segment.getApplicationInstanceId(); entryApplicationInstanceId = this.segment.getApplicationInstanceId();
...@@ -169,7 +172,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -169,7 +172,7 @@ public class TracingContext implements AbstractTracerContext {
int entryOperationId; int entryOperationId;
String entryOperationName; String entryOperationName;
int entryApplicationInstanceId; int entryApplicationInstanceId;
AbstractTracingSpan firstSpan = first(); AbstractSpan firstSpan = first();
if (refs != null && refs.size() > 0) { if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0); TraceSegmentRef ref = refs.get(0);
entryOperationId = ref.getEntryOperationId(); entryOperationId = ref.getEntryOperationId();
...@@ -225,8 +228,12 @@ public class TracingContext implements AbstractTracerContext { ...@@ -225,8 +228,12 @@ public class TracingContext implements AbstractTracerContext {
*/ */
@Override @Override
public AbstractSpan createEntrySpan(final String operationName) { public AbstractSpan createEntrySpan(final String operationName) {
AbstractTracingSpan entrySpan; if (isLimitMechanismWorking()) {
final AbstractTracingSpan parentSpan = peek(); NoopSpan span = new NoopSpan();
return push(span);
}
AbstractSpan entrySpan;
final AbstractSpan parentSpan = peek();
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
if (parentSpan == null) { if (parentSpan == null) {
entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
...@@ -269,7 +276,11 @@ public class TracingContext implements AbstractTracerContext { ...@@ -269,7 +276,11 @@ public class TracingContext implements AbstractTracerContext {
*/ */
@Override @Override
public AbstractSpan createLocalSpan(final String operationName) { public AbstractSpan createLocalSpan(final String operationName) {
AbstractTracingSpan parentSpan = peek(); if (isLimitMechanismWorking()) {
NoopSpan span = new NoopSpan();
return push(span);
}
AbstractSpan parentSpan = peek();
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection() AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
.findOrPrepare4Register(segment.getApplicationId(), operationName) .findOrPrepare4Register(segment.getApplicationId(), operationName)
...@@ -298,17 +309,21 @@ public class TracingContext implements AbstractTracerContext { ...@@ -298,17 +309,21 @@ public class TracingContext implements AbstractTracerContext {
*/ */
@Override @Override
public AbstractSpan createExitSpan(final String operationName, final String remotePeer) { public AbstractSpan createExitSpan(final String operationName, final String remotePeer) {
AbstractTracingSpan exitSpan; AbstractSpan exitSpan;
AbstractTracingSpan parentSpan = peek(); AbstractSpan parentSpan = peek();
if (parentSpan != null && parentSpan.isExit()) { if (parentSpan != null && parentSpan.isExit()) {
exitSpan = parentSpan; exitSpan = parentSpan;
} else { } else {
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId(); final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
exitSpan = (AbstractTracingSpan)DictionaryManager.findApplicationCodeSection() exitSpan = (AbstractSpan)DictionaryManager.findApplicationCodeSection()
.find(remotePeer).doInCondition( .find(remotePeer).doInCondition(
new PossibleFound.FoundAndObtain() { new PossibleFound.FoundAndObtain() {
@Override @Override
public Object doProcess(final int peerId) { public Object doProcess(final int peerId) {
if (isLimitMechanismWorking()) {
return new NoopExitSpan(peerId);
}
return DictionaryManager.findOperationNameCodeSection() return DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName) .findOnly(segment.getApplicationId(), operationName)
.doInCondition( .doInCondition(
...@@ -328,6 +343,10 @@ public class TracingContext implements AbstractTracerContext { ...@@ -328,6 +343,10 @@ public class TracingContext implements AbstractTracerContext {
new PossibleFound.NotFoundAndObtain() { new PossibleFound.NotFoundAndObtain() {
@Override @Override
public Object doProcess() { public Object doProcess() {
if (isLimitMechanismWorking()) {
return new NoopExitSpan(remotePeer);
}
return DictionaryManager.findOperationNameCodeSection() return DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName) .findOnly(segment.getApplicationId(), operationName)
.doInCondition( .doInCondition(
...@@ -354,8 +373,8 @@ public class TracingContext implements AbstractTracerContext { ...@@ -354,8 +373,8 @@ public class TracingContext implements AbstractTracerContext {
* @return the active span of current context, the top element of {@link #activeSpanStack} * @return the active span of current context, the top element of {@link #activeSpanStack}
*/ */
@Override @Override
public AbstractTracingSpan activeSpan() { public AbstractSpan activeSpan() {
AbstractTracingSpan span = peek(); AbstractSpan span = peek();
if (span == null) { if (span == null) {
throw new IllegalStateException("No active span."); throw new IllegalStateException("No active span.");
} }
...@@ -363,16 +382,21 @@ public class TracingContext implements AbstractTracerContext { ...@@ -363,16 +382,21 @@ public class TracingContext implements AbstractTracerContext {
} }
/** /**
* Stop the given span, if and only if this one is the top element of {@link #activeSpanStack}. * Stop the given span, if and only if this one is the top element of {@link #activeSpanStack}. Because the tracing
* Because the tracing core must make sure the span must match in a stack module, like any program did. * core must make sure the span must match in a stack module, like any program did.
* *
* @param span to finish * @param span to finish
*/ */
@Override @Override
public void stopSpan(AbstractSpan span) { public void stopSpan(AbstractSpan span) {
AbstractTracingSpan lastSpan = peek(); AbstractSpan lastSpan = peek();
if (lastSpan == span) { if (lastSpan == span) {
if (lastSpan.finish(segment)) { if (lastSpan instanceof AbstractTracingSpan) {
AbstractTracingSpan toFinishSpan = (AbstractTracingSpan)lastSpan;
if (toFinishSpan.finish(segment)) {
pop();
}
} else {
pop(); pop();
} }
} else { } else {
...@@ -389,7 +413,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -389,7 +413,7 @@ public class TracingContext implements AbstractTracerContext {
* TracingContext.ListenerManager} * TracingContext.ListenerManager}
*/ */
private void finish() { private void finish() {
TraceSegment finishedSegment = segment.finish(); TraceSegment finishedSegment = segment.finish(isLimitMechanismWorking());
/** /**
* Recheck the segment if the segment contains only one span. * Recheck the segment if the segment contains only one span.
* Because in the runtime, can't sure this segment is part of distributed trace. * Because in the runtime, can't sure this segment is part of distributed trace.
...@@ -421,9 +445,9 @@ public class TracingContext implements AbstractTracerContext { ...@@ -421,9 +445,9 @@ public class TracingContext implements AbstractTracerContext {
} }
/** /**
* Notify the {@link TracingContext.ListenerManager} about the given {@link TraceSegment} have finished. * Notify the {@link TracingContext.ListenerManager} about the given {@link TraceSegment} have finished. And
* And trigger {@link TracingContext.ListenerManager} to notify all {@link #LISTENERS} 's * trigger {@link TracingContext.ListenerManager} to notify all {@link #LISTENERS} 's {@link
* {@link TracingContextListener#afterFinished(TraceSegment)} * TracingContextListener#afterFinished(TraceSegment)}
* *
* @param finishedSegment * @param finishedSegment
*/ */
...@@ -445,7 +469,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -445,7 +469,7 @@ public class TracingContext implements AbstractTracerContext {
/** /**
* @return the top element of 'ActiveSpanStack', and remove it. * @return the top element of 'ActiveSpanStack', and remove it.
*/ */
private AbstractTracingSpan pop() { private AbstractSpan pop() {
return activeSpanStack.removeLast(); return activeSpanStack.removeLast();
} }
...@@ -454,7 +478,7 @@ public class TracingContext implements AbstractTracerContext { ...@@ -454,7 +478,7 @@ public class TracingContext implements AbstractTracerContext {
* *
* @param span * @param span
*/ */
private AbstractTracingSpan push(AbstractTracingSpan span) { private AbstractSpan push(AbstractSpan span) {
activeSpanStack.addLast(span); activeSpanStack.addLast(span);
return span; return span;
} }
...@@ -462,14 +486,18 @@ public class TracingContext implements AbstractTracerContext { ...@@ -462,14 +486,18 @@ public class TracingContext implements AbstractTracerContext {
/** /**
* @return the top element of 'ActiveSpanStack' only. * @return the top element of 'ActiveSpanStack' only.
*/ */
private AbstractTracingSpan peek() { private AbstractSpan peek() {
if (activeSpanStack.isEmpty()) { if (activeSpanStack.isEmpty()) {
return null; return null;
} }
return activeSpanStack.getLast(); return activeSpanStack.getLast();
} }
private AbstractTracingSpan first() { private AbstractSpan first() {
return activeSpanStack.getFirst(); return activeSpanStack.getFirst();
} }
private boolean isLimitMechanismWorking() {
return spanIdGenerator >= Config.Agent.SPAN_LIMIT_PER_SEGMENT;
}
} }
...@@ -22,8 +22,7 @@ import java.util.Map; ...@@ -22,8 +22,7 @@ import java.util.Map;
import org.skywalking.apm.network.trace.component.Component; import org.skywalking.apm.network.trace.component.Component;
/** /**
* The <code>AbstractSpan</code> represents the span's skeleton, * The <code>AbstractSpan</code> represents the span's skeleton, which contains all open methods.
* which contains all open methods.
* *
* @author wusheng * @author wusheng
*/ */
...@@ -37,8 +36,8 @@ public interface AbstractSpan { ...@@ -37,8 +36,8 @@ public interface AbstractSpan {
AbstractSpan setComponent(Component component); AbstractSpan setComponent(Component component);
/** /**
* Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. * Only use this method in explicit instrumentation, like opentracing-skywalking-bridge. It it higher recommend
* It it higher recommend don't use this for performance consideration. * don't use this for performance consideration.
* *
* @param componentName * @param componentName
* @return the span for chaining. * @return the span for chaining.
...@@ -89,4 +88,24 @@ public interface AbstractSpan { ...@@ -89,4 +88,24 @@ public interface AbstractSpan {
* @return this Span instance, for chaining * @return this Span instance, for chaining
*/ */
AbstractSpan setOperationName(String operationName); 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);
} }
...@@ -29,8 +29,8 @@ import org.skywalking.apm.network.proto.SpanType; ...@@ -29,8 +29,8 @@ import org.skywalking.apm.network.proto.SpanType;
import org.skywalking.apm.network.trace.component.Component; import org.skywalking.apm.network.trace.component.Component;
/** /**
* The <code>AbstractTracingSpan</code> represents a group of {@link AbstractSpan} implementations, * The <code>AbstractTracingSpan</code> represents a group of {@link AbstractSpan} implementations, which belongs a real
* which belongs a real distributed trace. * distributed trace.
* *
* @author wusheng * @author wusheng
*/ */
...@@ -59,9 +59,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -59,9 +59,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
protected String componentName; protected String componentName;
/** /**
* Log is a concept from OpenTracing spec. * Log is a concept from OpenTracing spec. <p> {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
* <p>
* {@see https://github.com/opentracing/specification/blob/master/specification.md#log-structured-data}
*/ */
protected List<LogDataEntity> logs; protected List<LogDataEntity> logs;
...@@ -94,8 +92,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -94,8 +92,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
} }
/** /**
* Finish the active Span. * Finish the active Span. When it is finished, it will be archived by the given {@link TraceSegment}, which owners
* When it is finished, it will be archived by the given {@link TraceSegment}, which owners it. * it.
* *
* @param owner of the Span. * @param owner of the Span.
*/ */
...@@ -105,6 +103,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -105,6 +103,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return true; return true;
} }
@Override
public AbstractTracingSpan start() { public AbstractTracingSpan start() {
this.startTime = System.currentTimeMillis(); this.startTime = System.currentTimeMillis();
return this; return this;
...@@ -150,8 +149,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -150,8 +149,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
} }
/** /**
* In the scope of this span tracing context, error occurred, * In the scope of this span tracing context, error occurred, in auto-instrumentation mechanism, almost means throw
* in auto-instrumentation mechanism, almost means throw an exception. * an exception.
* *
* @return span instance, for chaining. * @return span instance, for chaining.
*/ */
...@@ -162,8 +161,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -162,8 +161,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
} }
/** /**
* Set the operation name, just because these is not compress dictionary value for this name. * Set the operation name, just because these is not compress dictionary value for this name. Use the entire string
* Use the entire string temporarily, the agent will compress this name in async mode. * temporarily, the agent will compress this name in async mode.
* *
* @param operationName * @param operationName
* @return span instance, for chaining. * @return span instance, for chaining.
...@@ -181,20 +180,24 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -181,20 +180,24 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
* @param operationId * @param operationId
* @return span instance, for chaining. * @return span instance, for chaining.
*/ */
@Override
public AbstractTracingSpan setOperationId(int operationId) { public AbstractTracingSpan setOperationId(int operationId) {
this.operationId = operationId; this.operationId = operationId;
this.operationName = null; this.operationName = null;
return this; return this;
} }
@Override
public int getSpanId() { public int getSpanId() {
return spanId; return spanId;
} }
@Override
public int getOperationId() { public int getOperationId() {
return operationId; return operationId;
} }
@Override
public String getOperationName() { public String getOperationName() {
return operationName; return operationName;
} }
...@@ -206,8 +209,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -206,8 +209,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
} }
/** /**
* Set the component of this span, with internal supported. * Set the component of this span, with internal supported. Highly recommend to use this way.
* Highly recommend to use this way.
* *
* @param component * @param component
* @return span instance, for chaining. * @return span instance, for chaining.
...@@ -219,8 +221,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan { ...@@ -219,8 +221,7 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
} }
/** /**
* Set the component name. * Set the component name. By using this, cost more memory and network.
* By using this, cost more memory and network.
* *
* @param componentName * @param componentName
* @return span instance, for chaining. * @return span instance, for chaining.
......
...@@ -35,7 +35,7 @@ import org.skywalking.apm.network.trace.component.Component; ...@@ -35,7 +35,7 @@ import org.skywalking.apm.network.trace.component.Component;
* *
* @author wusheng * @author wusheng
*/ */
public class ExitSpan extends StackBasedTracingSpan { public class ExitSpan extends StackBasedTracingSpan implements WithPeerInfo {
private String peer; private String peer;
private int peerId; private int peerId;
...@@ -147,10 +147,12 @@ public class ExitSpan extends StackBasedTracingSpan { ...@@ -147,10 +147,12 @@ public class ExitSpan extends StackBasedTracingSpan {
} }
} }
@Override
public int getPeerId() { public int getPeerId() {
return peerId; return peerId;
} }
@Override
public String getPeer() { public String getPeer() {
return peer; return peer;
} }
......
/*
* 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;
public class NoopExitSpan extends NoopSpan implements WithPeerInfo {
private String peer;
private int peerId;
public NoopExitSpan(int peerId) {
this.peerId = peerId;
}
public NoopExitSpan(String peer) {
this.peer = peer;
}
@Override
public int getPeerId() {
return peerId;
}
@Override
public String getPeer() {
return peer;
}
@Override
public boolean isExit() {
return true;
}
}
...@@ -78,4 +78,24 @@ public class NoopSpan implements AbstractSpan { ...@@ -78,4 +78,24 @@ public class NoopSpan implements AbstractSpan {
@Override public AbstractSpan setOperationName(String operationName) { @Override public AbstractSpan setOperationName(String operationName) {
return this; return this;
} }
@Override public AbstractSpan start() {
return this;
}
@Override public int getSpanId() {
return 0;
}
@Override public int getOperationId() {
return 0;
}
@Override public String getOperationName() {
return "";
}
@Override public AbstractSpan setOperationId(int operationId) {
return this;
}
} }
...@@ -26,68 +26,51 @@ import org.skywalking.apm.agent.core.context.ids.DistributedTraceIds; ...@@ -26,68 +26,51 @@ import org.skywalking.apm.agent.core.context.ids.DistributedTraceIds;
import org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator; import org.skywalking.apm.agent.core.context.ids.GlobalIdGenerator;
import org.skywalking.apm.agent.core.context.ids.ID; import org.skywalking.apm.agent.core.context.ids.ID;
import org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId; import org.skywalking.apm.agent.core.context.ids.NewDistributedTraceId;
import org.skywalking.apm.agent.core.logging.api.ILog;
import org.skywalking.apm.agent.core.logging.api.LogManager;
import org.skywalking.apm.network.proto.TraceSegmentObject; import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.skywalking.apm.network.proto.UpstreamSegment; import org.skywalking.apm.network.proto.UpstreamSegment;
/** /**
* {@link TraceSegment} is a segment or fragment of the distributed trace. * {@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}
* {@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
* A {@link * by multi {@link TraceSegment}s, because the distributed trace crosses multi-processes, multi-threads. <p>
* 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.
* <p>
* *
* @author wusheng * @author wusheng
*/ */
public class TraceSegment { 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. * The id of this trace segment. Every segment has its unique-global-id.
* Every segment has its unique-global-id.
*/ */
private ID traceSegmentId; private ID traceSegmentId;
/** /**
* The refs of parent trace segments, except the primary one. * The refs of parent trace segments, except the primary one. For most RPC call, {@link #refs} contains only one
* For most RPC call, {@link #refs} contains only one element, * element, but if this segment is a start span of batch process, the segment faces multi parents, at this moment,
* but if this segment is a start span of batch process, the segment faces multi parents, * we use this {@link #refs} to link them.
* at this moment, we use this {@link #refs} to link them.
*/ */
private List<TraceSegmentRef> refs; private List<TraceSegmentRef> refs;
/** /**
* The spans belong to this trace segment. * The spans belong to this trace segment. They all have finished. All active spans are hold and controlled by
* They all have finished. * "skywalking-api" module.
* All active spans are hold and controlled by "skywalking-api" module.
*/ */
private List<AbstractTracingSpan> spans; private List<AbstractTracingSpan> spans;
/** /**
* The <code>relatedGlobalTraces</code> represent a set of all related trace. Most time it contains only one * The <code>relatedGlobalTraces</code> 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 * element, because only one parent {@link TraceSegment} exists, but, in batch scenario, the num becomes greater
* than 1, also meaning multi-parents {@link TraceSegment}. * than 1, also meaning multi-parents {@link TraceSegment}. <p> The difference between
* <p> * <code>relatedGlobalTraces</code> and {@link #refs} is: {@link #refs} targets this {@link TraceSegment}'s direct
* The difference between <code>relatedGlobalTraces</code> and {@link #refs} is: * parent, <p> and <p> <code>relatedGlobalTraces</code> targets this {@link TraceSegment}'s related call chain, a
* {@link #refs} targets this {@link TraceSegment}'s direct parent, * call chain contains multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui.
* <p>
* and
* <p>
* <code>relatedGlobalTraces</code> 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 DistributedTraceIds relatedGlobalTraces;
private boolean ignore = false; private boolean ignore = false;
private boolean isSizeLimited = false;
/** /**
* Create a default/empty trace segment, * Create a default/empty trace segment, with current time as start time, and generate a new segment id.
* with current time as start time,
* and generate a new segment id.
*/ */
public TraceSegment() { public TraceSegment() {
this.traceSegmentId = GlobalIdGenerator.generate(); this.traceSegmentId = GlobalIdGenerator.generate();
...@@ -118,8 +101,8 @@ public class TraceSegment { ...@@ -118,8 +101,8 @@ public class TraceSegment {
} }
/** /**
* After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module, * After {@link AbstractSpan} is finished, as be controller by "skywalking-api" module, notify the {@link
* notify the {@link TraceSegment} to archive it. * TraceSegment} to archive it.
* *
* @param finishedSpan * @param finishedSpan
*/ */
...@@ -128,11 +111,10 @@ public class TraceSegment { ...@@ -128,11 +111,10 @@ public class TraceSegment {
} }
/** /**
* Finish this {@link TraceSegment}. * Finish this {@link TraceSegment}. <p> return this, for chaining
* <p>
* return this, for chaining
*/ */
public TraceSegment finish() { public TraceSegment finish(boolean isSizeLimited) {
this.isSizeLimited = isSizeLimited;
return this; return this;
} }
...@@ -195,6 +177,7 @@ public class TraceSegment { ...@@ -195,6 +177,7 @@ public class TraceSegment {
} }
traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID); traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID); traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited);
upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString()); upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString());
return upstreamBuilder.build(); return upstreamBuilder.build();
......
/*
* 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();
}
...@@ -5,6 +5,10 @@ agent.application_code=Your_ApplicationName ...@@ -5,6 +5,10 @@ agent.application_code=Your_ApplicationName
# Negative number means sample traces as many as possible, most likely 100% # Negative number means sample traces as many as possible, most likely 100%
# agent.sample_n_per_3_secs=-1 # 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. # 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 # agent.ignore_suffix=.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册