Stabilize HTTP headers capturing configuration property names (#4459)

* Stabilize HTTP headers capturing configuration property names

* code review comments
This commit is contained in:
Mateusz Rzeszutek 2021-10-22 06:56:20 +02:00 committed by GitHub
parent e9022da102
commit 05a391459b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 22 deletions

View File

@ -38,12 +38,12 @@ You can configure the agent to capture predefined HTTP headers as span attribute
[semantic convention](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers).
Use the following properties to define which HTTP headers you want to capture:
| System property | Environment variable | Description |
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ----------- |
| `otel.instrumentation.common.experimental.capture-http-headers.client.request` | `OTEL_INSTRUMENTATION_COMMON_EXPERIMENTAL_CAPTURE_HTTP_HEADERS_CLIENT_REQUEST` | A comma-separated list of HTTP header names. HTTP client instrumentations will capture HTTP request header values for all configured header names.
| `otel.instrumentation.common.experimental.capture-http-headers.client.response` | `OTEL_INSTRUMENTATION_COMMON_EXPERIMENTAL_CAPTURE_HTTP_HEADERS_CLIENT_RESPONSE` | A comma-separated list of HTTP header names. HTTP client instrumentations will capture HTTP response header values for all configured header names.
| `otel.instrumentation.common.experimental.capture-http-headers.server.request` | `OTEL_INSTRUMENTATION_COMMON_EXPERIMENTAL_CAPTURE_HTTP_HEADERS_SERVER_REQUEST` | A comma-separated list of HTTP header names. HTTP server instrumentations will capture HTTP request header values for all configured header names.
| `otel.instrumentation.common.experimental.capture-http-headers.server.response` | `OTEL_INSTRUMENTATION_COMMON_EXPERIMENTAL_CAPTURE_HTTP_HEADERS_SERVER_RESPONSE` | A comma-separated list of HTTP header names. HTTP server instrumentations will capture HTTP response header values for all configured header names.
| System property | Environment variable | Description |
| ----------------------------------------------------------- | ----------------------------------------------------------- | ----------- |
| `otel.instrumentation.http.capture-headers.client.request` | `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_REQUEST` | A comma-separated list of HTTP header names. HTTP client instrumentations will capture HTTP request header values for all configured header names.
| `otel.instrumentation.http.capture-headers.client.response` | `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_CLIENT_RESPONSE` | A comma-separated list of HTTP header names. HTTP client instrumentations will capture HTTP response header values for all configured header names.
| `otel.instrumentation.http.capture-headers.server.request` | `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST` | A comma-separated list of HTTP header names. HTTP server instrumentations will capture HTTP request header values for all configured header names.
| `otel.instrumentation.http.capture-headers.server.response` | `OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE` | A comma-separated list of HTTP header names. HTTP server instrumentations will capture HTTP response header values for all configured header names.
These configuration options are supported by all HTTP client and server instrumentations.

View File

@ -34,28 +34,52 @@ public abstract class CapturedHttpHeaders {
return EMPTY;
}
private static final String CLIENT_REQUEST_PROPERTY =
"otel.instrumentation.http.capture-headers.client.request";
private static final String CLIENT_RESPONSE_PROPERTY =
"otel.instrumentation.http.capture-headers.client.response";
// TODO: remove the experimental properties after 1.8.0 release
private static final String EXPERIMENTAL_CLIENT_REQUEST_PROPERTY =
"otel.instrumentation.common.experimental.capture-http-headers.client.request";
private static final String EXPERIMENTAL_CLIENT_RESPONSE_PROPERTY =
"otel.instrumentation.common.experimental.capture-http-headers.client.response";
/**
* Returns a configuration that captures HTTP client request and response headers as configured in
* the received {@code config}.
*/
public static CapturedHttpHeaders client(Config config) {
// fall back to the experimental properties if the stable one isn't supplied
return CapturedHttpHeaders.create(
config.getList(
"otel.instrumentation.common.experimental.capture-http-headers.client.request"),
CLIENT_REQUEST_PROPERTY, config.getList(EXPERIMENTAL_CLIENT_REQUEST_PROPERTY)),
config.getList(
"otel.instrumentation.common.experimental.capture-http-headers.client.response"));
CLIENT_RESPONSE_PROPERTY, config.getList(EXPERIMENTAL_CLIENT_RESPONSE_PROPERTY)));
}
private static final String SERVER_REQUEST_PROPERTY =
"otel.instrumentation.http.capture-headers.server.request";
private static final String SERVER_RESPONSE_PROPERTY =
"otel.instrumentation.http.capture-headers.server.response";
// TODO: remove the experimental properties after 1.8.0 release
private static final String EXPERIMENTAL_SERVER_REQUEST_PROPERTY =
"otel.instrumentation.common.experimental.capture-http-headers.server.request";
private static final String EXPERIMENTAL_SERVER_RESPONSE_PROPERTY =
"otel.instrumentation.common.experimental.capture-http-headers.server.response";
/**
* Returns a configuration that captures HTTP server request and response headers as configured in
* the received {@code config}.
*/
public static CapturedHttpHeaders server(Config config) {
// fall back to the experimental properties if the stable one isn't supplied
return CapturedHttpHeaders.create(
config.getList(
"otel.instrumentation.common.experimental.capture-http-headers.server.request"),
SERVER_REQUEST_PROPERTY, config.getList(EXPERIMENTAL_SERVER_REQUEST_PROPERTY)),
config.getList(
"otel.instrumentation.common.experimental.capture-http-headers.server.response"));
SERVER_RESPONSE_PROPERTY, config.getList(EXPERIMENTAL_SERVER_RESPONSE_PROPERTY)));
}
/**

View File

@ -16,18 +16,10 @@ public class CapturedHttpHeadersTestConfigSource implements ConfigPropertySource
@Override
public Map<String, String> getProperties() {
Map<String, String> testConfig = new HashMap<>();
testConfig.put(
"otel.instrumentation.common.experimental.capture-http-headers.client.request",
"X-Test-Request");
testConfig.put(
"otel.instrumentation.common.experimental.capture-http-headers.client.response",
"X-Test-Response");
testConfig.put(
"otel.instrumentation.common.experimental.capture-http-headers.server.request",
"X-Test-Request");
testConfig.put(
"otel.instrumentation.common.experimental.capture-http-headers.server.response",
"X-Test-Response");
testConfig.put("otel.instrumentation.http.capture-headers.client.request", "X-Test-Request");
testConfig.put("otel.instrumentation.http.capture-headers.client.response", "X-Test-Response");
testConfig.put("otel.instrumentation.http.capture-headers.server.request", "X-Test-Request");
testConfig.put("otel.instrumentation.http.capture-headers.server.response", "X-Test-Response");
return testConfig;
}
}