Matthias Andreas Benkard | c8144a9 | 2021-05-03 08:04:53 +0200 | [diff] [blame^] | 1 | package eu.mulk.quarkus.observability.googlecloud.jsonlogging; |
| 2 | |
| 3 | import io.smallrye.common.constraint.Nullable; |
| 4 | import java.time.Instant; |
| 5 | import java.util.Map; |
| 6 | import 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 | */ |
| 15 | public 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 | } |