Skip to content

Commit

Permalink
Ktor: support setting custom spanNameExtractor (#12842) (#12850)
Browse files Browse the repository at this point in the history
  • Loading branch information
SIMULATAN authored Dec 12, 2024
1 parent 712e0a7 commit e002f7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import io.opentelemetry.api.common.AttributesBuilder
import io.opentelemetry.context.Context
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor
import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil
import java.util.function.Function

abstract class AbstractKtorClientTracingBuilder(
private val instrumentationName: String
Expand Down Expand Up @@ -169,4 +171,8 @@ abstract class AbstractKtorClientTracingBuilder(
fun emitExperimentalHttpClientMetrics() {
clientBuilder.setEmitExperimentalHttpClientMetrics(true)
}

fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<in HttpRequestData>, out SpanNameExtractor<in HttpRequestData>>) {
clientBuilder.setSpanNameExtractor(spanNameExtractorTransformer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package io.opentelemetry.instrumentation.ktor.server

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.opentelemetry.api.OpenTelemetry
Expand All @@ -16,9 +15,11 @@ import io.opentelemetry.context.Context
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor
import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil
import java.util.function.Function

abstract class AbstractKtorServerTracingBuilder(private val instrumentationName: String) {
companion object {
Expand Down Expand Up @@ -86,6 +87,10 @@ abstract class AbstractKtorServerTracingBuilder(private val instrumentationName:
}
}

fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<in ApplicationRequest>, out SpanNameExtractor<in ApplicationRequest>>) {
serverBuilder.setSpanNameExtractor(spanNameExtractorTransformer)
}

@Deprecated("Please use method `attributeExtractor`")
fun addAttributeExtractor(extractor: AttributesExtractor<in ApplicationRequest, in ApplicationResponse>) {
attributeExtractor {
Expand Down

0 comments on commit e002f7a

Please sign in to comment.