Skip to content

Commit 51131e4

Browse files
committed
adding app engine specific label prefix to instance_name, trace_id
1 parent 7d2d3ef commit 51131e4

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ String getKey() {
7474
}
7575
}
7676

77+
private static String appEngineLabelPrefix = "appengine.googleapis.com/";
78+
7779
private static Map<String, Label[]> resourceTypeWithLabels;
7880

7981
static {
@@ -198,11 +200,12 @@ private static List<LoggingEnhancer> getEnhancers(Resource resourceType) {
198200
// Trace logging enhancer is supported on GAE Flex and Standard.
199201
case GaeAppFlex:
200202
enhancers = new ArrayList<>();
201-
enhancers.add(new LabelLoggingEnhancer(Collections.singletonList(Label.InstanceName)));
202-
enhancers.add(new TraceLoggingEnhancer());
203+
enhancers.add(new LabelLoggingEnhancer(
204+
appEngineLabelPrefix, Collections.singletonList(Label.InstanceName)));
205+
enhancers.add(new TraceLoggingEnhancer(appEngineLabelPrefix));
203206
break;
204207
case GaeAppStandard:
205-
enhancers.add(new TraceLoggingEnhancer());
208+
enhancers.add(new TraceLoggingEnhancer(appEngineLabelPrefix));
206209
break;
207210
default:
208211
enhancers = Collections.emptyList();
@@ -218,9 +221,11 @@ private static List<LoggingEnhancer> getEnhancers(Resource resourceType) {
218221
* @see <a href="https://cloud.google.com/logging/docs/api/v2/resource-list">Logging Labels</a>
219222
*/
220223
static class LabelLoggingEnhancer implements LoggingEnhancer {
224+
String prefix;
221225
List<Label> labels;
222226

223-
LabelLoggingEnhancer(List<Label> labels) {
227+
LabelLoggingEnhancer(String prefix, List<Label> labels) {
228+
this.prefix = prefix != null ? prefix : "";
224229
this.labels = labels;
225230
}
226231

@@ -229,7 +234,7 @@ public void enhanceLogEntry(Builder logEntry) {
229234
for (Label label : labels) {
230235
String labelValue = MonitoredResourceUtil.getValue(label);
231236
if (labelValue != null) {
232-
logEntry.addLabel(label.getKey(), labelValue);
237+
logEntry.addLabel(prefix + label.getKey(), labelValue);
233238
}
234239
}
235240
}

google-cloud-logging/src/main/java/com/google/cloud/logging/TraceLoggingEnhancer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
/* Adds tracing support for logging with thread-local trace ID tracking. */
2020
public class TraceLoggingEnhancer implements LoggingEnhancer {
2121

22+
String prefix;
23+
public TraceLoggingEnhancer(String prefix) {
24+
this.prefix = (prefix != null) ? prefix : "";
25+
}
26+
2227
private static final ThreadLocal<String> traceId = new ThreadLocal<>();
2328

2429
/**
@@ -43,7 +48,7 @@ public static String getCurrentTraceId() {
4348
public void enhanceLogEntry(com.google.cloud.logging.LogEntry.Builder builder) {
4449
String traceId = getCurrentTraceId();
4550
if (traceId != null) {
46-
builder.addLabel("trace_id", traceId);
51+
builder.addLabel(prefix + "trace_id", traceId);
4752
}
4853
}
4954
}

0 commit comments

Comments
 (0)