Skip to content

Commit

Permalink
Add a console tracker for testing / development
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <peternied@hotmail.com>
  • Loading branch information
peternied committed Jun 4, 2024
1 parent 9e11ff0 commit a06f3fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
16 changes: 12 additions & 4 deletions RFS/src/test/java/com/rfs/tracing/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

import lombok.Getter;
import org.opensearch.migrations.tracing.BacktracingContextTracker;
import org.opensearch.migrations.tracing.CompositeContextTracker;
import org.opensearch.migrations.tracing.IContextTracker;
import org.opensearch.migrations.tracing.InMemoryInstrumentationBundle;
import org.opensearch.migrations.tracing.LoggingContextTracer;

public class TestContext extends RootRfsContext { @Getter
public class TestContext extends RootRfsContext {
@Getter
public InMemoryInstrumentationBundle instrumentationBundle;

public static TestContext withTracking(boolean tracing, boolean metrics) {
return new TestContext(new InMemoryInstrumentationBundle(tracing, metrics), new BacktracingContextTracker());
public static TestContext withTracking(boolean tracing, boolean metrics, boolean consoleLogging) {
IContextTracker tracker = new BacktracingContextTracker();
if (consoleLogging) {
tracker = new CompositeContextTracker(tracker, new LoggingContextTracer());
}

return new TestContext(new InMemoryInstrumentationBundle(tracing, metrics), tracker);
}

public static TestContext withAllTracking() {
return withTracking(true, true);
return withTracking(true, true, true);
}

public static TestContext noOtelTracking() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.opensearch.migrations.tracing;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LoggingContextTracer implements IContextTracker {

private static final String CREATED_MESSAGE = "<< Start: {}";
private static final String CLOSED_MESSAGE = ">> Close: {} {}";

@Override
public void onContextCreated(final IScopedInstrumentationAttributes context) {
log.atDebug()
.setMessage(CREATED_MESSAGE)
.addArgument(context.getActivityName())
.log();
}

@Override
public void onContextClosed(IScopedInstrumentationAttributes context) {
log.atDebug()
.setMessage(CLOSED_MESSAGE)
.addArgument(context.getActivityName())
.addArgument(context::getPopulatedSpanAttributes)
.log();
}
}

0 comments on commit a06f3fe

Please sign in to comment.