summaryrefslogtreecommitdiff
path: root/runtime/src/main/java/eu/mulk/quarkus/observability/googlecloud/jsonlogging/GoogleCloudLogEntry.java
blob: 0450d0c1679af46cd09ef7c2077e82994c95e50c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package eu.mulk.quarkus.observability.googlecloud.jsonlogging;

import io.smallrye.common.constraint.Nullable;
import java.time.Instant;
import java.util.Map;
import javax.json.bind.annotation.JsonbProperty;

/**
 * A JSON log entry compatible with Google Cloud Logging.
 *
 * <p>Roughly (but not quite) corresponds to Google Cloud Logging's <a
 * href="https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry">LogEntry</a>
 * structure.
 */
public record GoogleCloudLogEntry(
    String getMessage,
    String getSeverity,
    Timestamp getTimestamp,
    @Nullable String getTrace,
    @Nullable String getSpanId,
    @Nullable SourceLocation getSourceLocation,
    @Nullable Map<String, String> getLabels,
    @Nullable Map<String, Object> getParameters,
    @Nullable Map<String, String> getMappedDiagnosticContext,
    @Nullable String getNestedDiagnosticContext,
    @Nullable @JsonbProperty("@type") String getType) {

  public static record SourceLocation(
      @Nullable String getFile, @Nullable String getLine, @Nullable String getFunction) {}

  public static record Timestamp(long getSeconds, int getNanos) {

    public Timestamp(Instant t) {
      this(t.getEpochSecond(), t.getNano());
    }
  }
}