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

Commit 6ef5b77

Browse files
authored
Add a note about recording with extra tags. (#145)
* Add a note about recording with extra tags. * Add a code example to reflect this change. * Split the code examples. * Slightly reword on non-propagating.
1 parent 9815b40 commit 6ef5b77

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

stats/Record.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ contextual information of an exemplar, for example trace id, span id or dropped
5151
## Recording Stats
5252

5353
Users should record Measurements against a context, either an explicit context or the implicit
54-
current context. Tags from the context are recorded with the Measurements if they are any.
54+
current context. Tags from the context are recorded with the Measurements if they are any.
55+
When recording against an explicit context, implmentations should allow users to add extra tags,
56+
and those tags should not be added to current context..
57+
5558
Note that there is no implicit recording for exemplars. If you want to record a `Measurement`
5659
against an exemplar, you have to explicitly pass a string-string map.
5760

@@ -64,16 +67,33 @@ argument. e.g. `record(List<Measurement>)` or `record(...Measurement)`.
6467
Example in Java
6568

6669
```java
70+
// Static constants.
6771
private static final MeasureDouble RPC_LATENCY =
6872
MeasureDouble.create("grpc.io/client/latency", "latency", "ms");
6973
private static final MeasureLong RPC_BYTES_SENT =
7074
MeasureLong.create("grpc.io/client/bytes_sent", "bytes sent", "kb");
75+
private static final TagKey MY_KEY = TagKey.create("my.org/key");
76+
```
7177

78+
```java
79+
// Record against implicit context.
7280
MeasurementMap measurementMap = new MeasurementMap();
7381
measurementMap.put(RPC_LATENCY, 10.3);
7482
measurementMap.put(RPC_BYTES_SENT, 124);
7583
measurementMap.record(); // reads context from thread-local.
84+
```
7685

86+
```java
87+
// Record against explicit context.
88+
MeasurementMap measurementMap = new MeasurementMap();
89+
measurementMap.put(RPC_LATENCY, 15);
90+
measurementMap.put(RPC_BYTES_SENT, 200);
91+
TagValue value = TagValue.create("some value");
92+
measurementMap.record(
93+
Tags.getTagger().currentBuilder().put(MY_KEY, value).build()); // record against an extra tag.
94+
```
95+
96+
```java
7797
// Another example on recording against sampled SpanContext.
7898
SpanContext spanContext = tracer.getCurrentSpan().getContext();
7999
if (spanContext.getTraceOptions().isSampled()) {

0 commit comments

Comments
 (0)