-
Notifications
You must be signed in to change notification settings - Fork 869
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make DefaultHttpClientTelemetryBuilder internal
- Loading branch information
1 parent
d40519b
commit a753b80
Showing
20 changed files
with
85 additions
and
103 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...lemetry/instrumentation/api/incubator/builder/internal/HttpClientInstrumenterBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.incubator.builder.internal; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.instrumentation.api.incubator.config.internal.CoreCommonConfig; | ||
import java.lang.reflect.Field; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public class HttpClientInstrumenterBuilder { | ||
private HttpClientInstrumenterBuilder() {} | ||
|
||
@CanIgnoreReturnValue | ||
public static <REQUEST, RESPONSE> DefaultHttpClientTelemetryBuilder<REQUEST, RESPONSE> configure( | ||
CoreCommonConfig config, Object builder) { | ||
DefaultHttpClientTelemetryBuilder<REQUEST, RESPONSE> defaultBuilder = unwrapBuilder(builder); | ||
set(config::getKnownHttpRequestMethods, defaultBuilder::setKnownMethods); | ||
set(config::getClientRequestHeaders, defaultBuilder::setCapturedRequestHeaders); | ||
set(config::getClientResponseHeaders, defaultBuilder::setCapturedResponseHeaders); | ||
set(config::getPeerServiceResolver, defaultBuilder::setPeerServiceResolver); | ||
set( | ||
config::shouldEmitExperimentalHttpClientTelemetry, | ||
defaultBuilder::setEmitExperimentalHttpClientMetrics); | ||
return defaultBuilder; | ||
} | ||
|
||
private static <T> void set(Supplier<T> supplier, Consumer<T> consumer) { | ||
T t = supplier.get(); | ||
if (t != null) { | ||
consumer.accept(t); | ||
} | ||
} | ||
|
||
/** | ||
* This method is used to access the builder field of the builder object. | ||
* | ||
* <p>This approach allows us to re-use the existing builder classes from the library modules | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
private static <REQUEST, RESPONSE> | ||
DefaultHttpClientTelemetryBuilder<REQUEST, RESPONSE> unwrapBuilder(Object builder) { | ||
if (builder instanceof DefaultHttpClientTelemetryBuilder<?, ?>) { | ||
return (DefaultHttpClientTelemetryBuilder<REQUEST, RESPONSE>) builder; | ||
} | ||
try { | ||
Field field = builder.getClass().getDeclaredField("builder"); | ||
field.setAccessible(true); | ||
return (DefaultHttpClientTelemetryBuilder<REQUEST, RESPONSE>) field.get(builder); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Could not access builder field", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...ry/instrumentation/api/incubator/internal/instrumenter/HttpClientInstrumenterBuilder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters