blob: 8cf87db94e5d45b58102d0879feb9ca7defa76ec [file] [log] [blame]
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +02001package eu.mulk.quarkus.googlecloud.jsonlogging;
2
3import java.util.Collection;
4
5/**
6 * A user-supplied provider for {@link Label}s.
7 *
Matthias Andreas Benkard20210242022-01-15 10:39:30 +01008 * <p>Instances of this interface that are registered with the {@link Formatter} are applied to each
9 * log entry that is logged.
10 *
11 * <p>If you are using the Quarkus extension, any CDI beans registered under this interface are
12 * registered automatically.
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020013 *
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020014 * <p><strong>Example:</strong>
15 *
16 * <pre>{@code
17 * @Singleton
18 * @Unremovable
19 * public final class RequestIdLabelProvider implements LabelProvider {
20 *
21 * @Override
22 * public Collection<Label> getLabels() {
23 * return List.of(Label.of("requestId", RequestContext.current().getRequestId()));
24 * }
25 * }
26 * }</pre>
27 *
28 * Result:
29 *
30 * <pre>{@code
31 * {
32 * "textPayload": "Request rejected: unauthorized.",
33 * "labels": {
34 * "requestId": "123"
35 * }
36 * }
37 * }</pre>
38 *
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020039 * @see StructuredParameterProvider
40 */
41public interface LabelProvider {
42
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020043 /**
44 * Provides a collection of {@link Label}s to add to each log entry that is logged.
45 *
46 * @return a collection of {@link Label}s to add to each log entry that is logged.
47 */
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020048 Collection<Label> getLabels();
49}