Skip to content

Commit

Permalink
tracer can be configurable (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
elopezcastro authored Jan 10, 2024
1 parent f5cfeac commit f5b09b3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class OpenTracingConfiguration
@JsonProperty
private AuthenticationProvider authenticationProvider;

@JsonProperty
private TracerProvider tracerProvider;

public String getOpenTracingUri()
{
return openTracingUri;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,7 @@ protected void configureObjectMapper(Bootstrap<T> bootstrap)
{
StorageConfiguration.configureObjectMapper(bootstrap.getObjectMapper());
TracingAuthenticationProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper());
TracerProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper());
PrometheusMetricsProviderConfiguration.configureObjectMapper(bootstrap.getObjectMapper());
}

Expand Down

0 comments on commit f5b09b3

Please sign in to comment.