blob: 3f5a8366a20e7994a146253525b6c7d74dabc4f5 [file] [log] [blame]
Matthias Andreas Benkardc8144a92021-05-03 08:04:53 +02001package eu.mulk.quarkus.observability.googlecloud.jsonlogging;
2
3import io.smallrye.common.constraint.Nullable;
4import java.time.Instant;
5import java.util.Map;
6import javax.json.bind.annotation.JsonbProperty;
7
8/**
9 * A JSON log entry compatible with Google Cloud Logging.
10 *
11 * <p>Roughly (but not quite) corresponds to Google Cloud Logging's
12 * <a href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">LogEntry</a>
13 * structure.
14 */
15public record GoogleCloudLogEntry(
16 String getMessage,
17 String getSeverity,
18 Timestamp getTimestamp,
19 @Nullable String getTrace,
20 @Nullable String getSpanId,
21 @Nullable SourceLocation getSourceLocation,
22 @Nullable Map<String, String> getLabels,
23 @Nullable Map<String, Object> getParameters,
24 @Nullable Map<String, String> getMappedDiagnosticContext,
25 @Nullable String getNestedDiagnosticContext,
26 @Nullable @JsonbProperty("@type") String getType) {
27
28 static public record SourceLocation(
29 @Nullable String getFile,
30 @Nullable String getLine,
31 @Nullable String getFunction) {}
32
33 static public record Timestamp(
34 long getSeconds,
35 int getNanos) {
36
37 public Timestamp(Instant t) {
38 this(t.getEpochSecond(), t.getNano());
39 }
40 }
41}