Rename headers to header.
This commit is contained in:
parent
0edd98d7a4
commit
7403b04efd
5 changed files with 43 additions and 43 deletions
|
@ -6,7 +6,7 @@
|
|||
* [add default xml](docs/features/logback_default.md)
|
||||
* [preconfigured appender for different environments](docs/features/logback_appender.md)
|
||||
* [set log level based on HTTP request header](docs/features/http_log_level.md)
|
||||
* [add HTTP headers to MDC](docs/features/http_mdc_headers.md)
|
||||
* [add HTTP header to MDC](docs/features/http_mdc_header.md)
|
||||
* [add authentication information from HTTP request to MDC](docs/features/http_mdc_authentication.md)
|
||||
|
||||
## Development
|
||||
|
|
28
docs/features/http_mdc_header.md
Normal file
28
docs/features/http_mdc_header.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Add HTTP headers to MDC
|
||||
|
||||
## Properties
|
||||
|
||||
Property | Description | Default
|
||||
-------- | ----------- | -------
|
||||
`logger.http.header.enabled` | filter enabled? | `true`
|
||||
`logger.http.header.path` | filter path | `/**`
|
||||
`logger.http.header.order` | order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/v3.2.0/core/src/main/java/io/micronaut/core/order/Ordered.java) | [ServerFilterPhase.FIRST.before()](https://github.com/micronaut-projects/micronaut-core/blob/v3.2.0/http/src/main/java/io/micronaut/http/filter/ServerFilterPhase.java#L34)
|
||||
`logger.http.header.prefix` | prefix to MDC key | ``
|
||||
`logger.http.header.names` | http header names to add to MDC | `[]`
|
||||
|
||||
## Examples
|
||||
|
||||
Configuration for b3-propagation:
|
||||
|
||||
```yaml
|
||||
logger:
|
||||
http:
|
||||
header:
|
||||
prefix: header.
|
||||
names:
|
||||
- x-request-id
|
||||
- x-b3-traceId
|
||||
- x-b3-parentspanid
|
||||
- x-b3-spanid
|
||||
- x-b3-sampled
|
||||
```
|
|
@ -1,28 +0,0 @@
|
|||
# Add HTTP headers to MDC
|
||||
|
||||
## Properties
|
||||
|
||||
Property | Description | Default
|
||||
-------- | ----------- | -------
|
||||
`logger.http.headers.enabled` | filter enabled? | `true`
|
||||
`logger.http.headers.path` | filter path | `/**`
|
||||
`logger.http.headers.order` | order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/v3.2.0/core/src/main/java/io/micronaut/core/order/Ordered.java) | [ServerFilterPhase.FIRST.before()](https://github.com/micronaut-projects/micronaut-core/blob/v3.2.0/http/src/main/java/io/micronaut/http/filter/ServerFilterPhase.java#L34)
|
||||
`logger.http.headers.prefix` | prefix to MDC key | ``
|
||||
`logger.http.headers.names` | http header names to add to MDC | `[]`
|
||||
|
||||
## Examples
|
||||
|
||||
Configuration for b3-propagation:
|
||||
|
||||
```yaml
|
||||
logger:
|
||||
http:
|
||||
headers:
|
||||
prefix: header.
|
||||
names:
|
||||
- x-request-id
|
||||
- x-b3-traceId
|
||||
- x-b3-parentspanid
|
||||
- x-b3-spanid
|
||||
- x-b3-sampled
|
||||
```
|
|
@ -26,18 +26,18 @@ import lombok.extern.slf4j.Slf4j;
|
|||
* @author Stephan Schnabel
|
||||
*/
|
||||
@Refreshable
|
||||
@Requires(property = HttpHeadersMdcFilter.PREFIX + ".enabled", notEquals = StringUtils.FALSE)
|
||||
@Requires(property = HttpHeadersMdcFilter.PREFIX + ".names")
|
||||
@Filter("${" + HttpHeadersMdcFilter.PREFIX + ".path:/**}")
|
||||
@Requires(property = HeaderMdcFilter.PREFIX + ".enabled", notEquals = StringUtils.FALSE)
|
||||
@Requires(property = HeaderMdcFilter.PREFIX + ".names")
|
||||
@Filter("${" + HeaderMdcFilter.PREFIX + ".path:/**}")
|
||||
@Slf4j
|
||||
public class HttpHeadersMdcFilter extends AbstractMdcFilter {
|
||||
public class HeaderMdcFilter extends AbstractMdcFilter {
|
||||
|
||||
public static final String PREFIX = "logger.http.headers";
|
||||
public static final String PREFIX = "logger.http.header";
|
||||
public static final int DEFAULT_ORDER = ServerFilterPhase.FIRST.before();
|
||||
|
||||
private final Set<String> headers;
|
||||
|
||||
public HttpHeadersMdcFilter(
|
||||
public HeaderMdcFilter(
|
||||
@Value("${" + PREFIX + ".names}") List<String> headers,
|
||||
@Value("${" + PREFIX + ".prefix}") Optional<String> prefix,
|
||||
@Value("${" + PREFIX + ".order}") Optional<Integer> order) {
|
|
@ -11,12 +11,12 @@ import io.kokuwa.micronaut.logging.http.AbstractFilterTest;
|
|||
import io.micronaut.context.annotation.Property;
|
||||
|
||||
/**
|
||||
* Test for {@link HttpHeadersMdcFilter}.
|
||||
* Test for {@link HeaderMdcFilter}.
|
||||
*
|
||||
* @author Stephan Schnabel
|
||||
*/
|
||||
@DisplayName("http: mdc from headers")
|
||||
public class HttpHeadersMdcFilterTest extends AbstractFilterTest {
|
||||
public class HeaderMdcFilterTest extends AbstractFilterTest {
|
||||
|
||||
@DisplayName("noop: empty configuration")
|
||||
@Test
|
||||
|
@ -26,30 +26,30 @@ public class HttpHeadersMdcFilterTest extends AbstractFilterTest {
|
|||
|
||||
@DisplayName("noop: disabled")
|
||||
@Test
|
||||
@Property(name = "logger.http.headers.enabled", value = "false")
|
||||
@Property(name = "logger.http.headers.names", value = "foo")
|
||||
@Property(name = "logger.http.header.enabled", value = "false")
|
||||
@Property(name = "logger.http.header.names", value = "foo")
|
||||
void noopDisabled() {
|
||||
assertContext(Map.of(), Map.of("foo", "bar"));
|
||||
}
|
||||
|
||||
@DisplayName("mdc: mismatch")
|
||||
@Test
|
||||
@Property(name = "logger.http.headers.names", value = "foo")
|
||||
@Property(name = "logger.http.header.names", value = "foo")
|
||||
void mdcMismatch() {
|
||||
assertContext(Map.of(), Map.of("nope", "bar"));
|
||||
}
|
||||
|
||||
@DisplayName("mdc: match without prefix")
|
||||
@Test
|
||||
@Property(name = "logger.http.headers.names", value = "foo")
|
||||
@Property(name = "logger.http.header.names", value = "foo")
|
||||
void mdcMatchWithoutPrefix() {
|
||||
assertContext(Map.of("foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
||||
}
|
||||
|
||||
@DisplayName("mdc: match with prefix")
|
||||
@Test
|
||||
@Property(name = "logger.http.headers.names", value = "foo")
|
||||
@Property(name = "logger.http.headers.prefix", value = "header.")
|
||||
@Property(name = "logger.http.header.names", value = "foo")
|
||||
@Property(name = "logger.http.header.prefix", value = "header.")
|
||||
void mdcMatchWithPrefix() {
|
||||
assertContext(Map.of("header.foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue