From 623de4c58169ac180273c17e7e280253deeb4f43 Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Tue, 21 Jan 2025 17:09:58 -0800 Subject: [PATCH] feedback --- .../models/HttpInstrumentationOptions.java | 158 +++++++++++------- .../pipeline/HttpInstrumentationPolicy.java | 6 +- .../util/EnvironmentConfiguration.java | 2 +- .../util/configuration/Configuration.java | 2 +- .../HttpInstrumentationLoggingTests.java | 75 +++++---- ...ttpInstrumentationPolicyFallbackTests.java | 5 +- .../core/shared/HttpClientTests.java | 3 +- .../io/clientcore/http/stress/HttpPatch.java | 2 +- .../HttpInstrumentationPolicyTests.java | 4 +- 9 files changed, 160 insertions(+), 97 deletions(-) diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpInstrumentationOptions.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpInstrumentationOptions.java index 8e72381cf3265..5eb41ed2ef4f8 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpInstrumentationOptions.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpInstrumentationOptions.java @@ -38,7 +38,7 @@ *
  • Error details if the request fails
  • *
  • Time it takes to receive response
  • *
  • Correlation identifiers
  • - *
  • When content logging is enabled via {@link #setContentLoggingEnabled(boolean)}: request and response body, and time-to-last-byte
  • + *
  • When content logging is enabled via {@link HttpLogDetailLevel#BODY_AND_HEADERS}: request and response body, and time-to-last-byte
  • * * * Client libraries auto-discover global OpenTelemetry SDK instance configured by the java agent or @@ -80,8 +80,7 @@ * */ public final class HttpInstrumentationOptions extends InstrumentationOptions { - private boolean isHttpLoggingEnabled; - private boolean isContentLoggingEnabled; + private HttpLogDetailLevel logDetailLevel; private boolean isRedactedHeaderNamesLoggingEnabled; private Set allowedHeaderNames; private Set allowedQueryParamNames; @@ -93,18 +92,10 @@ public final class HttpInstrumentationOptions extends InstrumentationOptions { HttpHeaderName.PRAGMA, HttpHeaderName.RETRY_AFTER, HttpHeaderName.SERVER, HttpHeaderName.TRANSFER_ENCODING, HttpHeaderName.USER_AGENT, HttpHeaderName.WWW_AUTHENTICATE); + static final HttpLogDetailLevel ENVIRONMENT_HTTP_LOG_DETAIL_LEVEL + = HttpLogDetailLevel.fromConfiguration(Configuration.getGlobalConfiguration()); private static final List DEFAULT_QUERY_PARAMS_ALLOWLIST = Collections.singletonList("api-version"); - private static final ConfigurationProperty HTTP_LOGGING_ENABLED - = ConfigurationPropertyBuilder.ofBoolean("http.logging.enabled") - .shared(true) - .environmentVariableName(Configuration.PROPERTY_HTTP_LOGGING_ENABLED) - .defaultValue(false) - .build(); - - private static final boolean DEFAULT_HTTP_LOGGING_ENABLED - = Configuration.getGlobalConfiguration().get(HTTP_LOGGING_ENABLED); - /** * Creates a new instance using default options: *
      @@ -114,24 +105,22 @@ public final class HttpInstrumentationOptions extends InstrumentationOptions { */ public HttpInstrumentationOptions() { super(); - isHttpLoggingEnabled = DEFAULT_HTTP_LOGGING_ENABLED; - isContentLoggingEnabled = false; + logDetailLevel = ENVIRONMENT_HTTP_LOG_DETAIL_LEVEL; isRedactedHeaderNamesLoggingEnabled = true; allowedHeaderNames = new HashSet<>(DEFAULT_HEADERS_ALLOWLIST); allowedQueryParamNames = new HashSet<>(DEFAULT_QUERY_PARAMS_ALLOWLIST); } /** - * Flag indicating whether detailed HTTP request and response logging is enabled. - * False by default. + * Gets the level of detail for HTTP request logs. Default is {@link HttpLogDetailLevel#NONE}. *

      * When HTTP logging is disabled, basic information about the request and response is still recorded * on distributed tracing spans. * - * @return True if logging is enabled, false otherwise. + * @return The {@link HttpLogDetailLevel}. */ - public boolean isHttpLoggingEnabled() { - return isHttpLoggingEnabled; + public HttpLogDetailLevel getHttpLogLevel() { + return logDetailLevel; } /** @@ -158,46 +147,15 @@ public HttpInstrumentationOptions setRedactedHeaderNamesLoggingEnabled(boolean r } /** - * Flag indicating whether HTTP request and response body is logged. - * False by default. - *

      - * Note: even when content logging is explicitly enabled, content is not logged - * for requests and responses where the content length is not known or greater than 16KB. + * Sets the level of detail for HTTP request logs. + * Default is {@link HttpLogDetailLevel#NONE}. * - * @return True if content logging is enabled, false otherwise. - */ - public boolean isContentLoggingEnabled() { - return isContentLoggingEnabled; - } - - /** - * Enables or disables logging of HTTP request and response. - * False by default. - *

      - * When HTTP logging is disabled, basic information about the request and response is still recorded - * via distributed tracing. - * - * @param isHttpLoggingEnabled True to enable detailed HTTP logging, false otherwise. - * @return The updated {@link HttpInstrumentationOptions} object. - */ - public HttpInstrumentationOptions setHttpLoggingEnabled(boolean isHttpLoggingEnabled) { - this.isHttpLoggingEnabled = isHttpLoggingEnabled; - return this; - } - - /** - * Enables or disables logging of HTTP request and response body. False by default. - * Enabling content logging also enables HTTP logging in general. - *

      - * Note: even when content logging is explicitly enabled, content is not logged for requests and responses where the - * content length is not known or greater than 16KB. + * @param logDetailLevel The {@link HttpLogDetailLevel}. * - * @param isContentLoggingEnabled True to enable content logging, false otherwise. * @return The updated {@link HttpInstrumentationOptions} object. */ - public HttpInstrumentationOptions setContentLoggingEnabled(boolean isContentLoggingEnabled) { - this.isHttpLoggingEnabled |= isContentLoggingEnabled; - this.isContentLoggingEnabled = isContentLoggingEnabled; + public HttpInstrumentationOptions setHttpLogLevel(HttpLogDetailLevel logDetailLevel) { + this.logDetailLevel = logDetailLevel; return this; } @@ -226,7 +184,7 @@ public Set getAllowedHeaderNames() { * @return The updated HttpLogOptions object. */ public HttpInstrumentationOptions setAllowedHeaderNames(final Set allowedHeaderNames) { - this.allowedHeaderNames = allowedHeaderNames == null ? new HashSet<>() : allowedHeaderNames; + this.allowedHeaderNames = allowedHeaderNames == null ? new HashSet<>() : new HashSet<>(allowedHeaderNames); return this; } @@ -266,7 +224,8 @@ public Set getAllowedQueryParamNames() { * @return The updated {@code allowedQueryParamName} object. */ public HttpInstrumentationOptions setAllowedQueryParamNames(final Set allowedQueryParamNames) { - this.allowedQueryParamNames = allowedQueryParamNames == null ? new HashSet<>() : allowedQueryParamNames; + this.allowedQueryParamNames + = allowedQueryParamNames == null ? new HashSet<>() : new HashSet<>(allowedQueryParamNames); return this; } @@ -296,4 +255,87 @@ public HttpInstrumentationOptions setTelemetryProvider(Object telemetryProvider) super.setTelemetryProvider(telemetryProvider); return this; } + + /** + * The level of detail for HTTP request logs. + */ + public enum HttpLogDetailLevel { + /** + * HTTP logging is turned off. + */ + NONE, + + /** + * Enables logging the following information on detailed HTTP logs + *

        + *
      • Request method, URI, and body size. URI is sanitized based on allowed query parameters configurable with {@link #setAllowedQueryParamNames(Set)} and {@link #addAllowedQueryParamName(String)}
      • + *
      • Response status code and body size
      • + *
      • Request and response headers from allow-list configured via {@link #setAllowedHeaderNames(Set)} and {@link #addAllowedHeaderName(HttpHeaderName)}.
      • + *
      • Error details if the request fails
      • + *
      • Time it takes to receive response
      • + *
      • Correlation identifiers
      • + *
      + */ + HEADERS, + + /** + * Enables logging the following information on detailed HTTP logs + *
        + *
      • Request method, URI, and body size. URI is sanitized based on allowed query parameters configurable with {@link #setAllowedQueryParamNames(Set)} and {@link #addAllowedQueryParamName(String)}
      • + *
      • Response status code and body size
      • + *
      • Error details if the request fails
      • + *
      • Time it takes to receive response
      • + *
      • Correlation identifiers
      • + *
      • Request and response bodies
      • + *
      • Time-to-last-byte
      • + *
      + * + *

      + * The request and response body will be buffered into memory even if it is never consumed by an application, possibly impacting + * performance. + *

      + * Body is not logged (and not buffered) for requests and responses where the content length is not known or greater than 16KB. + */ + BODY, + + /** + * Enables logging everything in {@link #HEADERS} and {@link #BODY}. + * + *

      + * The request and response body will be buffered into memory even if it is never consumed by an application, possibly impacting + * performance. + *

      + * Body is not logged (and not buffered) for requests and responses where the content length is not known or greater than 16KB. + */ + BODY_AND_HEADERS; + + private static final String HEADERS_VALUE = "headers"; + private static final String BODY_VALUE = "body"; + private static final String BODY_AND_HEADERS_VALUE = "body_and_headers"; + + private static final ConfigurationProperty HTTP_LOG_DETAIL_LEVEL + = ConfigurationPropertyBuilder.ofString("http.log.detail.level") + .shared(true) + .environmentVariableName(Configuration.PROPERTY_HTTP_LOG_DETAIL_LEVEL) + .defaultValue("none") + .build(); + + static HttpLogDetailLevel fromConfiguration(Configuration configuration) { + String detailLevel = configuration.get(HTTP_LOG_DETAIL_LEVEL); + + HttpLogDetailLevel logDetailLevel; + + if (HEADERS_VALUE.equalsIgnoreCase(detailLevel)) { + logDetailLevel = HEADERS; + } else if (BODY_VALUE.equalsIgnoreCase(detailLevel)) { + logDetailLevel = BODY; + } else if (BODY_AND_HEADERS_VALUE.equalsIgnoreCase(detailLevel)) { + logDetailLevel = BODY_AND_HEADERS; + } else { + logDetailLevel = NONE; + } + + return logDetailLevel; + } + } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java index 30fa319ba77ec..40f0d7e7ea4e0 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java @@ -185,8 +185,10 @@ public HttpInstrumentationPolicy(HttpInstrumentationOptions instrumentationOptio HttpInstrumentationOptions optionsToUse = instrumentationOptions == null ? DEFAULT_OPTIONS : instrumentationOptions; - this.isLoggingEnabled = optionsToUse.isHttpLoggingEnabled(); - this.isContentLoggingEnabled = optionsToUse.isContentLoggingEnabled(); + this.isLoggingEnabled = optionsToUse.getHttpLogLevel() != HttpInstrumentationOptions.HttpLogDetailLevel.NONE; + this.isContentLoggingEnabled + = optionsToUse.getHttpLogLevel() == HttpInstrumentationOptions.HttpLogDetailLevel.BODY + || optionsToUse.getHttpLogLevel() == HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS; this.isRedactedHeadersLoggingEnabled = optionsToUse.isRedactedHeaderNamesLoggingEnabled(); this.allowedHeaderNames = optionsToUse.getAllowedHeaderNames(); this.allowedQueryParameterNames = optionsToUse.getAllowedQueryParamNames() diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/util/EnvironmentConfiguration.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/util/EnvironmentConfiguration.java index 7e7e5b5a2f4d1..11518a3258175 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/util/EnvironmentConfiguration.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/util/EnvironmentConfiguration.java @@ -27,7 +27,7 @@ public class EnvironmentConfiguration { */ private static final Set DEFAULT_CONFIGURATIONS = new HashSet<>(Arrays.asList(Configuration.PROPERTY_HTTP_PROXY, Configuration.PROPERTY_HTTPS_PROXY, - Configuration.PROPERTY_LOG_LEVEL, Configuration.PROPERTY_HTTP_LOGGING_ENABLED, + Configuration.PROPERTY_LOG_LEVEL, Configuration.PROPERTY_HTTP_LOG_DETAIL_LEVEL, Configuration.PROPERTY_REQUEST_RETRY_COUNT, Configuration.PROPERTY_REQUEST_CONNECT_TIMEOUT, Configuration.PROPERTY_REQUEST_WRITE_TIMEOUT, Configuration.PROPERTY_REQUEST_RESPONSE_TIMEOUT, Configuration.PROPERTY_REQUEST_READ_TIMEOUT)); diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/util/configuration/Configuration.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/util/configuration/Configuration.java index f47018bcccacb..6e749a54c3c92 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/util/configuration/Configuration.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/util/configuration/Configuration.java @@ -58,7 +58,7 @@ public class Configuration { /** * Enables HTTP request/response logging by setting an HTTP log detail level. */ - public static final String PROPERTY_HTTP_LOGGING_ENABLED = "HTTP_LOGGING_ENABLED"; + public static final String PROPERTY_HTTP_LOG_DETAIL_LEVEL = "HTTP_LOG_DETAIL_LEVEL"; /** * Sets the default number of times a request will be retried, if it passes the conditions for retrying, before it diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationLoggingTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationLoggingTests.java index 4b631e2d0e76e..456dd76bcccc2 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationLoggingTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationLoggingTests.java @@ -69,12 +69,11 @@ public HttpInstrumentationLoggingTests() { @ParameterizedTest @MethodSource("disabledHttpLoggingSource") - public void testDisabledHttpLogging(ClientLogger.LogLevel logLevel, boolean enableLogging, - boolean enableContentLogging) throws IOException { + public void testDisabledHttpLogging(ClientLogger.LogLevel logLevel, + HttpInstrumentationOptions.HttpLogDetailLevel detailLevel) throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(logLevel, logCaptureStream); - HttpPipeline pipeline = createPipeline(new HttpInstrumentationOptions().setHttpLoggingEnabled(enableLogging) - .setContentLoggingEnabled(enableContentLogging)); + HttpPipeline pipeline = createPipeline(new HttpInstrumentationOptions().setHttpLogLevel(detailLevel)); HttpRequest request = new HttpRequest(HttpMethod.GET, URI); request.setRequestOptions(new RequestOptions().setLogger(logger)); @@ -84,10 +83,11 @@ public void testDisabledHttpLogging(ClientLogger.LogLevel logLevel, boolean enab } public static Stream disabledHttpLoggingSource() { - return Stream.of(Arguments.of(ClientLogger.LogLevel.VERBOSE, false, false), - Arguments.of(ClientLogger.LogLevel.WARNING, false, true), - Arguments.of(ClientLogger.LogLevel.WARNING, true, false), - Arguments.of(ClientLogger.LogLevel.WARNING, true, true)); + return Stream.of( + Arguments.of(ClientLogger.LogLevel.VERBOSE, HttpInstrumentationOptions.HttpLogDetailLevel.NONE), + Arguments.of(ClientLogger.LogLevel.WARNING, HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS), + Arguments.of(ClientLogger.LogLevel.WARNING, HttpInstrumentationOptions.HttpLogDetailLevel.BODY), Arguments + .of(ClientLogger.LogLevel.WARNING, HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS)); } @ParameterizedTest @@ -95,7 +95,8 @@ public static Stream disabledHttpLoggingSource() { public void testBasicHttpLogging(Set allowedParams, String expectedUri) throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); HttpInstrumentationOptions options - = new HttpInstrumentationOptions().setHttpLoggingEnabled(true).setAllowedQueryParamNames(allowedParams); + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS) + .setAllowedQueryParamNames(allowedParams); HttpPipeline pipeline = createPipeline(options); @@ -122,7 +123,8 @@ public void testBasicHttpLogging(Set allowedParams, String expectedUri) public void testBasicHttpLoggingNoRedactedHeaders() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); HttpInstrumentationOptions options - = new HttpInstrumentationOptions().setHttpLoggingEnabled(true).setRedactedHeaderNamesLoggingEnabled(false); + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS) + .setRedactedHeaderNamesLoggingEnabled(false); HttpPipeline pipeline = createPipeline(options); @@ -148,8 +150,8 @@ public void testHttpLoggingTracingDisabled() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); HttpInstrumentationOptions options = new HttpInstrumentationOptions().setTracingEnabled(false) - .setRedactedHeaderNamesLoggingEnabled(false) - .setHttpLoggingEnabled(true); + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS) + .setRedactedHeaderNamesLoggingEnabled(false); HttpPipeline pipeline = createPipeline(options); HttpRequest request = createRequest(HttpMethod.GET, URI, logger); @@ -169,8 +171,8 @@ public void testHttpLoggingTracingDisabled() throws IOException { @Test public void testHttpLoggingTracingDisabledCustomContext() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options - = new HttpInstrumentationOptions().setTracingEnabled(false).setHttpLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions().setTracingEnabled(false) + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS); HttpPipeline pipeline = createPipeline(options); @@ -194,7 +196,8 @@ public void testHttpLoggingTracingDisabledCustomContext() throws IOException { @Test public void testTryCount() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + HttpInstrumentationOptions options + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS); HttpPipeline pipeline = createPipeline(options); @@ -214,7 +217,8 @@ public void testTryCount() throws IOException { @MethodSource("testExceptionSeverity") public void testConnectionException(ClientLogger.LogLevel level, boolean expectExceptionLog) { ClientLogger logger = setupLogLevelAndGetLogger(level, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + HttpInstrumentationOptions options + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS); RuntimeException expectedException = new RuntimeException("socket error"); HttpPipeline pipeline = createPipeline(options, request -> { @@ -237,7 +241,8 @@ public void testConnectionException(ClientLogger.LogLevel level, boolean expectE @MethodSource("testExceptionSeverity") public void testRequestBodyException(ClientLogger.LogLevel level, boolean expectExceptionLog) { ClientLogger logger = setupLogLevelAndGetLogger(level, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); IOException expectedException = new IOException("socket error"); TestStream requestStream = new TestStream(1024, expectedException); @@ -261,7 +266,8 @@ public void testRequestBodyException(ClientLogger.LogLevel level, boolean expect @MethodSource("testExceptionSeverity") public void testResponseBodyException(ClientLogger.LogLevel level, boolean expectExceptionLog) { ClientLogger logger = setupLogLevelAndGetLogger(level, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); IOException expectedException = new IOException("socket error"); TestStream responseStream = new TestStream(1024, expectedException); @@ -284,7 +290,8 @@ public void testResponseBodyException(ClientLogger.LogLevel level, boolean expec @Test public void testResponseBodyLoggingOnClose() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.INFORMATIONAL, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); HttpPipeline pipeline = createPipeline(options, request -> new MockHttpResponse(request, 200, BinaryData.fromString("Response body"))); @@ -303,7 +310,8 @@ public void testResponseBodyLoggingOnClose() throws IOException { @Test public void testResponseBodyRequestedMultipleTimes() { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.INFORMATIONAL, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); HttpPipeline pipeline = createPipeline(options, request -> new MockHttpResponse(request, 200, BinaryData.fromString("Response body"))); @@ -324,7 +332,8 @@ public void testResponseBodyRequestedMultipleTimes() { public void testBasicHttpLoggingRequestOff(Set allowedParams, String expectedUri) throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.INFORMATIONAL, logCaptureStream); HttpInstrumentationOptions options - = new HttpInstrumentationOptions().setHttpLoggingEnabled(true).setAllowedQueryParamNames(allowedParams); + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS) + .setAllowedQueryParamNames(allowedParams); HttpPipeline pipeline = createPipeline(options); @@ -344,7 +353,8 @@ public void testBasicHttpLoggingRequestOff(Set allowedParams, String exp public void testHeadersHttpLogging(Set allowedHeaders) throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); HttpInstrumentationOptions options - = new HttpInstrumentationOptions().setHttpLoggingEnabled(true).setAllowedHeaderNames(allowedHeaders); + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS) + .setAllowedHeaderNames(allowedHeaders); HttpPipeline pipeline = createPipeline(options); @@ -380,7 +390,8 @@ public void testHeadersHttpLogging(Set allowedHeaders) throws IO @Test public void testStringBodyLogging() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); HttpPipeline pipeline = createPipeline(options, request -> new MockHttpResponse(request, 200, BinaryData.fromString("Response body"))); @@ -408,7 +419,8 @@ public void testStringBodyLogging() throws IOException { @Test public void testStreamBodyLogging() { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); BinaryData responseBody = BinaryData.fromString("Response body"); TestStream responseStream = new TestStream(responseBody); @@ -446,7 +458,8 @@ public void testStreamBodyLogging() { @Test public void testHugeBodyNotLogged() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); TestStream requestStream = new TestStream(1024 * 1024); TestStream responseStream = new TestStream(1024 * 1024); @@ -477,7 +490,8 @@ public void testHugeBodyNotLogged() throws IOException { @Test public void testBodyWithUnknownLengthNotLogged() throws IOException { ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setContentLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); TestStream requestStream = new TestStream(1024); TestStream responseStream = new TestStream(1024); @@ -511,7 +525,8 @@ public void testBodyWithUnknownLengthNotLogged() throws IOException { public void tracingWithRetriesException() throws IOException { AtomicInteger count = new AtomicInteger(0); ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); AtomicReference firstTryContext = new AtomicReference<>(); UnknownHostException expectedException = new UnknownHostException("test exception"); @@ -551,7 +566,8 @@ public void tracingWithRetriesException() throws IOException { public void tracingWithRetriesStatusCode() throws IOException { AtomicInteger count = new AtomicInteger(0); ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); AtomicReference firstTryContext = new AtomicReference<>(); @@ -623,7 +639,8 @@ public void retryPolicyLoggingRetriesExhausted(ClientLogger.LogLevel logLevel, b public void tracingWithRedirects() throws IOException { AtomicInteger count = new AtomicInteger(0); ClientLogger logger = setupLogLevelAndGetLogger(ClientLogger.LogLevel.VERBOSE, logCaptureStream); - HttpInstrumentationOptions options = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + HttpInstrumentationOptions options = new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS); AtomicReference firstRedirectContext = new AtomicReference<>(); diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyFallbackTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyFallbackTests.java index 71c72cca793ef..508c20ce2ca58 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyFallbackTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyFallbackTests.java @@ -26,7 +26,8 @@ public class HttpInstrumentationPolicyFallbackTests { @Test public void simpleRequestTracingDisabled() throws IOException { HttpInstrumentationOptions tracingOffLoggingOnOptions - = new HttpInstrumentationOptions().setTracingEnabled(false).setHttpLoggingEnabled(true); + = new HttpInstrumentationOptions().setTracingEnabled(false) + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS); HttpPipeline pipeline = new HttpPipelineBuilder().policies(new HttpInstrumentationPolicy(tracingOffLoggingOnOptions)) @@ -45,7 +46,7 @@ public void simpleRequestTracingDisabled() throws IOException { @ValueSource(ints = { 200, 201, 206, 302, 400, 404, 500, 503 }) public void simpleRequestTracingEnabled(int statusCode) throws IOException { HttpInstrumentationOptions tracingOnLoggingOnOptions - = new HttpInstrumentationOptions().setHttpLoggingEnabled(true); + = new HttpInstrumentationOptions().setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS); HttpPipeline pipeline = new HttpPipelineBuilder().policies(new HttpInstrumentationPolicy(tracingOnLoggingOnOptions)) diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/shared/HttpClientTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/shared/HttpClientTests.java index 8c5eb2b147cf4..d9c4d6a52fa33 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/shared/HttpClientTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/shared/HttpClientTests.java @@ -1492,7 +1492,8 @@ public void binaryDataUploadTest() throws Exception { // Order in which policies applied will be the order in which they added to builder final HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) - .policies(new HttpInstrumentationPolicy(new HttpInstrumentationOptions().setContentLoggingEnabled(true))) + .policies(new HttpInstrumentationPolicy(new HttpInstrumentationOptions() + .setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.BODY_AND_HEADERS))) .build(); Response response diff --git a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java index 27a09bed1b374..36cf10aef91e5 100644 --- a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java +++ b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java @@ -88,7 +88,7 @@ private HttpRequest createRequest() { private HttpPipelineBuilder getPipelineBuilder() { HttpPipelineBuilder builder = new HttpPipelineBuilder().policies(new HttpRetryPolicy(), - new HttpInstrumentationPolicy(new HttpInstrumentationOptions<>().setHttpLoggingEnabled(true))); + new HttpInstrumentationPolicy(new HttpInstrumentationOptions().setHttpLoggingEnabled(true))); if (options.getHttpClient() == PerfStressOptions.HttpClientType.OKHTTP) { builder.httpClient(new OkHttpHttpClientProvider().getSharedInstance()); diff --git a/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyTests.java b/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyTests.java index 0dee6e3f46dd6..381d6dca13439 100644 --- a/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyTests.java +++ b/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicyTests.java @@ -324,8 +324,8 @@ public void userAgentIsRecorded() throws IOException { @Test public void enrichSpans() throws IOException { - HttpInstrumentationPolicy httpInstrumentationPolicy - = new HttpInstrumentationPolicy(otelOptions.setHttpLoggingEnabled(true)); + HttpInstrumentationPolicy httpInstrumentationPolicy = new HttpInstrumentationPolicy( + otelOptions.setHttpLogLevel(HttpInstrumentationOptions.HttpLogDetailLevel.HEADERS)); HttpPipelinePolicy enrichingPolicy = (request, next) -> { io.clientcore.core.instrumentation.tracing.Span span