Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate misk.tracing extensions #2810

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object Dependencies {
val wireRuntime = "com.squareup.wire:wire-runtime:4.6.2"
val wireSchema = "com.squareup.wire:wire-schema:4.6.2"
val wispAwsEnvironment = "app.cash.wisp:wisp-aws-environment"
val wispBom = "app.cash.wisp:wisp-bom:1.4.2"
val wispBom = "app.cash.wisp:wisp-bom:1.4.3"
val wispClient = "app.cash.wisp:wisp-client"
val wispConfig = "app.cash.wisp:wisp-config"
val wispContainersTesting = "app.cash.wisp:wisp-containers-testing"
Expand All @@ -179,4 +179,5 @@ object Dependencies {
val wispTimeTesting = "app.cash.wisp:wisp-time-testing"
val wispToken = "app.cash.wisp:wisp-token"
val wispTokenTesting = "app.cash.wisp:wisp-token-testing"
val wispTracing = "app.cash.wisp:wisp-tracing"
}
1 change: 1 addition & 0 deletions misk-aws/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation(Dependencies.tracingDatadog)
implementation(Dependencies.wispDeployment)
implementation(Dependencies.wispLogging)
implementation(Dependencies.wispTracing)
implementation(project(":misk-core"))
implementation(project(":misk-hibernate"))
implementation(project(":misk-metrics"))
Expand Down
3 changes: 1 addition & 2 deletions misk-aws/src/main/kotlin/misk/jobqueue/sqs/SqsJobConsumer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import misk.jobqueue.QueueName
import misk.tasks.RepeatedTaskQueue
import misk.tasks.Status
import misk.time.timed
import misk.tracing.traceWithNewRootSpan
import okhttp3.internal.toLongOrDefault
import org.slf4j.MDC
import wisp.lease.LeaseManager
import wisp.logging.getLogger
import wisp.tracing.traceWithNewRootSpan
import java.time.Clock
import java.time.Duration
import java.util.concurrent.CompletableFuture
Expand Down
8 changes: 4 additions & 4 deletions misk-aws/src/main/kotlin/misk/jobqueue/sqs/SqsJobQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import misk.jobqueue.JobQueue.Companion.SQS_MAX_BATCH_ENQUEUE_JOB_SIZE
import misk.jobqueue.QueueName
import misk.moshi.adapter
import misk.time.timed
import misk.tracing.traceWithSpan
import wisp.tracing.traceWithSpan
import java.time.Duration
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -163,9 +163,9 @@ internal class SqsJobQueue @Inject internal constructor(
queueName.value,
queueName.value
)
}
catch (batchEnqueueException: JobQueue.BatchEnqueueException) {
metrics.jobEnqueueFailures.labels(queueName.value, queueName.value).inc(batchEnqueueException.failed.size.toDouble())
} catch (batchEnqueueException: JobQueue.BatchEnqueueException) {
metrics.jobEnqueueFailures.labels(queueName.value, queueName.value)
.inc(batchEnqueueException.failed.size.toDouble())
throw batchEnqueueException
} catch (th: Throwable) {
metrics.jobEnqueueFailures.labels(queueName.value, queueName.value).inc()
Expand Down
1 change: 1 addition & 0 deletions misk-gcp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ dependencies {
testImplementation(Dependencies.kotlinTest)
testImplementation(Dependencies.openTracingDatadog)
testImplementation(Dependencies.wispContainersTesting)
testImplementation(Dependencies.wispTracing)
testImplementation(project(":misk-gcp"))
testImplementation(project(":misk-testing"))
testImplementation(testFixtures(project(":misk-gcp")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ddtrot.dd.trace.common.writer.Writer
import ddtrot.dd.trace.core.DDSpan
import io.opentracing.noop.NoopTracerFactory
import misk.testing.MiskTest
import misk.tracing.traceWithSpan
import wisp.tracing.traceWithSpan
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import javax.inject.Singleton
* Extends [MockTracer] for use in concurrent environments, such as a web server and test client.
* Prefer this wherever you'd otherwise use [MockTracer].
*/
// TODO(keefer): Deprecate this (or forward the type via delegate) when wisp-tracing-test-fixtures
// publication is fixed. wisp-tracing provides a preferred copy of this class.
@Singleton
class ConcurrentMockTracer @Inject constructor() : MockTracer() {
private val queue = LinkedBlockingDeque<MockSpan>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import misk.inject.KAbstractModule

class MockTracingBackendModule : KAbstractModule() {
override fun configure() {
// TODO(keefer): Update to use wisp-tracing's ConcurrentMockTracer instead.
bind<MockTracer>().to<ConcurrentMockTracer>()
bind<Tracer>().to<ConcurrentMockTracer>()
}
Expand Down
1 change: 1 addition & 0 deletions misk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
implementation(Dependencies.wispLogging)
implementation(Dependencies.wispMoshi)
implementation(Dependencies.wispSsl)
implementation(Dependencies.wispTracing)
implementation(project(":misk-prometheus"))
implementation(project(":misk-proto"))
implementation(project(":misk-service"))
Expand Down
66 changes: 28 additions & 38 deletions misk/src/main/kotlin/misk/tracing/TracerExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,43 @@ package misk.tracing

import io.opentracing.Span
import io.opentracing.Tracer
import io.opentracing.tag.Tags

/** [trace] traces the given function with the specific span name and optional tags */
import wisp.tracing.trace as wispTrace
import wisp.tracing.traceWithNewRootSpan as wispTraceWithNewRootSpan
import wisp.tracing.traceWithSpan as wispTraceWithSpan

@Deprecated(
message = "Prefer wisp-tracing.",
replaceWith = ReplaceWith(
expression = "this.trace(spanName, tags, f)",
imports = ["wisp.tracing.trace"]
)
)
fun <T : Any?> Tracer.trace(spanName: String, tags: Map<String, String> = mapOf(), f: () -> T): T =
traceWithSpan(spanName, tags) { f() }
wispTrace(spanName, tags, f)

/** [traceWithSpan] traces the given function, passing the span into the function.
* If a span is already active, the new span is made a child of the existing. */
@Deprecated(
message = "Prefer wisp-tracing.",
replaceWith = ReplaceWith(
expression = "this.traceWithSpan(spanName, tags, f)",
imports = ["wisp.tracing.traceWithSpan"]
)
)
fun <T : Any?> Tracer.traceWithSpan(
spanName: String,
tags: Map<String, String> = mapOf(),
f: (Span) -> T
): T {
return traceWithSpanInternal(spanName, tags, true, f)
}
): T = wispTraceWithSpan(spanName, tags, f)

/** [traceWithNewRootSpan] traces the given function, always starting a new root span */
@Deprecated(
message = "Prefer wisp-tracing.",
replaceWith = ReplaceWith(
expression = "this.traceWithNewRootSpan(spanName, tags, false, f)",
imports = ["wisp.tracing.traceWithNewRootSpan"]
)
)
fun <T : Any?> Tracer.traceWithNewRootSpan(
spanName: String,
tags: Map<String, String> = mapOf(),
f: (Span) -> T
): T {
return traceWithSpanInternal(spanName, tags, false, f)
}

private fun <T : Any?> Tracer.traceWithSpanInternal(
spanName: String,
tags: Map<String, String> = mapOf(),
asChild: Boolean,
f: (Span) -> T
): T {
var spanBuilder = buildSpan(spanName)
tags.forEach { (k, v) -> spanBuilder.withTag(k, v) }

if (!asChild) {
spanBuilder = spanBuilder.ignoreActiveSpan()
}

val span = spanBuilder.start()
val scope = scopeManager().activate(span)
return try {
f(span)
} catch (t: Throwable) {
Tags.ERROR.set(span, true)
throw t
} finally {
scope.close()
span.finish()
}
}
): T = wispTraceWithNewRootSpan(spanName, tags, retainBaggage = false, f)
88 changes: 0 additions & 88 deletions misk/src/test/kotlin/misk/tracing/TracerExtTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import misk.testing.ConcurrentMockTracer
import misk.testing.MiskTest
import misk.testing.MiskTestModule
import misk.testing.MockTracingBackendModule
import misk.tracing.traceWithSpan
import misk.web.DispatchMechanism
import misk.web.FakeHttpCall
import misk.web.Get
Expand All @@ -25,6 +24,7 @@ import misk.web.jetty.JettyService
import okhttp3.Headers.Companion.headersOf
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import wisp.tracing.traceWithSpan
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import java.net.HttpURLConnection
Expand Down