Skip to content

Commit

Permalink
feat: 批量上报traceId #2489
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan authored Aug 15, 2024
1 parent 34eb08f commit 3eb7b8f
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@

package com.tencent.bkrepo.common.service.otel.web

import io.opentelemetry.sdk.trace.SpanProcessor
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder
import io.opentelemetry.sdk.trace.export.SpanExporter
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.cloud.sleuth.autoconfig.otel.OtelProcessorProperties
import org.springframework.cloud.sleuth.autoconfig.otel.SpanProcessorProvider
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import java.util.concurrent.TimeUnit

@Configuration
class OtelWebConfiguration {
Expand All @@ -43,4 +51,40 @@ class OtelWebConfiguration {
registrationBean.addUrlPatterns("/*")
return registrationBean
}

@Bean
@ConditionalOnMissingBean
fun otelBatchSpanProcessorProvider(otelProcessorProperties: OtelProcessorProperties): SpanProcessorProvider {
return object : SpanProcessorProvider {
override fun toSpanProcessor(spanExporter: SpanExporter): SpanProcessor {
val builder = BatchSpanProcessor.builder(spanExporter)
setBuilderProperties(otelProcessorProperties, builder)
return builder.build()
}

fun setBuilderProperties(
otelProcessorProperties: OtelProcessorProperties,
builder: BatchSpanProcessorBuilder
) {
if (otelProcessorProperties.batch.exporterTimeout != null) {
builder.setExporterTimeout(
otelProcessorProperties.batch.exporterTimeout,
TimeUnit.MILLISECONDS
)
}
if (otelProcessorProperties.batch.maxExportBatchSize != null) {
builder.setMaxExportBatchSize(otelProcessorProperties.batch.maxExportBatchSize)
}
if (otelProcessorProperties.batch.maxQueueSize != null) {
builder.setMaxQueueSize(otelProcessorProperties.batch.maxQueueSize)
}
if (otelProcessorProperties.batch.scheduleDelay != null) {
builder.setScheduleDelay(
otelProcessorProperties.batch.scheduleDelay,
TimeUnit.MILLISECONDS
)
}
}
}
}
}

0 comments on commit 3eb7b8f

Please sign in to comment.