blob: decf9372da9ab9d22674ed32a9d2424e22e485af [file] [log] [blame]
Matthias Andreas Benkard82d7e442021-08-29 08:34:11 +02001package eu.mulk.quarkus.googlecloud.jsonlogging;
2
3/**
4 * A user-supplied provider for {@link StructuredParameter}s.
5 *
Matthias Andreas Benkard20210242022-01-15 10:39:30 +01006 * <p>Instances of this interface that are registered with the {@link Formatter} are applied to each
7 * log entry that is logged.
8 *
9 * <p>If you are using the Quarkus extension, any CDI beans registered under this interface are
10 * registered automatically.
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020011 *
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020012 * <p><strong>Example:</strong>
13 *
14 * <pre>{@code
15 * @Singleton
16 * @Unremovable
17 * public final class TraceLogParameterProvider implements StructuredParameterProvider {
18 *
19 * @Override
20 * public StructuredParameter getParameter() {
21 * var b = Json.createObjectBuilder();
22 * b.add("traceId", Span.current().getSpanContext().getTraceId());
23 * b.add("spanId", Span.current().getSpanContext().getSpanId());
24 * return () -> b;
25 * }
26 * }
27 * }</pre>
28 *
29 * Result:
30 *
31 * <pre>{@code
32 * {
33 * "jsonPayload": {
34 * "message": "Request rejected: unauthorized.",
35 * "traceId": "39f9a49a9567a8bd7087b708f8932550",
36 * "spanId": "c7431b14630b633d"
37 * }
38 * }
39 * }</pre>
40 *
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020041 * @see LabelProvider
Matthias Andreas Benkard82d7e442021-08-29 08:34:11 +020042 */
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020043public interface StructuredParameterProvider {
Matthias Andreas Benkard82d7e442021-08-29 08:34:11 +020044
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020045 /**
46 * Provides a {@link StructuredParameter} to add to each log entry that is logged.
47 *
48 * <p>It is often useful to return a custom {@link StructuredParameter} rather than a {@link
49 * KeyValueParameter} from this method. This way multiple key–value pairs can be generated by a
50 * single invocation.
51 *
52 * @return a {@link StructuredParameter} to add to each log entry that is logged.
53 */
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020054 StructuredParameter getParameter();
Matthias Andreas Benkard82d7e442021-08-29 08:34:11 +020055}