Skip to content

Commit

Permalink
Stabilize HTTP headers capturing configuration property names (#4459)
Browse files Browse the repository at this point in the history
* Stabilize HTTP headers capturing configuration property names

* code review comments
  • Loading branch information
Mateusz Rzeszutek authored Oct 22, 2021
1 parent e9022da commit 05a3914
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
12 changes: 6 additions & 6 deletions docs/config/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,52 @@ public static CapturedHttpHeaders empty() {
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)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 05a3914

Please sign in to comment.