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

Commit f049c18

Browse files
authored
Temporarily remove "traceSampled" label from Stackdriver log correlation. (#1532)
Currently, opencensus-contrib-log-correlation-stackdriver adds the sampling decision to a LogEntry as a custom label. Once google-cloud-logging adds a sampling decision field to its LogEntry class, we can set that field instead, so that the value will be intepreted by Stackdriver. However, removing the custom label will be a breaking change. This commit temporarily removes the custom label so that we can make a non-experimental release of opencensus-contrib-log-correlation-stackdriver and add the sampling decision to the LogEntry later as a backwards-compatible change.
1 parent fb8cc01 commit f049c18

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

contrib/log_correlation/stackdriver/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ The `opencensus-contrib-log-correlation-stackdriver` artifact provides a
1111
that automatically adds tracing data to log entries. The class name is
1212
`OpenCensusTraceLoggingEnhancer`. `OpenCensusTraceLoggingEnhancer` adds the current trace and span
1313
ID to each log entry, which allows Stackdriver to display the log entries associated with each
14-
trace, or filter logs based on trace or span ID. It currently also adds the sampling decision using
15-
the label "`opencensusTraceSampled`".
14+
trace, or filter logs based on trace or span ID.
1615

1716
## Instructions
1817

contrib/log_correlation/stackdriver/src/main/java/io/opencensus/contrib/logcorrelation/stackdriver/OpenCensusTraceLoggingEnhancer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737
@ExperimentalApi
3838
public final class OpenCensusTraceLoggingEnhancer implements LoggingEnhancer {
39-
private static final String SAMPLED_LABEL_KEY = "opencensusTraceSampled";
4039

4140
/**
4241
* Name of the property that overrides the default project ID (overrides the value returned by
@@ -120,8 +119,7 @@ private static void addTracingData(
120119
builder.setTrace(formatTraceId(tracePrefix, span.getTraceId()));
121120
builder.setSpanId(span.getSpanId().toLowerBase16());
122121

123-
// TODO(sebright): Find the correct way to add the sampling decision.
124-
builder.addLabel(SAMPLED_LABEL_KEY, Boolean.toString(span.getTraceOptions().isSampled()));
122+
// TODO(sebright): Add the sampling decision once google-cloud-logging supports it.
125123
}
126124

127125
private static String formatTraceId(String tracePrefix, TraceId traceId) {

contrib/log_correlation/stackdriver/src/test/java/io/opencensus/contrib/logcorrelation/stackdriver/OpenCensusTraceLoggingEnhancerTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public void enhanceLogEntry_AddSampledSpanToLogEntry() {
6767
SpanId.fromLowerBase16("de52e84d13dd232d"),
6868
TraceOptions.builder().setIsSampled(true).build(),
6969
EMPTY_TRACESTATE)));
70-
assertThat(logEntry.getLabels()).containsEntry("opencensusTraceSampled", "true");
7170
assertThat(logEntry.getTrace())
7271
.isEqualTo("projects/my-test-project-3/traces/4c6af40c499951eb7de2777ba1e4fefa");
7372
assertThat(logEntry.getSpanId()).isEqualTo("de52e84d13dd232d");
@@ -84,7 +83,6 @@ public void enhanceLogEntry_AddNonSampledSpanToLogEntry() {
8483
SpanId.fromLowerBase16("731e102335b7a5a0"),
8584
TraceOptions.builder().setIsSampled(false).build(),
8685
EMPTY_TRACESTATE)));
87-
assertThat(logEntry.getLabels()).containsEntry("opencensusTraceSampled", "false");
8886
assertThat(logEntry.getTrace())
8987
.isEqualTo("projects/my-test-project-6/traces/72c905c76f99e99974afd84dc053a480");
9088
assertThat(logEntry.getSpanId()).isEqualTo("731e102335b7a5a0");
@@ -95,7 +93,6 @@ public void enhanceLogEntry_AddBlankSpanToLogEntry() {
9593
LogEntry logEntry =
9694
getEnhancedLogEntry(
9795
new OpenCensusTraceLoggingEnhancer("my-test-project-7"), BlankSpan.INSTANCE);
98-
assertThat(logEntry.getLabels().get("opencensusTraceSampled")).isEqualTo("false");
9996
assertThat(logEntry.getTrace())
10097
.isEqualTo("projects/my-test-project-7/traces/00000000000000000000000000000000");
10198
assertThat(logEntry.getSpanId()).isEqualTo("0000000000000000");

0 commit comments

Comments
 (0)