From 05a391459b97c190da37410ad9381abd70e22370 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Fri, 22 Oct 2021 06:56:20 +0200 Subject: [PATCH] Stabilize HTTP headers capturing configuration property names (#4459) * Stabilize HTTP headers capturing configuration property names * code review comments --- docs/config/common.md | 12 +++---- .../http/CapturedHttpHeaders.java | 32 ++++++++++++++++--- .../CapturedHttpHeadersTestConfigSource.java | 16 +++------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/docs/config/common.md b/docs/config/common.md index ecf757d3b49b..a185db3d1a88 100644 --- a/docs/config/common.md +++ b/docs/config/common.md @@ -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. diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java index 4f9c119ea4ae..a6fcd2251373 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/CapturedHttpHeaders.java @@ -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))); } /** diff --git a/testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/http/CapturedHttpHeadersTestConfigSource.java b/testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/http/CapturedHttpHeadersTestConfigSource.java index 90b766cfb496..eec0215d5404 100644 --- a/testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/http/CapturedHttpHeadersTestConfigSource.java +++ b/testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/http/CapturedHttpHeadersTestConfigSource.java @@ -16,18 +16,10 @@ public class CapturedHttpHeadersTestConfigSource implements ConfigPropertySource @Override public Map getProperties() { Map 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; } }