Class TagContextBuilder

java.lang.Object
io.opencensus.tags.TagContextBuilder
Direct Known Subclasses:
NoopTagMapBuilder, NoopTags.NoopTagContextBuilder, TagMapBuilderImpl

public abstract class TagContextBuilder extends Object
Builder for the TagContext class.
Since:
0.8
  • Field Details

    • METADATA_NO_PROPAGATION

      private static final TagMetadata METADATA_NO_PROPAGATION
    • METADATA_UNLIMITED_PROPAGATION

      private static final TagMetadata METADATA_UNLIMITED_PROPAGATION
  • Constructor Details

    • TagContextBuilder

      public TagContextBuilder()
  • Method Details

    • put

      @Deprecated public abstract TagContextBuilder put(TagKey key, TagValue value)
      Deprecated.
      in favor of put(TagKey, TagValue, TagMetadata), or putLocal(TagKey, TagValue) if you only want in-process tags.
      Adds the key/value pair regardless of whether the key is present.

      For backwards-compatibility this method still produces propagating Tags.

      Equivalent to calling put(key, value, TagMetadata.create(TagTtl.UNLIMITED_PROPAGATION)).

      Parameters:
      key - the TagKey which will be set.
      value - the TagValue to set for the given key.
      Returns:
      this
      Since:
      0.8
    • put

      public TagContextBuilder put(TagKey key, TagValue value, TagMetadata tagMetadata)
      Adds the key/value pair and metadata regardless of whether the key is present.
      Parameters:
      key - the TagKey which will be set.
      value - the TagValue to set for the given key.
      tagMetadata - the TagMetadata associated with this Tag.
      Returns:
      this
      Since:
      0.20
    • putLocal

      public final TagContextBuilder putLocal(TagKey key, TagValue value)
      Adds a non-propagating tag to this TagContextBuilder.

      This is equivalent to calling put(key, value, TagMetadata.create(TagTtl.NO_PROPAGATION)).

      Parameters:
      key - the TagKey which will be set.
      value - the TagValue to set for the given key.
      Returns:
      this
      Since:
      0.21
    • putPropagating

      public final TagContextBuilder putPropagating(TagKey key, TagValue value)
      Adds an unlimited propagating tag to this TagContextBuilder.

      This is equivalent to calling put(key, value, TagMetadata.create(TagTtl.METADATA_UNLIMITED_PROPAGATION)).

      Only call this method if you want propagating tags. If you want tags for breaking down metrics, or there are sensitive messages in your tags, use putLocal(TagKey, TagValue) instead.

      Parameters:
      key - the TagKey which will be set.
      value - the TagValue to set for the given key.
      Returns:
      this
      Since:
      0.21
    • remove

      public abstract TagContextBuilder remove(TagKey key)
      Removes the key if it exists.
      Parameters:
      key - the TagKey which will be removed.
      Returns:
      this
      Since:
      0.8
    • build

      public abstract TagContext build()
      Creates a TagContext from this builder.
      Returns:
      a TagContext with the same tags as this builder.
      Since:
      0.8
    • buildScoped

      public abstract Scope buildScoped()
      Enters the scope of code where the TagContext created from this builder is in the current context and returns an object that represents that scope. The scope is exited when the returned object is closed.
      Returns:
      an object that defines a scope where the TagContext created from this builder is set to the current context.
      Since:
      0.8