Skip to content

Commit e8e8dee

Browse files
Bogdan Drutuchingor13
authored andcommitted
---
yaml --- r: 12101 b: refs/heads/autosynth-errorreporting c: fac25a3 h: refs/heads/master i: 12099: 1dd1bdb
1 parent 737a878 commit e8e8dee

3 files changed

Lines changed: 48 additions & 19 deletions

File tree

  • branches/autosynth-errorreporting/google-cloud-clients/google-cloud-logging/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 781fdb430a60f9a6491f116e31e4e10118157bdb
132132
refs/heads/autosynth-datastore: af1fb76aa3eee02fe6f31f8fa1c72a4f048d149b
133133
refs/heads/autosynth-dialogflow: ebdd13c445b9674ff9ad4601f78d7ecd6f9c3660
134-
refs/heads/autosynth-errorreporting: 0a60b05d0c0c378a5da58c52e832b685db2721b3
134+
refs/heads/autosynth-errorreporting: fac25a3bb519bdd0685008108df73b5870ec7ba5
135135
refs/heads/autosynth-firestore: 450623a0568a156847a97f05d0ea5aeeeeaca698
136136
refs/heads/autosynth-iot: 2a21f544087dee8f5b5802779ff9e2a70c1acdca
137137
refs/heads/autosynth-kms: 44920781bf79d494a1835207fc7110b743a1d7d4

branches/autosynth-errorreporting/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public LogEntry apply(com.google.logging.v2.LogEntry pb) {
6565
private final HttpRequest httpRequest;
6666
private final Map<String, String> labels;
6767
private final Operation operation;
68-
private final String trace;
69-
private final String spanId;
68+
private final Object trace;
69+
private final Object spanId;
7070
private final boolean traceSampled;
7171
private final SourceLocation sourceLocation;
7272
private final Payload<?> payload;
@@ -85,8 +85,8 @@ public static class Builder {
8585
private HttpRequest httpRequest;
8686
private Map<String, String> labels = new HashMap<>();
8787
private Operation operation;
88-
private String trace;
89-
private String spanId;
88+
private Object trace;
89+
private Object spanId;
9090
private boolean traceSampled;
9191
private SourceLocation sourceLocation;
9292
private Payload<?> payload;
@@ -223,7 +223,6 @@ public Builder setOperation(Operation operation) {
223223
return this;
224224
}
225225

226-
227226
/**
228227
* Sets the resource name of the trace associated with the log entry, if any. If it contains a
229228
* relative resource name, the name is assumed to be relative to `//tracing.googleapis.com`.
@@ -233,6 +232,14 @@ public Builder setTrace(String trace) {
233232
return this;
234233
}
235234

235+
/**
236+
* Sets the resource name of the trace associated with the log entry, if any. If it contains a
237+
* relative resource name, the name is assumed to be relative to `//tracing.googleapis.com`.
238+
*/
239+
public Builder setTrace(Object trace) {
240+
this.trace = trace;
241+
return this;
242+
}
236243

237244
/**
238245
* Sets the ID of the trace span associated with the log entry, if any.
@@ -242,6 +249,14 @@ public Builder setSpanId(String spanId) {
242249
return this;
243250
}
244251

252+
/**
253+
* Sets the ID of the trace span associated with the log entry, if any.
254+
*/
255+
public Builder setSpanId(Object spanId) {
256+
this.spanId = spanId;
257+
return this;
258+
}
259+
245260

246261
/**
247262
* Sets the sampling decision of the trace span associated with the log entry.
@@ -385,15 +400,17 @@ public Operation getOperation() {
385400
* relative resource name, the name is assumed to be relative to `//tracing.googleapis.com`.
386401
*/
387402
public String getTrace() {
388-
return trace;
403+
// For backwards compatibility return null when trace not set instead of "null".
404+
return trace == null ? null : String.valueOf(trace);
389405
}
390406

391407

392408
/**
393409
* Returns the ID of the trace span associated with the log entry, if any.
394410
*/
395411
public String getSpanId() {
396-
return spanId;
412+
// For backwards compatibility return null when spanId not set instead of "null".
413+
return spanId == null ? null : String.valueOf(spanId);
397414
}
398415

399416

@@ -429,7 +446,7 @@ public <T extends Payload> T getPayload() {
429446
@Override
430447
public int hashCode() {
431448
return Objects.hash(logName, resource, timestamp, receiveTimestamp, severity, insertId,
432-
httpRequest, labels, operation, trace, spanId, traceSampled, sourceLocation, payload);
449+
httpRequest, labels, operation, getTrace(), getSpanId(), traceSampled, sourceLocation, payload);
433450
}
434451

435452
@Override
@@ -450,8 +467,8 @@ public boolean equals(Object obj) {
450467
&& Objects.equals(httpRequest, other.httpRequest)
451468
&& Objects.equals(labels, other.labels)
452469
&& Objects.equals(operation, other.operation)
453-
&& Objects.equals(trace, other.trace)
454-
&& Objects.equals(spanId, other.spanId)
470+
&& Objects.equals(getTrace(), other.getTrace())
471+
&& Objects.equals(getSpanId(), other.getSpanId())
455472
&& Objects.equals(traceSampled, other.traceSampled)
456473
&& Objects.equals(sourceLocation, other.sourceLocation)
457474
&& Objects.equals(payload, other.payload);
@@ -524,10 +541,10 @@ com.google.logging.v2.LogEntry toPb(String projectId) {
524541
builder.setOperation(operation.toPb());
525542
}
526543
if (trace != null) {
527-
builder.setTrace(trace);
544+
builder.setTrace(getTrace());
528545
}
529546
if (spanId != null) {
530-
builder.setSpanId(spanId);
547+
builder.setSpanId(getSpanId());
531548
}
532549
builder.setTraceSampled(traceSampled);
533550
if (sourceLocation != null) {

branches/autosynth-errorreporting/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LogEntryTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ public class LogEntryTest {
5151
ImmutableMap.of("key1", "value1", "key2", "value2");
5252
private static final Operation OPERATION = Operation.of("id", "producer");
5353
private static final String TRACE = "trace";
54+
private static final Object TRACE_FORMATTER = new Object() {
55+
@Override
56+
public String toString() {
57+
return TRACE;
58+
}
59+
};
5460
private static final String SPAN_ID = "spanId";
61+
private static final Object SPAN_ID_FORMATTER = new Object() {
62+
@Override
63+
public String toString() {
64+
return SPAN_ID;
65+
}
66+
};
5567
private static final boolean TRACE_SAMPLED = true;
5668
private static final SourceLocation SOURCE_LOCATION = new SourceLocation.Builder()
5769
.setFile("file")
@@ -73,8 +85,8 @@ public class LogEntryTest {
7385
.setHttpRequest(HTTP_REQUEST)
7486
.setLabels(LABELS)
7587
.setOperation(OPERATION)
76-
.setTrace(TRACE)
77-
.setSpanId(SPAN_ID)
88+
.setTrace(TRACE_FORMATTER)
89+
.setSpanId(SPAN_ID_FORMATTER)
7890
.setTraceSampled(TRACE_SAMPLED)
7991
.setSourceLocation(SOURCE_LOCATION)
8092
.build();
@@ -88,8 +100,8 @@ public class LogEntryTest {
88100
.setHttpRequest(HTTP_REQUEST)
89101
.setLabels(LABELS)
90102
.setOperation(OPERATION)
91-
.setTrace(TRACE)
92-
.setSpanId(SPAN_ID)
103+
.setTrace(TRACE_FORMATTER)
104+
.setSpanId(SPAN_ID_FORMATTER)
93105
.setTraceSampled(TRACE_SAMPLED)
94106
.setSourceLocation(SOURCE_LOCATION)
95107
.build();
@@ -103,8 +115,8 @@ public class LogEntryTest {
103115
.setHttpRequest(HTTP_REQUEST)
104116
.setLabels(LABELS)
105117
.setOperation(OPERATION)
106-
.setTrace(TRACE)
107-
.setSpanId(SPAN_ID)
118+
.setTrace(TRACE_FORMATTER)
119+
.setSpanId(SPAN_ID_FORMATTER)
108120
.setTraceSampled(TRACE_SAMPLED)
109121
.setSourceLocation(SOURCE_LOCATION)
110122
.build();

0 commit comments

Comments
 (0)