Skip to content
Permalink
Browse files

Merge pull request #1190 from systay/span-context-in-queries

Only add tracing to queries over the MySQL protocol
  • Loading branch information...
systay committed Sep 11, 2019
2 parents 79da379 + 989fab3 commit e8eb2c447318dd9e9552d79ac08675c9365c5815
@@ -2,8 +2,10 @@ package misk.jdbc

import net.ttddyy.dsproxy.transform.TransformInfo
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import io.opentracing.mock.MockTracer
import org.assertj.core.api.Assertions.assertThat
import javax.sql.DataSource

class JaegerSpanInjectorTest {
@Test
@@ -23,4 +25,26 @@ class JaegerSpanInjectorTest {
assertThat(result).isEqualTo("/*VT_SPAN_CONTEXT=$contextString*/$query")
scope.close()
}

@Test
fun testNotDecorateIfItsVitess() {
val tracer = MockTracer()
val config = DataSourceConfig(DataSourceType.VITESS)
val injector = JaegerSpanInjector(tracer, config)
val ds = Mockito.mock(DataSource::class.java)

assertThat(injector.decorate(ds)).
isSameAs(ds)
}

@Test
fun testDecoratesIfItsVitessMysql() {
val tracer = MockTracer()
val config = DataSourceConfig(DataSourceType.VITESS_MYSQL)
val injector = JaegerSpanInjector(tracer, config)
val ds = Mockito.mock(DataSource::class.java)

assertThat(injector.decorate(ds)).
isNotSameAs(ds)
}
}
@@ -14,7 +14,7 @@ class JaegerSpanInjector(
val config: DataSourceConfig
) : QueryTransformer, DataSourceDecorator {
override fun decorate(dataSource: DataSource): DataSource {
if (config.type != DataSourceType.VITESS || tracer == null) return dataSource
if (config.type != DataSourceType.VITESS_MYSQL || tracer == null) return dataSource
return ProxyDataSourceBuilder(dataSource).queryTransformer(this).build()
}

0 comments on commit e8eb2c4

Please sign in to comment.
You can’t perform that action at this time.