Skip to content

Commit

Permalink
rename-var
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 10, 2024
1 parent 3dc49f8 commit 4e8bdb3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ abstract class AbstractKtorClientTelemetryBuilder(
) {
companion object {
init {
KtorBuilderUtil.clientBuilderExtractor = { it.clientBuilder }
KtorBuilderUtil.clientBuilderExtractor = { it.builder }
}
}

internal lateinit var openTelemetry: OpenTelemetry
protected lateinit var clientBuilder: DefaultHttpClientInstrumenterBuilder<HttpRequestData, HttpResponse>
protected lateinit var builder: DefaultHttpClientInstrumenterBuilder<HttpRequestData, HttpResponse>

fun setOpenTelemetry(openTelemetry: OpenTelemetry) {
this.openTelemetry = openTelemetry
this.clientBuilder = DefaultHttpClientInstrumenterBuilder.create(
this.builder = DefaultHttpClientInstrumenterBuilder.create(
instrumentationName,
openTelemetry,
KtorHttpClientAttributesGetter
Expand All @@ -43,13 +43,13 @@ abstract class AbstractKtorClientTelemetryBuilder(
fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable())

fun capturedRequestHeaders(headers: Iterable<String>) {
clientBuilder.setCapturedRequestHeaders(headers.toList())
builder.setCapturedRequestHeaders(headers.toList())
}

fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable())

fun capturedResponseHeaders(headers: Iterable<String>) {
clientBuilder.setCapturedResponseHeaders(headers.toList())
builder.setCapturedResponseHeaders(headers.toList())
}

fun knownMethods(vararg methods: String) = knownMethods(methods.asIterable())
Expand All @@ -60,12 +60,12 @@ abstract class AbstractKtorClientTelemetryBuilder(
fun knownMethods(methods: Iterable<HttpMethod>) = knownMethods(methods.map { it.value })

fun knownMethods(methods: Iterable<String>) {
clientBuilder.setKnownMethods(methods.toSet())
builder.setKnownMethods(methods.toSet())
}

fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) {
val builder = ExtractorBuilder().apply(extractorBuilder).build()
this.clientBuilder.addAttributeExtractor(
this.builder.addAttributeExtractor(
object : AttributesExtractor<HttpRequestData, HttpResponse> {
override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) {
builder.onStart(OnStartData(attributes, parentContext, request))
Expand Down Expand Up @@ -116,6 +116,6 @@ abstract class AbstractKtorClientTelemetryBuilder(
* Experimental#setEmitExperimentalHttpClientMetrics(AbstractKtorClientTelemetryBuilder, boolean)}.
*/
internal fun emitExperimentalHttpClientMetrics() {
clientBuilder.setEmitExperimentalHttpClientMetrics(true)
builder.setEmitExperimentalHttpClientMetrics(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object KtorServerTelemetryUtil {

private fun instrumenter(builder: AbstractKtorServerTelemetryBuilder): Instrumenter<ApplicationRequest, ApplicationResponse> {
return InstrumenterUtil.buildUpstreamInstrumenter(
builder.serverBuilder.instrumenterBuilder(),
builder.builder.instrumenterBuilder(),
ApplicationRequestGetter,
builder.spanKindExtractor(SpanKindExtractor.alwaysServer())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUti
abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) {
companion object {
init {
KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder }
KtorBuilderUtil.serverBuilderExtractor = { it.builder }
}
}

internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder<ApplicationRequest, ApplicationResponse>
internal lateinit var builder: DefaultHttpServerInstrumenterBuilder<ApplicationRequest, ApplicationResponse>

internal var spanKindExtractor:
(SpanKindExtractor<ApplicationRequest>) -> SpanKindExtractor<ApplicationRequest> = { a -> a }

fun setOpenTelemetry(openTelemetry: OpenTelemetry) {
this.serverBuilder =
this.builder =
DefaultHttpServerInstrumenterBuilder.create(
instrumentationName,
openTelemetry,
Expand All @@ -50,7 +50,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam
}

fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>) -> Unit) {
serverBuilder.setStatusExtractor { prevExtractor ->
builder.setStatusExtractor { prevExtractor ->
SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder,
request: ApplicationRequest,
response: ApplicationResponse?,
Expand Down Expand Up @@ -99,7 +99,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam

fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) {
val builder = ExtractorBuilder().apply(extractorBuilder).build()
serverBuilder.addAttributesExtractor(
this.builder.addAttributesExtractor(
object : AttributesExtractor<ApplicationRequest, ApplicationResponse> {
override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: ApplicationRequest) {
builder.onStart(OnStartData(attributes, parentContext, request))
Expand Down Expand Up @@ -154,7 +154,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam
fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable())

fun capturedRequestHeaders(headers: Iterable<String>) {
serverBuilder.setCapturedRequestHeaders(headers.toList())
builder.setCapturedRequestHeaders(headers.toList())
}

@Deprecated(
Expand All @@ -166,7 +166,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam
fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable())

fun capturedResponseHeaders(headers: Iterable<String>) {
serverBuilder.setCapturedResponseHeaders(headers.toList())
builder.setCapturedResponseHeaders(headers.toList())
}

@Deprecated(
Expand All @@ -184,12 +184,12 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam

fun knownMethods(methods: Iterable<String>) {
methods.toSet().apply {
serverBuilder.setKnownMethods(this)
builder.setKnownMethods(this)
}
}

/**
* {@link #setOpenTelemetry(OpenTelemetry)} sets the serverBuilder to a non-null value.
*/
fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized
fun isOpenTelemetryInitialized(): Boolean = this::builder.isInitialized
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClie
class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) {

internal fun build(): KtorClientTelemetry = KtorClientTelemetry(
instrumenter = clientBuilder.build(),
instrumenter = builder.build(),
propagators = getOpenTelemetry().propagators,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INST
class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) {

internal fun build(): KtorClientTelemetry = KtorClientTelemetry(
instrumenter = clientBuilder.build(),
instrumenter = builder.build(),
propagators = getOpenTelemetry().propagators,
)
}

0 comments on commit 4e8bdb3

Please sign in to comment.