blob: 0450d0c1679af46cd09ef7c2077e82994c95e50c [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 *
Matthias Andreas Benkard4bae5f12021-05-03 19:16:48 +020011 * <p>Roughly (but not quite) corresponds to Google Cloud Logging's <a
12 * href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">LogEntry</a>
Matthias Andreas Benkardc8144a92021-05-03 08:04:53 +020013 * 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
Matthias Andreas Benkard4bae5f12021-05-03 19:16:48 +020028 public static record SourceLocation(
29 @Nullable String getFile, @Nullable String getLine, @Nullable String getFunction) {}
Matthias Andreas Benkardc8144a92021-05-03 08:04:53 +020030
Matthias Andreas Benkard4bae5f12021-05-03 19:16:48 +020031 public static record Timestamp(long getSeconds, int getNanos) {
Matthias Andreas Benkardc8144a92021-05-03 08:04:53 +020032
33 public Timestamp(Instant t) {
34 this(t.getEpochSecond(), t.getNano());
35 }
36 }
37}