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)
|
* [add default xml](docs/features/logback_default.md)
|
||||||
* [preconfigured appender for different environments](docs/features/logback_appender.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)
|
* [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)
|
* [add authentication information from HTTP request to MDC](docs/features/http_mdc_authentication.md)
|
||||||
|
|
||||||
## Development
|
## 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
|
* @author Stephan Schnabel
|
||||||
*/
|
*/
|
||||||
@Refreshable
|
@Refreshable
|
||||||
@Requires(property = HttpHeadersMdcFilter.PREFIX + ".enabled", notEquals = StringUtils.FALSE)
|
@Requires(property = HeaderMdcFilter.PREFIX + ".enabled", notEquals = StringUtils.FALSE)
|
||||||
@Requires(property = HttpHeadersMdcFilter.PREFIX + ".names")
|
@Requires(property = HeaderMdcFilter.PREFIX + ".names")
|
||||||
@Filter("${" + HttpHeadersMdcFilter.PREFIX + ".path:/**}")
|
@Filter("${" + HeaderMdcFilter.PREFIX + ".path:/**}")
|
||||||
@Slf4j
|
@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();
|
public static final int DEFAULT_ORDER = ServerFilterPhase.FIRST.before();
|
||||||
|
|
||||||
private final Set<String> headers;
|
private final Set<String> headers;
|
||||||
|
|
||||||
public HttpHeadersMdcFilter(
|
public HeaderMdcFilter(
|
||||||
@Value("${" + PREFIX + ".names}") List<String> headers,
|
@Value("${" + PREFIX + ".names}") List<String> headers,
|
||||||
@Value("${" + PREFIX + ".prefix}") Optional<String> prefix,
|
@Value("${" + PREFIX + ".prefix}") Optional<String> prefix,
|
||||||
@Value("${" + PREFIX + ".order}") Optional<Integer> order) {
|
@Value("${" + PREFIX + ".order}") Optional<Integer> order) {
|
|
@ -11,12 +11,12 @@ import io.kokuwa.micronaut.logging.http.AbstractFilterTest;
|
||||||
import io.micronaut.context.annotation.Property;
|
import io.micronaut.context.annotation.Property;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link HttpHeadersMdcFilter}.
|
* Test for {@link HeaderMdcFilter}.
|
||||||
*
|
*
|
||||||
* @author Stephan Schnabel
|
* @author Stephan Schnabel
|
||||||
*/
|
*/
|
||||||
@DisplayName("http: mdc from headers")
|
@DisplayName("http: mdc from headers")
|
||||||
public class HttpHeadersMdcFilterTest extends AbstractFilterTest {
|
public class HeaderMdcFilterTest extends AbstractFilterTest {
|
||||||
|
|
||||||
@DisplayName("noop: empty configuration")
|
@DisplayName("noop: empty configuration")
|
||||||
@Test
|
@Test
|
||||||
|
@ -26,30 +26,30 @@ public class HttpHeadersMdcFilterTest extends AbstractFilterTest {
|
||||||
|
|
||||||
@DisplayName("noop: disabled")
|
@DisplayName("noop: disabled")
|
||||||
@Test
|
@Test
|
||||||
@Property(name = "logger.http.headers.enabled", value = "false")
|
@Property(name = "logger.http.header.enabled", value = "false")
|
||||||
@Property(name = "logger.http.headers.names", value = "foo")
|
@Property(name = "logger.http.header.names", value = "foo")
|
||||||
void noopDisabled() {
|
void noopDisabled() {
|
||||||
assertContext(Map.of(), Map.of("foo", "bar"));
|
assertContext(Map.of(), Map.of("foo", "bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("mdc: mismatch")
|
@DisplayName("mdc: mismatch")
|
||||||
@Test
|
@Test
|
||||||
@Property(name = "logger.http.headers.names", value = "foo")
|
@Property(name = "logger.http.header.names", value = "foo")
|
||||||
void mdcMismatch() {
|
void mdcMismatch() {
|
||||||
assertContext(Map.of(), Map.of("nope", "bar"));
|
assertContext(Map.of(), Map.of("nope", "bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("mdc: match without prefix")
|
@DisplayName("mdc: match without prefix")
|
||||||
@Test
|
@Test
|
||||||
@Property(name = "logger.http.headers.names", value = "foo")
|
@Property(name = "logger.http.header.names", value = "foo")
|
||||||
void mdcMatchWithoutPrefix() {
|
void mdcMatchWithoutPrefix() {
|
||||||
assertContext(Map.of("foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
assertContext(Map.of("foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("mdc: match with prefix")
|
@DisplayName("mdc: match with prefix")
|
||||||
@Test
|
@Test
|
||||||
@Property(name = "logger.http.headers.names", value = "foo")
|
@Property(name = "logger.http.header.names", value = "foo")
|
||||||
@Property(name = "logger.http.headers.prefix", value = "header.")
|
@Property(name = "logger.http.header.prefix", value = "header.")
|
||||||
void mdcMatchWithPrefix() {
|
void mdcMatchWithPrefix() {
|
||||||
assertContext(Map.of("header.foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
assertContext(Map.of("header.foo", "bar"), Map.of("foo", "bar", "nope", "bar"));
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue