aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java/io/opencensus/trace/Tracer.java
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-06-30 11:12:56 -0700
committerGitHub <noreply@github.com>2017-06-30 11:12:56 -0700
commit07d69996286f6800be2d3977571cac0a80bb4e7c (patch)
tree0411a46146d208b253c5bb633203905b6f84dda1 /api/src/main/java/io/opencensus/trace/Tracer.java
parent1989720ea57fc40a4a2aaedcfb09fe988e9b186d (diff)
downloadopencensus-java-07d69996286f6800be2d3977571cac0a80bb4e7c.tar.gz
Change API to remove the "Option" logic and keep only Builder. (#380)
Diffstat (limited to 'api/src/main/java/io/opencensus/trace/Tracer.java')
-rw-r--r--api/src/main/java/io/opencensus/trace/Tracer.java67
1 files changed, 30 insertions, 37 deletions
diff --git a/api/src/main/java/io/opencensus/trace/Tracer.java b/api/src/main/java/io/opencensus/trace/Tracer.java
index e6172bed..ef5616a9 100644
--- a/api/src/main/java/io/opencensus/trace/Tracer.java
+++ b/api/src/main/java/io/opencensus/trace/Tracer.java
@@ -16,8 +16,6 @@ package io.opencensus.trace;
import static com.google.common.base.Preconditions.checkNotNull;
import io.opencensus.common.NonThrowingCloseable;
-import io.opencensus.trace.base.StartSpanOptions;
-import io.opencensus.trace.internal.SpanFactory;
import javax.annotation.Nullable;
/**
@@ -67,7 +65,6 @@ import javax.annotation.Nullable;
*/
public abstract class Tracer {
private static final NoopTracer noopTracer = new NoopTracer();
- private final SpanFactory spanFactory;
/**
* Returns the no-op implementation of the {@code Tracer}.
@@ -142,7 +139,7 @@ public abstract class Tracer {
* @param span The {@link Span} to be set to the current Context.
* @return an object that defines a scope where the given {@link Span} will be set to the current
* Context.
- * @throws NullPointerException if span is null.
+ * @throws NullPointerException if {@code span} is null.
*/
public final NonThrowingCloseable withSpan(Span span) {
return ContextUtils.withSpan(checkNotNull(span, "span"));
@@ -150,7 +147,7 @@ public abstract class Tracer {
/**
* Returns a {@link SpanBuilder} to create and start a new child {@link Span} as a child of to the
- * current {@code Span} if any, otherwise create a root Span with the default options.
+ * current {@code Span} if any, otherwise creates a root {@code Span}.
*
* <p>See {@link SpanBuilder} for usage examples.
*
@@ -159,7 +156,7 @@ public abstract class Tracer {
*
* @param name The name of the returned Span.
* @return a {@code SpanBuilder} to create and start a new {@code Span}.
- * @throws NullPointerException if name is null.
+ * @throws NullPointerException if {@code name} is null.
*/
public final SpanBuilder spanBuilder(String name) {
return spanBuilder(ContextUtils.getCurrentSpan(), name);
@@ -167,64 +164,60 @@ public abstract class Tracer {
/**
* Returns a {@link SpanBuilder} to create and start a new child {@link Span} (or root if parent
- * is null), with parent being the designated {@code Span}.
+ * is {@code null} or has an invalid {@link SpanContext}), with parent being the designated {@code
+ * Span}.
*
* <p>See {@link SpanBuilder} for usage examples.
*
- * <p>This <b>must</b> be used to create a {@code Span} when manual Context propagation is used.
+ * <p>This <b>must</b> be used to create a {@code Span} when manual Context propagation is used
+ * OR when creating a root {@code Span} with a {@code null} parent.
*
* @param parent The parent of the returned Span. If null the {@code SpanBuilder} will build a
* root {@code Span}.
* @param name The name of the returned Span.
* @return a {@code SpanBuilder} to create and start a new {@code Span}.
- * @throws NullPointerException if name is null.
+ * @throws NullPointerException if {@code name} is null.
*/
- public final SpanBuilder spanBuilder(@Nullable Span parent, String name) {
- return SpanBuilder.builder(spanFactory, parent, checkNotNull(name, "name"));
- }
+ public abstract SpanBuilder spanBuilder(@Nullable Span parent, String name);
/**
* Returns a {@link SpanBuilder} to create and start a new child {@link Span} (or root if parent
- * is null), with parent being the {@link Span} designated by the {@link SpanContext}.
+ * is an invalid {@link SpanContext}), with parent being the {@link Span} designated by the {@link
+ * SpanContext}.
*
* <p>See {@link SpanBuilder} for usage examples.
*
* <p>This <b>must</b> be used to create a {@code Span} when the parent is in a different process.
* This is only intended for use by RPC systems or similar.
*
- * @param remoteParent The remote parent of the returned Span.
+ * <p>If no {@link SpanContext} OR fail to parse the {@link SpanContext} on the server side,
+ * users must call this method with an {@link SpanContext#INVALID} remote parent {@code
+ * SpanContext}.
+ *
+ * @param remoteParentSpanContext The remote parent of the returned Span.
* @param name The name of the returned Span.
* @return a {@code SpanBuilder} to create and start a new {@code Span}.
- * @throws NullPointerException if name is null.
+ * @throws NullPointerException if {@code name} or {@code remoteParentSpanContext} are null.
*/
- public final SpanBuilder spanBuilderWithRemoteParent(
- @Nullable SpanContext remoteParent, String name) {
- return SpanBuilder.builderWithRemoteParent(
- spanFactory, remoteParent, checkNotNull(name, "name"));
- }
+ public abstract SpanBuilder spanBuilderWithRemoteParent(
+ SpanContext remoteParentSpanContext, String name);
// No-Op implementation of the Tracer.
private static final class NoopTracer extends Tracer {
- private NoopTracer() {
- super(new NoopSpanFactory());
- }
- // No-op implementation of the SpanFactory
- private static final class NoopSpanFactory extends SpanFactory {
- @Override
- public Span startSpan(@Nullable Span parent, String name, StartSpanOptions options) {
- return BlankSpan.INSTANCE;
- }
+ @Override
+ public SpanBuilder spanBuilder(@Nullable Span parent, String name) {
+ return new SpanBuilder.NoopSpanBuilder(parent, name);
+ }
- @Override
- public Span startSpanWithRemoteParent(
- @Nullable SpanContext remoteParent, String name, StartSpanOptions options) {
- return BlankSpan.INSTANCE;
- }
+ @Override
+ public SpanBuilder spanBuilderWithRemoteParent(
+ SpanContext remoteParentSpanContext, String name) {
+ return new SpanBuilder.NoopSpanBuilder(remoteParentSpanContext, name);
}
- }
- protected Tracer(SpanFactory spanFactory) {
- this.spanFactory = checkNotNull(spanFactory, "spanFactory");
+ private NoopTracer() {}
}
+
+ protected Tracer() {}
}