diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/OpenTracingConfiguration.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/OpenTracingConfiguration.java index c1c7c182f..d1d8d5315 100644 --- a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/OpenTracingConfiguration.java +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/OpenTracingConfiguration.java @@ -33,6 +33,9 @@ public class OpenTracingConfiguration @JsonProperty private AuthenticationProvider authenticationProvider; + @JsonProperty + private TracerProvider tracerProvider; + public String getOpenTracingUri() { return openTracingUri; @@ -72,4 +75,14 @@ public void setAuthenticationProvider(AuthenticationProvider authenticationProvi { this.authenticationProvider = authenticationProvider; } + + public TracerProvider getTracerProvider() + { + return tracerProvider; + } + + public void setTracerProvider(TracerProvider tracerProvider) + { + this.tracerProvider = tracerProvider; + } } diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProvider.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProvider.java new file mode 100644 index 000000000..355a1516a --- /dev/null +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProvider.java @@ -0,0 +1,24 @@ +// Copyright 2021 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.core.services.api.tracing.configuration; + +import io.opentracing.Tracer; +import zipkin2.reporter.Sender; + +public interface TracerProvider +{ + Tracer create(Sender sender, String serviceName); +} diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProviderConfiguration.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProviderConfiguration.java new file mode 100644 index 000000000..c8cbb1aa9 --- /dev/null +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/api/tracing/configuration/TracerProviderConfiguration.java @@ -0,0 +1,39 @@ +// Copyright 2021 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.core.services.api.tracing.configuration; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.finos.legend.opentracing.AuthenticationProvider; + +public abstract class TracerProviderConfiguration +{ + private TracerProviderConfiguration() + { + } + + public static ObjectMapper configureObjectMapper(ObjectMapper objectMapper) + { + @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) + abstract class WrapperMixin + { + } + + return objectMapper + .addMixIn(TracerProvider.class, WrapperMixin.class); + } + +} diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/DefaultTracerProvider.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/DefaultTracerProvider.java new file mode 100644 index 000000000..c66026a28 --- /dev/null +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/DefaultTracerProvider.java @@ -0,0 +1,46 @@ +// Copyright 2021 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package org.finos.legend.depot.core.services.tracing; + +import io.opentracing.Tracer; +import io.prometheus.client.CollectorRegistry; +import org.finos.legend.depot.core.services.api.tracing.configuration.TracerProvider; +import org.finos.legend.engine.shared.core.operational.prometheus.TracingExports; +import org.finos.legend.opentracing.OpenTracing; +import zipkin2.reporter.InMemoryReporterMetrics; +import zipkin2.reporter.Sender; + +import java.util.logging.Level; +import java.util.logging.LogManager; + +public class DefaultTracerProvider implements TracerProvider +{ + @Override + public Tracer create(Sender sender,String serviceName) + { + Tracer tracer = OpenTracing.create(sender, serviceName, null, getMemoryMetricsReporter()); + LogManager.getLogManager().getLogger("").setLevel(Level.FINE); + return tracer; + } + + private InMemoryReporterMetrics getMemoryMetricsReporter() + { + CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry; + InMemoryReporterMetrics tracingMetrics = new InMemoryReporterMetrics(); + collectorRegistry.register(new TracingExports(tracingMetrics)); + return tracingMetrics; + } +} diff --git a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/TracerFactory.java b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/TracerFactory.java index df882f322..11cf68765 100644 --- a/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/TracerFactory.java +++ b/legend-depot-core-tracing/src/main/java/org/finos/legend/depot/core/services/tracing/TracerFactory.java @@ -26,6 +26,7 @@ import org.finos.legend.depot.core.services.api.tracing.TracingException; import org.finos.legend.depot.core.services.api.tracing.VoidAuthenticationProvider; import org.finos.legend.depot.core.services.api.tracing.configuration.OpenTracingConfiguration; +import org.finos.legend.depot.core.services.api.tracing.configuration.TracerProvider; import org.finos.legend.engine.shared.core.operational.prometheus.TracingExports; import org.finos.legend.opentracing.AuthenticationProvider; import org.finos.legend.opentracing.JerseyClientSender; @@ -82,9 +83,8 @@ public static TracerFactory configure(OpenTracingConfiguration openTracingConfig openTracingConfiguration.getServiceName() : DEFAULT_SERVICE_NAME; try (JerseyClientSender sender = new JerseyClientSender(new URI(openTracingConfiguration.getOpenTracingUri()), authenticationProvider);) { - - Tracer tracer = OpenTracing.create(sender, serviceName, null, getMemoryMetricsReporter()); - LogManager.getLogManager().getLogger("").setLevel(Level.FINE); + TracerProvider tracerProvider = openTracingConfiguration.getTracerProvider() != null ? openTracingConfiguration.getTracerProvider() : new DefaultTracerProvider(); + Tracer tracer = tracerProvider.create(sender,serviceName); GlobalTracer.registerIfAbsent(tracer); INSTANCE = new TracerFactory(tracer); } @@ -101,13 +101,7 @@ public static TracerFactory configure(OpenTracingConfiguration openTracingConfig return INSTANCE; } - private static InMemoryReporterMetrics getMemoryMetricsReporter() - { - CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry; - InMemoryReporterMetrics tracingMetrics = new InMemoryReporterMetrics(); - collectorRegistry.register(new TracingExports(tracingMetrics)); - return tracingMetrics; - } + private Span startSpan(String trace) { diff --git a/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/server/BaseServer.java b/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/server/BaseServer.java index 9d331945a..bd4bfb471 100644 --- a/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/server/BaseServer.java +++ b/legend-depot-servers-common/src/main/java/org/finos/legend/depot/core/server/BaseServer.java @@ -35,6 +35,7 @@ import org.eclipse.jetty.servlets.CrossOriginFilter; import org.eclipse.jetty.util.component.LifeCycle; import org.finos.legend.depot.core.services.api.metrics.configuration.PrometheusMetricsProviderConfiguration; +import org.finos.legend.depot.core.services.api.tracing.configuration.TracerProviderConfiguration; import org.finos.legend.depot.core.services.api.tracing.configuration.TracingAuthenticationProviderConfiguration; import org.finos.legend.depot.core.services.metrics.PrometheusMetricsFactory; import org.finos.legend.depot.store.StorageConfiguration; @@ -90,6 +91,7 @@ protected void configureObjectMapper(Bootstrap bootstrap) { StorageConfiguration.configureObjectMapper(bootstrap.getObjectMapper()); TracingAuthenticationProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper()); + TracerProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper()); PrometheusMetricsProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper()); }