-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from bas-kirill/feature/add-jaeger-for-distri…
…buted-tracing feat(jaeger): add `Jaeger` for Distributed Tracing
- Loading branch information
Showing
11 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
server/app/src/main/kotlin/mu/muse/application/muse/JaegerDbSpanCreator.kt
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,33 @@ | ||
package mu.muse.application.muse | ||
|
||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.api.trace.Tracer | ||
import org.jooq.ExecuteContext | ||
import org.jooq.ExecuteListener | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
class JaegerDbSpanCreator( | ||
private val tracer: Tracer, | ||
) : ExecuteListener { | ||
|
||
companion object { | ||
const val CONTEXT_KEY_SPAN_ID = "spanId" | ||
} | ||
|
||
private val spanIdToSpan = ConcurrentHashMap<String, Span>() | ||
|
||
override fun start(ctx: ExecuteContext) { | ||
val span = tracer.spanBuilder("PostgreSQL Query").startSpan() | ||
span.setAttribute("sql", ctx.query().toString()) | ||
val spanId = span.spanContext.spanId | ||
spanIdToSpan[spanId] = span | ||
ctx.data(CONTEXT_KEY_SPAN_ID, spanId) | ||
} | ||
|
||
override fun end(ctx: ExecuteContext) { | ||
val spanId = ctx.data(CONTEXT_KEY_SPAN_ID) | ||
val span = spanIdToSpan.remove(spanId) | ||
?: throw RuntimeException("No span for Span ID=`${spanId}`") // fail-fast in case of breaking invariant | ||
span.end() | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
server/app/src/main/kotlin/mu/muse/application/muse/TracingConfiguration.kt
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,20 @@ | ||
package mu.muse.application.muse | ||
|
||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class TracingConfiguration( | ||
@Value("\${tracing.url}") private val tracingUrl: String, | ||
) { | ||
|
||
@Bean | ||
fun otlpHttpSpanExporter(): OtlpGrpcSpanExporter { | ||
return OtlpGrpcSpanExporter | ||
.builder() | ||
.setEndpoint(tracingUrl) | ||
.build() | ||
} | ||
} |
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