Skip to content

Commit

Permalink
Make Tracer injectable (#8696)
Browse files Browse the repository at this point in the history
* Make Tracer injectable

Signed-off-by: suranjay <[email protected]>

* Add changelog entry

Signed-off-by: suranjay <[email protected]>

* Remove entry from CHANGELOG.md

Signed-off-by: suranjay <[email protected]>

---------

Signed-off-by: suranjay <[email protected]>
  • Loading branch information
suranjay authored Jul 19, 2023
1 parent 1d3b006 commit 83a4b6e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.opensearch.plugins.ExtensionAwarePlugin;
import org.opensearch.plugins.SearchPipelinePlugin;
import org.opensearch.telemetry.tracing.NoopTracerFactory;
import org.opensearch.telemetry.tracing.Tracer;
import org.opensearch.telemetry.tracing.TracerFactory;
import org.opensearch.search.backpressure.SearchBackpressureService;
import org.opensearch.search.backpressure.settings.SearchBackpressureSettings;
Expand Down Expand Up @@ -378,7 +379,7 @@ public static class DiscoverySettings {
private final Collection<LifecycleComponent> pluginLifecycleComponents;
private final LocalNodeFactory localNodeFactory;
private final NodeService nodeService;
private final TracerFactory tracerFactory;
private final Tracer tracer;
final NamedWriteableRegistry namedWriteableRegistry;
private final AtomicReference<RunnableTaskExecutionListener> runnableTaskListener;
private FileCache fileCache;
Expand Down Expand Up @@ -1027,6 +1028,7 @@ protected Node(
searchModule.getIndexSearcherExecutor(threadPool)
);

TracerFactory tracerFactory;
if (FeatureFlags.isEnabled(TELEMETRY)) {
final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings());
List<TelemetryPlugin> telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class);
Expand All @@ -1035,7 +1037,8 @@ protected Node(
} else {
tracerFactory = new NoopTracerFactory();
}
resourcesToClose.add(tracerFactory::close);
tracer = tracerFactory.getTracer();
resourcesToClose.add(tracer::close);

final List<PersistentTasksExecutor<?>> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class)
.stream()
Expand Down Expand Up @@ -1142,7 +1145,7 @@ protected Node(
b.bind(FsHealthService.class).toInstance(fsHealthService);
b.bind(SystemIndices.class).toInstance(systemIndices);
b.bind(IdentityService.class).toInstance(identityService);
b.bind(TracerFactory.class).toInstance(this.tracerFactory);
b.bind(Tracer.class).toInstance(tracer);
});
injector = modules.createInjector();

Expand Down Expand Up @@ -1499,7 +1502,7 @@ public synchronized void close() throws IOException {
toClose.add(injector.getInstance(NodeEnvironment.class));
toClose.add(stopWatch::stop);
if (FeatureFlags.isEnabled(TELEMETRY)) {
toClose.add(injector.getInstance(TracerFactory.class));
toClose.add(injector.getInstance(Tracer.class));
}

if (logger.isTraceEnabled()) {
Expand Down

0 comments on commit 83a4b6e

Please sign in to comment.