Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit fbd628f

Browse files
authored
Tags: Add TagContextBuilder.putPropagating(). (#1852)
1 parent 7dc2112 commit fbd628f

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
- Add an option to allow users to override the default "opencensus_task" metric label in Stackdriver Stats Exporter.
55
- Allow setting custom namespace in Prometheus exporter.
66
- Add Cumulative (`DoubleCumulative`, `LongCumulative`, `DerivedDoubleCumulative`, `DerivedLongCumulative`) APIs.
7-
- Add a convenient API `TagContextBuilder.putLocal()` that adds non-propagating tags.
7+
- Add convenience APIs `TagContextBuilder.putLocal()` that adds non-propagating tags,
8+
and `TagContextBuilder.putPropagating()` that adds unlimited propagating tags.
89

910
## 0.20.0 - 2019-03-28
1011
- Add OpenCensus Java OC-Agent Trace Exporter.

api/src/main/java/io/opencensus/tags/TagContextBuilder.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public abstract class TagContextBuilder {
2828

2929
private static final TagMetadata METADATA_NO_PROPAGATION =
3030
TagMetadata.create(TagTtl.NO_PROPAGATION);
31+
private static final TagMetadata METADATA_UNLIMITED_PROPAGATION =
32+
TagMetadata.create(TagTtl.UNLIMITED_PROPAGATION);
3133

3234
/**
3335
* Adds the key/value pair regardless of whether the key is present.
@@ -77,6 +79,25 @@ public final TagContextBuilder putLocal(TagKey key, TagValue value) {
7779
return put(key, value, METADATA_NO_PROPAGATION);
7880
}
7981

82+
/**
83+
* Adds an unlimited propagating tag to this {@code TagContextBuilder}.
84+
*
85+
* <p>This is equivalent to calling {@code put(key, value,
86+
* TagMetadata.create(TagTtl.METADATA_UNLIMITED_PROPAGATION))}.
87+
*
88+
* <p>Only call this method if you want propagating tags. If you want tags for breaking down
89+
* metrics, or there are sensitive messages in your tags, use {@link #putLocal(TagKey, TagValue)}
90+
* instead.
91+
*
92+
* @param key the {@code TagKey} which will be set.
93+
* @param value the {@code TagValue} to set for the given key.
94+
* @return this
95+
* @since 0.21
96+
*/
97+
public final TagContextBuilder putPropagating(TagKey key, TagValue value) {
98+
return put(key, value, METADATA_UNLIMITED_PROPAGATION);
99+
}
100+
80101
/**
81102
* Removes the key if it exists.
82103
*

impl_core/src/test/java/io/opencensus/implcore/tags/TagMapImplTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public void putLocal() {
120120
assertThat(tags1).isEqualTo(tags2);
121121
}
122122

123+
@Test
124+
public void putPropagating() {
125+
TagContext tags1 = tagger.emptyBuilder().put(K1, V1, METADATA_UNLIMITED_PROPAGATION).build();
126+
TagContext tags2 = tagger.emptyBuilder().putPropagating(K1, V1).build();
127+
assertThat(tags1).isEqualTo(tags2);
128+
}
129+
123130
@Test
124131
public void remove_existingKey() {
125132
TagContext tags = new TagMapImpl(ImmutableMap.of(K1, VM1, K2, VM2));

0 commit comments

Comments
 (0)