blob: dbd035cd20384ae7068595c8509f45ece5d880c2 [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 *
8 * <p>Any CDI beans registered under this class are applied to each log entry that is logged.
9 *
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020010 * <p><strong>Example:</strong>
11 *
12 * <pre>{@code
13 * @Singleton
14 * @Unremovable
15 * public final class RequestIdLabelProvider implements LabelProvider {
16 *
17 * @Override
18 * public Collection<Label> getLabels() {
19 * return List.of(Label.of("requestId", RequestContext.current().getRequestId()));
20 * }
21 * }
22 * }</pre>
23 *
24 * Result:
25 *
26 * <pre>{@code
27 * {
28 * "textPayload": "Request rejected: unauthorized.",
29 * "labels": {
30 * "requestId": "123"
31 * }
32 * }
33 * }</pre>
34 *
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020035 * @see StructuredParameterProvider
36 */
37public interface LabelProvider {
38
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020039 /**
40 * Provides a collection of {@link Label}s to add to each log entry that is logged.
41 *
42 * @return a collection of {@link Label}s to add to each log entry that is logged.
43 */
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +020044 Collection<Label> getLabels();
45}