• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-17, OpenCensus Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.opencensus.trace;
18 
19 import io.opencensus.internal.Utils;
20 import java.util.Map;
21 import javax.annotation.concurrent.Immutable;
22 
23 /**
24  * The {@code BlankSpan} is a singleton class, which is the default {@link Span} that is used when
25  * no {@code Span} implementation is available. All operations are no-op.
26  *
27  * <p>Used also to stop tracing, see {@link Tracer#withSpan}.
28  *
29  * @since 0.5
30  */
31 @Immutable
32 public final class BlankSpan extends Span {
33   /**
34    * Singleton instance of this class.
35    *
36    * @since 0.5
37    */
38   public static final BlankSpan INSTANCE = new BlankSpan();
39 
BlankSpan()40   private BlankSpan() {
41     super(SpanContext.INVALID, null);
42   }
43 
44   /** No-op implementation of the {@link Span#putAttribute(String, AttributeValue)} method. */
45   @Override
putAttribute(String key, AttributeValue value)46   public void putAttribute(String key, AttributeValue value) {
47     Utils.checkNotNull(key, "key");
48     Utils.checkNotNull(value, "value");
49   }
50 
51   /** No-op implementation of the {@link Span#putAttributes(Map)} method. */
52   @Override
putAttributes(Map<String, AttributeValue> attributes)53   public void putAttributes(Map<String, AttributeValue> attributes) {
54     Utils.checkNotNull(attributes, "attributes");
55   }
56 
57   /** No-op implementation of the {@link Span#addAnnotation(String, Map)} method. */
58   @Override
addAnnotation(String description, Map<String, AttributeValue> attributes)59   public void addAnnotation(String description, Map<String, AttributeValue> attributes) {
60     Utils.checkNotNull(description, "description");
61     Utils.checkNotNull(attributes, "attributes");
62   }
63 
64   /** No-op implementation of the {@link Span#addAnnotation(Annotation)} method. */
65   @Override
addAnnotation(Annotation annotation)66   public void addAnnotation(Annotation annotation) {
67     Utils.checkNotNull(annotation, "annotation");
68   }
69 
70   /** No-op implementation of the {@link Span#addNetworkEvent(NetworkEvent)} method. */
71   @Override
72   @Deprecated
addNetworkEvent(NetworkEvent networkEvent)73   public void addNetworkEvent(NetworkEvent networkEvent) {}
74 
75   /** No-op implementation of the {@link Span#addMessageEvent(MessageEvent)} method. */
76   @Override
addMessageEvent(MessageEvent messageEvent)77   public void addMessageEvent(MessageEvent messageEvent) {
78     Utils.checkNotNull(messageEvent, "messageEvent");
79   }
80 
81   /** No-op implementation of the {@link Span#addLink(Link)} method. */
82   @Override
addLink(Link link)83   public void addLink(Link link) {
84     Utils.checkNotNull(link, "link");
85   }
86 
87   @Override
setStatus(Status status)88   public void setStatus(Status status) {
89     Utils.checkNotNull(status, "status");
90   }
91 
92   /** No-op implementation of the {@link Span#end(EndSpanOptions)} method. */
93   @Override
end(EndSpanOptions options)94   public void end(EndSpanOptions options) {
95     Utils.checkNotNull(options, "options");
96   }
97 
98   @Override
toString()99   public String toString() {
100     return "BlankSpan";
101   }
102 }
103