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

Commit e35df43

Browse files
authored
Hide methods in OpenCensusTraceLoggingEnhancer that aren't necessary currently. (#1538)
Code that creates or uses OpenCensusTraceLoggingEnhancer probably won't know its type, so it will only call the no-arg constructor and 'enhanceLogEntry'. This commit hides the other methods in the class, create(String) and getProjectId(). They can be re-exposed in the future if necessary.
1 parent 71dba4a commit e35df43

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,12 @@ public OpenCensusTraceLoggingEnhancer() {
6363
this(lookUpProjectId());
6464
}
6565

66-
private OpenCensusTraceLoggingEnhancer(@Nullable String projectId) {
66+
// visible for testing
67+
OpenCensusTraceLoggingEnhancer(@Nullable String projectId) {
6768
this.projectId = projectId == null ? "" : projectId;
6869
this.tracePrefix = "projects/" + this.projectId + "/traces/";
6970
}
7071

71-
/**
72-
* Returns a {@code OpenCensusTraceLoggingEnhancer} with the given project ID.
73-
*
74-
* @param projectId the project ID to be used by the logging enhancer.
75-
* @return a {@code OpenCensusTraceLoggingEnhancer} with the given project ID.
76-
* @since 0.17
77-
*/
78-
public static OpenCensusTraceLoggingEnhancer create(@Nullable String projectId) {
79-
return new OpenCensusTraceLoggingEnhancer(projectId);
80-
}
81-
8272
private static String lookUpProjectId() {
8373
String projectIdProperty = lookUpProperty(PROJECT_ID_PROPERTY_NAME);
8474
return projectIdProperty == null || projectIdProperty.isEmpty()
@@ -94,13 +84,8 @@ private static String lookUpProperty(String name) {
9484
return property == null || property.isEmpty() ? System.getProperty(name) : property;
9585
}
9686

97-
/**
98-
* Returns the project ID setting for this instance.
99-
*
100-
* @return the project ID setting for this instance.
101-
* @since 0.15
102-
*/
103-
public String getProjectId() {
87+
// visible for testing
88+
String getProjectId() {
10489
return projectId;
10590
}
10691

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class OpenCensusTraceLoggingEnhancerTest {
6060
public void enhanceLogEntry_AddSampledSpanToLogEntry() {
6161
LogEntry logEntry =
6262
getEnhancedLogEntry(
63-
OpenCensusTraceLoggingEnhancer.create("my-test-project-3"),
63+
new OpenCensusTraceLoggingEnhancer("my-test-project-3"),
6464
new TestSpan(
6565
SpanContext.create(
6666
TraceId.fromLowerBase16("4c6af40c499951eb7de2777ba1e4fefa"),
@@ -76,7 +76,7 @@ public void enhanceLogEntry_AddSampledSpanToLogEntry() {
7676
public void enhanceLogEntry_AddNonSampledSpanToLogEntry() {
7777
LogEntry logEntry =
7878
getEnhancedLogEntry(
79-
OpenCensusTraceLoggingEnhancer.create("my-test-project-6"),
79+
new OpenCensusTraceLoggingEnhancer("my-test-project-6"),
8080
new TestSpan(
8181
SpanContext.create(
8282
TraceId.fromLowerBase16("72c905c76f99e99974afd84dc053a480"),
@@ -92,7 +92,7 @@ public void enhanceLogEntry_AddNonSampledSpanToLogEntry() {
9292
public void enhanceLogEntry_AddBlankSpanToLogEntry() {
9393
LogEntry logEntry =
9494
getEnhancedLogEntry(
95-
OpenCensusTraceLoggingEnhancer.create("my-test-project-7"), BlankSpan.INSTANCE);
95+
new OpenCensusTraceLoggingEnhancer("my-test-project-7"), BlankSpan.INSTANCE);
9696
assertThat(logEntry.getTrace())
9797
.isEqualTo("projects/my-test-project-7/traces/00000000000000000000000000000000");
9898
assertThat(logEntry.getSpanId()).isEqualTo("0000000000000000");
@@ -102,7 +102,7 @@ public void enhanceLogEntry_AddBlankSpanToLogEntry() {
102102
public void enhanceLogEntry_ConvertNullProjectIdToEmptyString() {
103103
LogEntry logEntry =
104104
getEnhancedLogEntry(
105-
OpenCensusTraceLoggingEnhancer.create(null),
105+
new OpenCensusTraceLoggingEnhancer(null),
106106
new TestSpan(
107107
SpanContext.create(
108108
TraceId.fromLowerBase16("bfb4248a24325a905873a1d43001d9a0"),

0 commit comments

Comments
 (0)