diff --git a/clients/client/src/main/java/org/projectnessie/client/NessieHttpClient.java b/clients/client/src/main/java/org/projectnessie/client/NessieHttpClient.java index 35703506651..209e3849d15 100644 --- a/clients/client/src/main/java/org/projectnessie/client/NessieHttpClient.java +++ b/clients/client/src/main/java/org/projectnessie/client/NessieHttpClient.java @@ -23,7 +23,7 @@ import io.opentracing.log.Fields; import io.opentracing.propagation.Format.Builtin; import io.opentracing.propagation.TextMap; -import io.opentracing.propagation.TextMapInjectAdapter; +import io.opentracing.propagation.TextMapAdapter; import io.opentracing.tag.Tags; import io.opentracing.util.GlobalTracer; import java.io.IOException; @@ -104,16 +104,14 @@ private static void addTracing(HttpClient httpClient) { context -> { Span span = tracer.activeSpan(); if (span != null) { - Scope scope = tracer.buildSpan("Nessie-HTTP").startActive(true); + Span inner = tracer.buildSpan("Nessie-HTTP").start(); + Scope scope = tracer.activateSpan(inner); context.addResponseCallback( (responseContext, exception) -> { if (responseContext != null) { try { - scope - .span() - .setTag( - "http.status_code", - responseContext.getResponseCode().getCode()); + inner.setTag( + "http.status_code", responseContext.getResponseCode().getCode()); } catch (IOException e) { // There's not much we can (and probably should) do here. } @@ -122,19 +120,18 @@ private static void addTracing(HttpClient httpClient) { Map log = new HashMap<>(); log.put(Fields.EVENT, Tags.ERROR.getKey()); log.put(Fields.ERROR_OBJECT, exception.toString()); - Tags.ERROR.set(scope.span().log(log), true); + Tags.ERROR.set(inner.log(log), true); } scope.close(); }); - scope - .span() + inner .setTag("http.uri", context.getUri().toString()) .setTag("http.method", context.getMethod().name()); HashMap headerMap = new HashMap<>(); - TextMap httpHeadersCarrier = new TextMapInjectAdapter(headerMap); - tracer.inject(scope.span().context(), Builtin.HTTP_HEADERS, httpHeadersCarrier); + TextMap httpHeadersCarrier = new TextMapAdapter(headerMap); + tracer.inject(inner.context(), Builtin.HTTP_HEADERS, httpHeadersCarrier); headerMap.forEach(context::putHeader); } }); diff --git a/clients/client/src/test/java/org/projectnessie/client/TestNessieHttpClient.java b/clients/client/src/test/java/org/projectnessie/client/TestNessieHttpClient.java index 4e7d32d0ad6..a490c9c1ed0 100644 --- a/clients/client/src/test/java/org/projectnessie/client/TestNessieHttpClient.java +++ b/clients/client/src/test/java/org/projectnessie/client/TestNessieHttpClient.java @@ -78,7 +78,9 @@ void testTracing() throws Exception { try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) { NessieClient client = NessieClient.builder().withUri(server.getUri()).withTracing(true).build(); - try (Scope ignore = GlobalTracer.get().buildSpan("testOpenTracing").startActive(true)) { + try (Scope ignore = + GlobalTracer.get() + .activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) { client.getConfigApi().getConfig(); } } @@ -96,7 +98,9 @@ void testTracingNotEnabled() throws Exception { try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) { NessieClient client = NessieClient.builder().withUri(server.getUri()).withTracing(false).build(); - try (Scope ignore = GlobalTracer.get().buildSpan("testOpenTracing").startActive(true)) { + try (Scope ignore = + GlobalTracer.get() + .activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) { client.getConfigApi().getConfig(); } } diff --git a/pom.xml b/pom.xml index 2d264679ecc..138f676857d 100644 --- a/pom.xml +++ b/pom.xml @@ -147,10 +147,10 @@ 5.7.2 1.2.3 3.11.2 - 1.1.2 + 2.0 0.9.0 3.17.3 - 1.13.7.Final + 2.0.0.Final 2020.0.8 2.12.13 2.13.6 diff --git a/servers/quarkus-server/pom.xml b/servers/quarkus-server/pom.xml index ef03d270aea..2d7f1cc88ae 100644 --- a/servers/quarkus-server/pom.xml +++ b/servers/quarkus-server/pom.xml @@ -66,6 +66,10 @@ io.quarkus quarkus-hibernate-validator + + io.quarkus + quarkus-jgit + jakarta.validation jakarta.validation-api @@ -93,6 +97,10 @@ io.quarkus quarkus-resteasy + + io.quarkus + quarkus-apache-httpclient + io.quarkus quarkus-junit5 diff --git a/tools/apprunner-gradle-plugin/src/main/java/org/projectnessie/quarkus/gradle/QuarkusApp.java b/tools/apprunner-gradle-plugin/src/main/java/org/projectnessie/quarkus/gradle/QuarkusApp.java index 8881dad62a5..b6cdf081ce9 100644 --- a/tools/apprunner-gradle-plugin/src/main/java/org/projectnessie/quarkus/gradle/QuarkusApp.java +++ b/tools/apprunner-gradle-plugin/src/main/java/org/projectnessie/quarkus/gradle/QuarkusApp.java @@ -15,7 +15,7 @@ */ package org.projectnessie.quarkus.gradle; -import static io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor.toArtifact; +import static io.quarkus.bootstrap.util.DependencyNodeUtils.toArtifact; import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.APP_CONFIG_NAME; import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.LAUNCH_CONFIG_NAME; import static org.projectnessie.quarkus.gradle.QuarkusAppPlugin.RUNTIME_CONFIG_NAME; diff --git a/tools/apprunner-maven-plugin/src/main/java/org/projectnessie/quarkus/maven/MojoConfigSource.java b/tools/apprunner-maven-plugin/src/main/java/org/projectnessie/quarkus/maven/MojoConfigSource.java index 10ca93f8540..1a260e2f4db 100644 --- a/tools/apprunner-maven-plugin/src/main/java/org/projectnessie/quarkus/maven/MojoConfigSource.java +++ b/tools/apprunner-maven-plugin/src/main/java/org/projectnessie/quarkus/maven/MojoConfigSource.java @@ -17,7 +17,9 @@ import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.TreeMap; +import java.util.stream.Collectors; import org.eclipse.microprofile.config.spi.ConfigSource; /** A config source to override default application when using apprunner. */ @@ -35,6 +37,11 @@ public Map getProperties() { return map; } + @Override + public Set getPropertyNames() { + return properties.keySet().stream().map(String.class::cast).collect(Collectors.toSet()); + } + @Override public String getValue(String propertyName) { Object obj = properties.get(propertyName); diff --git a/versioned/spi/src/main/java/org/projectnessie/versioned/TracingUtil.java b/versioned/spi/src/main/java/org/projectnessie/versioned/TracingUtil.java index 590a6d98498..503640f3e3a 100644 --- a/versioned/spi/src/main/java/org/projectnessie/versioned/TracingUtil.java +++ b/versioned/spi/src/main/java/org/projectnessie/versioned/TracingUtil.java @@ -16,7 +16,7 @@ package org.projectnessie.versioned; import com.google.common.collect.ImmutableMap; -import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.log.Fields; import io.opentracing.tag.Tags; import java.util.Collection; @@ -39,17 +39,14 @@ public static int safeSize(Collection collection) { /** * Set {@link Tags#ERROR} with {@link Fields#EVENT} + {@link Fields#ERROR_OBJECT}. * - * @param scope trace-scope + * @param span trace-span * @param e exception to trace * @return returns {@code e} */ - public static RuntimeException traceError(Scope scope, RuntimeException e) { + public static RuntimeException traceError(Span span, RuntimeException e) { Tags.ERROR.set( - scope - .span() - .log( - ImmutableMap.of( - Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, e.toString())), + span.log( + ImmutableMap.of(Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, e.toString())), true); return e; } diff --git a/versioned/spi/src/main/java/org/projectnessie/versioned/TracingVersionStore.java b/versioned/spi/src/main/java/org/projectnessie/versioned/TracingVersionStore.java index 18769102b4e..0cbd37722dc 100644 --- a/versioned/spi/src/main/java/org/projectnessie/versioned/TracingVersionStore.java +++ b/versioned/spi/src/main/java/org/projectnessie/versioned/TracingVersionStore.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.Tracer.SpanBuilder; import io.opentracing.util.GlobalTracer; @@ -200,13 +201,18 @@ public Collector collectGarbage() { return call("CollectGarbage", b -> {}, delegate::collectGarbage); } - private Scope createActiveScope(String name, Consumer spanBuilder) { + private Span createSpan(String name, Consumer spanBuilder) { Tracer tracer = GlobalTracer.get(); String spanName = makeSpanName(name); SpanBuilder builder = tracer.buildSpan(spanName).asChildOf(tracer.activeSpan()).withTag(TAG_OPERATION, name); spanBuilder.accept(builder); - return builder.startActive(true); + return builder.start(); + } + + private Scope activeScope(Span span) { + Tracer tracer = GlobalTracer.get(); + return tracer.activateSpan(span); } @VisibleForTesting @@ -216,7 +222,8 @@ static String makeSpanName(String name) { private Stream callStream( String spanName, Consumer spanBuilder, Invoker> invoker) { - Scope scope = createActiveScope(spanName, spanBuilder); + Span span = createSpan(spanName, spanBuilder); + Scope scope = activeScope(span); Stream result = null; try { result = invoker.handle().onClose(scope::close); @@ -225,7 +232,7 @@ private Stream callStream( // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } finally { // See below (callStreamWithOneException) if (result == null) { @@ -239,7 +246,8 @@ private Stream callStreamWithOneExcepti Consumer spanBuilder, InvokerWithOneException, E1> invoker) throws E1 { - Scope scope = createActiveScope(spanName, spanBuilder); + Span span = createSpan(spanName, spanBuilder); + Scope scope = activeScope(span); Stream result = null; try { result = invoker.handle().onClose(scope::close); @@ -248,7 +256,7 @@ private Stream callStreamWithOneExcepti // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } finally { // We cannot `catch (E1 e)`, so assume that the delegate threw an exception, when result==null // and then close the trace-scope. @@ -259,14 +267,15 @@ private Stream callStreamWithOneExcepti } private R call(String spanName, Consumer spanBuilder, Invoker invoker) { - try (Scope scope = createActiveScope(spanName, spanBuilder)) { + Span span = createSpan(spanName, spanBuilder); + try (Scope scope = activeScope(span)) { try { return invoker.handle(); } catch (IllegalArgumentException e) { // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } } } @@ -274,14 +283,15 @@ private R call(String spanName, Consumer spanBuilder, Invoker R callWithOneException( String spanName, Consumer spanBuilder, InvokerWithOneException invoker) throws E1 { - try (Scope scope = createActiveScope(spanName, spanBuilder)) { + Span span = createSpan(spanName, spanBuilder); + try (Scope scope = activeScope(span)) { try { return invoker.handle(); } catch (IllegalArgumentException e) { // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } } } @@ -292,14 +302,15 @@ void callWithTwoExceptions( Consumer spanBuilder, InvokerWithTwoExceptions invoker) throws E1, E2 { - try (Scope scope = createActiveScope(spanName, spanBuilder)) { + Span span = createSpan(spanName, spanBuilder); + try (Scope scope = activeScope(span)) { try { invoker.handle(); } catch (IllegalArgumentException e) { // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } } } @@ -310,14 +321,15 @@ R callWithTwoExceptions( Consumer spanBuilder, InvokerWithTwoExceptionsR invoker) throws E1, E2 { - try (Scope scope = createActiveScope(spanName, spanBuilder)) { + Span span = createSpan(spanName, spanBuilder); + try (Scope scope = activeScope(span)) { try { return invoker.handle(); } catch (IllegalArgumentException e) { // IllegalArgumentException is a special kind of exception that indicates a user-error. throw e; } catch (RuntimeException e) { - throw traceError(scope, e); + throw traceError(span, e); } } } diff --git a/versioned/spi/src/test/java/org/projectnessie/versioned/test/tracing/TestTracer.java b/versioned/spi/src/test/java/org/projectnessie/versioned/test/tracing/TestTracer.java index 84c35cb9270..f68caf7b2d7 100644 --- a/versioned/spi/src/test/java/org/projectnessie/versioned/test/tracing/TestTracer.java +++ b/versioned/spi/src/test/java/org/projectnessie/versioned/test/tracing/TestTracer.java @@ -24,6 +24,7 @@ import io.opentracing.SpanContext; import io.opentracing.Tracer; import io.opentracing.propagation.Format; +import io.opentracing.tag.Tag; import io.opentracing.util.GlobalTracer; import java.lang.reflect.Proxy; import java.util.ArrayList; @@ -87,6 +88,15 @@ public Span activeSpan() { return activeSpan; } + @Override + public Scope activateSpan(Span span) { + activeSpan = (TestSpan) span; + return () -> { + assertFalse(closed); + closed = true; + }; + } + @Override public SpanBuilder buildSpan(String operationName) { opName = operationName; @@ -113,21 +123,8 @@ public SpanBuilder withTag(String key, Number value) { } @Override - public Scope startActive(boolean finishSpanOnClose) { - activeSpan = new TestSpan(tags); - - return new Scope() { - @Override - public void close() { - assertFalse(closed); - closed = true; - } - - @Override - public Span span() { - return activeSpan; - } - }; + public SpanBuilder withTag(Tag tag, T t) { + throw new UnsupportedOperationException(); } @Override @@ -158,14 +155,10 @@ public SpanBuilder withStartTimestamp(long microseconds) { throw new UnsupportedOperationException(); } - @Override - public Span startManual() { - throw new UnsupportedOperationException(); - } - @Override public Span start() { - throw new UnsupportedOperationException(); + activeSpan = new TestSpan(tags); + return activeSpan; } }; } @@ -180,6 +173,9 @@ public SpanContext extract(Format format, C carrier) { throw new UnsupportedOperationException(); } + @Override + public void close() {} + public class TestSpan implements Span { private final Map tags = new HashMap<>(); @@ -220,6 +216,11 @@ public Span setTag(String key, Number value) { return this; } + @Override + public Span setTag(Tag tag, T t) { + throw new UnsupportedOperationException(); + } + @Override public Span log(Map fields) { logs.add(fields); diff --git a/versioned/tiered/dynamodb/src/main/java/org/projectnessie/versioned/dynamodb/DynamoStore.java b/versioned/tiered/dynamodb/src/main/java/org/projectnessie/versioned/dynamodb/DynamoStore.java index c9f781a4730..f642e86c856 100644 --- a/versioned/tiered/dynamodb/src/main/java/org/projectnessie/versioned/dynamodb/DynamoStore.java +++ b/versioned/tiered/dynamodb/src/main/java/org/projectnessie/versioned/dynamodb/DynamoStore.java @@ -29,8 +29,10 @@ import com.google.common.collect.Multimaps; import com.google.common.collect.Sets; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.noop.NoopScopeManager.NoopScope; +import io.opentracing.noop.NoopSpan; import io.opentracing.util.GlobalTracer; import java.util.ArrayList; import java.util.Collection; @@ -236,7 +238,8 @@ public void close() { public void load(LoadStep loadstep) throws NotFoundException { try { for (int stepNumber = 0; ; stepNumber++) { // for each load step in the chain. - try (Scope scope = createScope("load-step-" + stepNumber)) { + Span span = createSpan("load-step-" + stepNumber); + try (Scope scope = scope(span)) { List>> stepPages = paginateLoads(loadstep, paginationSize); for (int pageNumber = 0; pageNumber < stepPages.size(); pageNumber++) { @@ -271,7 +274,7 @@ public void load(LoadStep loadstep) throws NotFoundException { .consistentRead(true) .build(); })); - scope.span().log(traceLogs); + span.log(traceLogs); BatchGetItemResponse response = client.batchGetItem(BatchGetItemRequest.builder().requestItems(loads).build()); @@ -676,10 +679,19 @@ private static void verifyKeySchema(TableDescription description) { description.tableName())); } - private Scope createScope(String name) { + private Span createSpan(String name) { if (config.enableTracing()) { Tracer tracer = GlobalTracer.get(); - return tracer.buildSpan(name).asChildOf(tracer.activeSpan()).startActive(true); + return tracer.buildSpan(name).asChildOf(tracer.activeSpan()).start(); + } else { + return NoopSpan.INSTANCE; + } + } + + private Scope scope(Span span) { + if (config.enableTracing()) { + Tracer tracer = GlobalTracer.get(); + return tracer.activateSpan(span); } else { return NoopScope.INSTANCE; } diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/InternalBranch.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/InternalBranch.java index 2806c8fc97a..964cfed904a 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/InternalBranch.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/impl/InternalBranch.java @@ -23,9 +23,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.Tracer.SpanBuilder; import io.opentracing.log.Fields; +import io.opentracing.noop.NoopScopeManager.NoopScope; import io.opentracing.noop.NoopSpanBuilder; import io.opentracing.tag.Tags; import io.opentracing.util.GlobalTracer; @@ -442,18 +444,18 @@ private static InternalBranch collapseIntentionLog( InternalBranch branch, TieredVersionStoreConfig config) throws ReferenceNotFoundException, ReferenceConflictException { - try (Scope outerScope = + Span outerSpan = createSpan(config.enableTracing(), "InternalBranch.collapseIntentionLog") .withTag(TAG_OPERATION, "CollapseIntentionLog") .withTag(TAG_BRANCH, branch.getName()) - .startActive(true)) { + .start(); + try (Scope ignore = scope(config.enableTracing(), outerSpan)) { try { for (int attempt = 0; attempt < config.getP2CommitAttempts(); attempt++) { - try (Scope innerScope = - createSpan(config.enableTracing(), "Attempt-" + attempt).startActive(true)) { + Span innerSpan = createSpan(config.enableTracing(), "Attempt-" + attempt).start(); + try (Scope ignored = scope(config.enableTracing(), innerSpan)) { - innerScope - .span() + innerSpan .setTag("nessie.num-saves", updateState.saves.size()) .setTag("nessie.num-deletes", updateState.deletes.size()); @@ -461,7 +463,7 @@ private static InternalBranch collapseIntentionLog( tryCollapseIntentionLog(store, branch, updateState, attempt); if (updated.isPresent()) { - innerScope.span().setTag("nessie.completed", true); + innerSpan.setTag("nessie.completed", true); return updated.get(); } @@ -485,11 +487,9 @@ private static InternalBranch collapseIntentionLog( throw ex; } catch (Exception ex) { Tags.ERROR.set( - outerScope - .span() - .log( - ImmutableMap.of( - Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, ex.toString())), + outerSpan.log( + ImmutableMap.of( + Fields.EVENT, Tags.ERROR.getKey(), Fields.ERROR_OBJECT, ex.toString())), true); LOGGER.debug("Exception when trying to collapse intention log.", ex); Throwables.throwIfUnchecked(ex); @@ -498,6 +498,15 @@ private static InternalBranch collapseIntentionLog( } } + private static Scope scope(boolean enableTracing, Span span) { + if (enableTracing) { + Tracer tracer = GlobalTracer.get(); + return tracer.activateSpan(span); + } else { + return NoopScope.INSTANCE; + } + } + private static Optional tryCollapseIntentionLog( Store store, InternalBranch branch, UpdateState updateState, int attempt) { // ensure that any to-be-saved items are saved. This is a noop on attempt 0 since diff --git a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/store/TracingStore.java b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/store/TracingStore.java index 33edcb7ed6c..cbaefd8e558 100644 --- a/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/store/TracingStore.java +++ b/versioned/tiered/tiered-impl/src/main/java/org/projectnessie/versioned/store/TracingStore.java @@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.Tracer; import io.opentracing.Tracer.SpanBuilder; import io.opentracing.util.GlobalTracer; @@ -60,48 +61,52 @@ static String makeSpanName(String name) { @Override public void start() { - try (Scope scope = createSpan("Start").startActive(true)) { + Span span = createSpan("Start").start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { store.start(); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public void close() { - try (Scope scope = createSpan("Close").startActive(true)) { + Span span = createSpan("Close").start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { store.close(); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public void load(LoadStep loadstep) { - try (Scope scope = createSpan("Load").startActive(true)) { + Span span = createSpan("Load").start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { store.load(loadstep); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public > boolean putIfAbsent(SaveOp saveOp) { - try (Scope scope = + Span span = createSpan("PutIfAbsent") .withTag(TAG_VALUE_TYPE, safeOpTypeToString(saveOp)) .withTag(TAG_ID, safeOpIdToString(saveOp)) - .startActive(true)) { + .start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { return store.putIfAbsent(saveOp); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @@ -109,15 +114,16 @@ public > boolean putIfAbsent(SaveOp saveOp) { @Override public > void put( SaveOp saveOp, Optional condition) { - try (Scope scope = + Span span = createSpan("Put") .withTag(TAG_VALUE_TYPE, safeOpTypeToString(saveOp)) .withTag(TAG_ID, safeOpIdToString(saveOp)) - .startActive(true)) { + .start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { store.put(saveOp, condition); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @@ -125,51 +131,52 @@ public > void put( @Override public > boolean delete( ValueType type, Id id, Optional condition) { - try (Scope scope = + Span span = createSpan("Delete") .withTag(TAG_VALUE_TYPE, safeName(type)) .withTag(TAG_ID, safeToString(id)) - .startActive(true)) { + .start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { return store.delete(type, id, condition); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public void save(List> ops) { - try (Scope scope = createSpan("Save").withTag(TAG_NUM_OPS, safeSize(ops)).startActive(true)) { + Span span = createSpan("Save").withTag(TAG_NUM_OPS, safeSize(ops)).start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { - scope - .span() - .log( - ops.stream() - .collect( - Collectors.groupingBy( - op -> String.format("nessie.store.save.%s.ids", op.getType().name()), - Collectors.mapping( - op -> op.getId().toString(), Collectors.joining(", "))))); + span.log( + ops.stream() + .collect( + Collectors.groupingBy( + op -> String.format("nessie.store.save.%s.ids", op.getType().name()), + Collectors.mapping( + op -> op.getId().toString(), Collectors.joining(", "))))); store.save(ops); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public > void loadSingle(ValueType type, Id id, C consumer) { - try (Scope scope = + Span span = createSpan("LoadSingle") .withTag(TAG_VALUE_TYPE, safeName(type)) .withTag(TAG_ID, safeToString(id)) - .startActive(true)) { + .start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { store.loadSingle(type, id, consumer); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @@ -182,28 +189,30 @@ public > boolean update( Optional condition, Optional> consumer) throws NotFoundException { - try (Scope scope = + Span span = createSpan("Update") .withTag(TAG_VALUE_TYPE, safeName(type)) .withTag(TAG_ID, safeToString(id)) .withTag(TAG_UPDATE, safeToString(update)) .withTag(TAG_CONDITION, safeToString(condition)) - .startActive(true)) { + .start(); + try (Scope scope = GlobalTracer.get().activateSpan(span)) { try { return store.update(type, id, update, condition, consumer); } catch (RuntimeException e) { - throw traceRuntimeException(scope, e); + throw traceRuntimeException(span, e); } } } @Override public > Stream> getValues(ValueType type) { - Scope scope = createSpan("GetValues").withTag(TAG_VALUE_TYPE, type.name()).startActive(true); + Span span = createSpan("GetValues").withTag(TAG_VALUE_TYPE, type.name()).start(); + Scope scope = GlobalTracer.get().activateSpan(span); try { return store.getValues(type).onClose(scope::close); } catch (RuntimeException e) { - e = traceRuntimeException(scope, e); + e = traceRuntimeException(span, e); scope.close(); throw e; } @@ -221,9 +230,9 @@ private static > String safeOpTypeToString(SaveOp save return saveOp != null ? safeName(saveOp.getType()) : ""; } - private static RuntimeException traceRuntimeException(Scope scope, RuntimeException e) { + private static RuntimeException traceRuntimeException(Span span, RuntimeException e) { if (!(e instanceof StoreException) || e instanceof StoreOperationException) { - return traceError(scope, e); + return traceError(span, e); } return e; }