[otel] refactor: remove redundant opentelemetry computeWithSpanAttribute util

GitOrigin-RevId: bf668f0228930467b99f6b9a60907370204b5116
This commit is contained in:
Andrei Efanov
2024-07-31 10:48:23 +02:00
committed by intellij-monorepo-bot
parent 357361c034
commit 177123caaa
2 changed files with 27 additions and 58 deletions

View File

@@ -3,7 +3,6 @@ package com.intellij.platform.diagnostic.telemetry.helpers
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.util.ThrowableNotNullFunction
import com.intellij.platform.diagnostic.telemetry.IJTracer
import com.intellij.util.ThrowableConsumer
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.trace.Span
@@ -74,33 +73,6 @@ suspend inline fun <T> SpanBuilder.useWithScope(context: CoroutineContext = Empt
}
}
@Internal
fun <T> computeWithSpanAttribute(tracer: IJTracer,
spanName: String,
attributeName: String,
attributeValue: (T) -> String,
operation: () -> T): T {
return tracer.spanBuilder(spanName).use { span ->
val result = operation.invoke()
span.setAttribute(attributeName, attributeValue.invoke(result))
result
}
}
@Internal
fun <T> computeWithSpanAttributes(tracer: IJTracer,
spanName: String,
attributeGenerator: (T) -> Map<String, String>,
operation: () -> T): T {
return tracer.spanBuilder(spanName).use { span ->
val result = operation.invoke()
attributeGenerator.invoke(result).forEach { (attributeName, attributeValue) ->
span.setAttribute(attributeName, attributeValue)
}
result
}
}
@Internal
inline fun <T> computeWithSpan(tracer: Tracer, spanName: String, operation: (Span) -> T): T {
return tracer.spanBuilder(spanName).use(operation)

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.platform.diagnostic.telemetry.IJTracer;
import com.intellij.platform.diagnostic.telemetry.Scope;
import com.intellij.platform.diagnostic.telemetry.TelemetryManager;
import com.intellij.platform.diagnostic.telemetry.helpers.TraceKt;
import com.intellij.testFramework.BenchmarkTestInfo;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.ProfilerForTests;
@@ -39,8 +40,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Supplier;
import static com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.computeWithSpanAttribute;
public class BenchmarkTestInfoImpl implements BenchmarkTestInfo {
private enum IterationMode {
WARMUP,
@@ -321,40 +320,38 @@ public class BenchmarkTestInfoImpl implements BenchmarkTestInfo {
}
try {
computeWithSpanAttribute(tracer, uniqueTestName, "warmup", (st) -> String.valueOf(iterationType.equals(IterationMode.WARMUP)), () -> {
try {
PlatformTestUtil.waitForAllBackgroundActivityToCalmDown();
TraceKt.use(tracer.spanBuilder(uniqueTestName).setAttribute("warmup", String.valueOf(iterationType.equals(IterationMode.WARMUP))),
__ -> {
try {
PlatformTestUtil.waitForAllBackgroundActivityToCalmDown();
for (int attempt = 1; attempt <= maxIterationsNumber; attempt++) {
AtomicInteger actualInputSize;
for (int attempt = 1; attempt <= maxIterationsNumber; attempt++) {
AtomicInteger actualInputSize;
if (setup != null) setup.run();
actualInputSize = new AtomicInteger(expectedInputSize);
if (setup != null) setup.run();
actualInputSize = new AtomicInteger(expectedInputSize);
Supplier<Object> perfTestWorkload = getPerfTestWorkloadSupplier(iterationType, attempt, actualInputSize);
Supplier<Object> perfTestWorkload = getPerfTestWorkloadSupplier(iterationType, attempt, actualInputSize);
computeWithSpanAttribute(
tracer, "Attempt: " + attempt,
"warmup",
(st) -> String.valueOf(iterationType.equals(IterationMode.WARMUP)),
() -> perfTestWorkload.get()
);
TraceKt.use(tracer.spanBuilder("Attempt: " + attempt)
.setAttribute("warmup", String.valueOf(iterationType.equals(IterationMode.WARMUP))),
ignore -> perfTestWorkload.get());
if (!UsefulTestCase.IS_UNDER_TEAMCITY) {
// TODO: Print debug metrics here https://youtrack.jetbrains.com/issue/AT-726
}
//noinspection CallToSystemGC
System.gc();
StorageLockContext.forceDirectMemoryCache();
}
}
catch (Throwable throwable) {
ExceptionUtil.rethrowUnchecked(throwable);
throw new RuntimeException(throwable);
}
if (!UsefulTestCase.IS_UNDER_TEAMCITY) {
// TODO: Print debug metrics here https://youtrack.jetbrains.com/issue/AT-726
}
//noinspection CallToSystemGC
System.gc();
StorageLockContext.forceDirectMemoryCache();
}
}
catch (Throwable throwable) {
ExceptionUtil.rethrowUnchecked(throwable);
throw new RuntimeException(throwable);
}
return null;
});
return null;
});
}
finally {
try {