Skip to content

Commit

Permalink
ManagedScope -> ScopeState; delegateManagedScope -> newScopeState
Browse files Browse the repository at this point in the history
Signed-off-by: monosoul <[email protected]>
  • Loading branch information
monosoul committed Dec 9, 2022
1 parent d0cbeac commit 079ab2c
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CoroutineContextAdvice {
public static void enter(
@Advice.Argument(value = 1, readOnly = false) CoroutineContext coroutineContext) {
if (coroutineContext != null) {
coroutineContext = coroutineContext.plus(new ManagedScopeCoroutineContext());
coroutineContext = coroutineContext.plus(new ScopeStateCoroutineContext());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public KotlinCoroutinesInstrumentation() {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".ManagedScopeCoroutineContext",
packageName + ".ManagedScopeCoroutineContext$ContextElementKey",
packageName + ".ScopeStateCoroutineContext",
packageName + ".ScopeStateCoroutineContext$ContextElementKey",
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package datadog.trace.instrumentation.kotlin.coroutines;

import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.ManagedScope;
import datadog.trace.bootstrap.instrumentation.api.ScopeState;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.functions.Function2;
import kotlinx.coroutines.ThreadContextElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ManagedScopeCoroutineContext implements ThreadContextElement<ManagedScope> {
public class ScopeStateCoroutineContext implements ThreadContextElement<ScopeState> {

private static final Key<ManagedScopeCoroutineContext> KEY = new ContextElementKey();
private final ManagedScope managedScope = AgentTracer.get().delegateManagedScope();
private static final Key<ScopeStateCoroutineContext> KEY = new ContextElementKey();
private final ScopeState scopeState = AgentTracer.get().newScopeState();

@Override
public void restoreThreadContext(
@NotNull CoroutineContext coroutineContext, ManagedScope oldState) {
@NotNull CoroutineContext coroutineContext, ScopeState oldState) {
oldState.activate();
}

@Override
public ManagedScope updateThreadContext(@NotNull CoroutineContext coroutineContext) {
final ManagedScope oldManagedScope = AgentTracer.get().delegateManagedScope();
oldManagedScope.fetch();
public ScopeState updateThreadContext(@NotNull CoroutineContext coroutineContext) {
final ScopeState oldScopeState = AgentTracer.get().newScopeState();
oldScopeState.fetchFromActive();

managedScope.activate();
scopeState.activate();

return oldManagedScope;
return oldScopeState;
}

@Nullable
Expand Down Expand Up @@ -59,5 +59,5 @@ public Key<?> getKey() {
return KEY;
}

static class ContextElementKey implements Key<ManagedScopeCoroutineContext> {}
static class ContextElementKey implements Key<ScopeStateCoroutineContext> {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import datadog.trace.bootstrap.instrumentation.api.AgentScopeManager;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.ManagedScope;
import datadog.trace.bootstrap.instrumentation.api.PathwayContext;
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
import datadog.trace.bootstrap.instrumentation.api.ScopeSource;
import datadog.trace.bootstrap.instrumentation.api.ScopeState;
import datadog.trace.bootstrap.instrumentation.api.TagContext;
import datadog.trace.civisibility.CiVisibilityTraceInterceptor;
import datadog.trace.common.metrics.MetricsAggregator;
Expand Down Expand Up @@ -201,8 +201,8 @@ public void onRootSpanStarted(AgentSpan root) {
}

@Override
public ManagedScope delegateManagedScope() {
return scopeManager.delegateManagedScope();
public ScopeState newScopeState() {
return scopeManager.newScopeState();
}

public static class CoreTracerBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import datadog.trace.bootstrap.instrumentation.api.AgentTrace;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.AttachableWrapper;
import datadog.trace.bootstrap.instrumentation.api.ManagedScope;
import datadog.trace.bootstrap.instrumentation.api.ProfilingContextIntegration;
import datadog.trace.bootstrap.instrumentation.api.ScopeSource;
import datadog.trace.bootstrap.instrumentation.api.ScopeState;
import datadog.trace.util.AgentTaskScheduler;
import java.util.ArrayDeque;
import java.util.Iterator;
Expand Down Expand Up @@ -256,11 +256,11 @@ ScopeStack scopeStack() {
}

@Override
public ManagedScope delegateManagedScope() {
return new ContinuableManagedScope();
public ScopeState newScopeState() {
return new ContinuableScopeState();
}

private class ContinuableManagedScope implements ManagedScope {
private class ContinuableScopeState implements ScopeState {

private ScopeStack localScopeStack = tlsScopeStack.initialValue();
private AgentSpan span = activeSpan();
Expand All @@ -274,7 +274,7 @@ public void activate() {
}

@Override
public void fetch() {
public void fetchFromActive() {
localScopeStack = tlsScopeStack.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentScopeManager;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.ManagedScope;
import datadog.trace.bootstrap.instrumentation.api.ScopeSource;
import datadog.trace.bootstrap.instrumentation.api.ScopeState;
import datadog.trace.util.AgentTaskScheduler;
import io.opentracing.Scope;
import io.opentracing.ScopeManager;
Expand Down Expand Up @@ -149,11 +149,11 @@ public AgentScope activateNext(final AgentSpan agentSpan) {
}

@Override
public ManagedScope delegateManagedScope() {
return new CustomManagedScope();
public ScopeState newScopeState() {
return new CustomScopeState();
}

private class CustomManagedScope implements ManagedScope {
private class CustomScopeState implements ScopeState {

private AgentSpan span = activeSpan();

Expand All @@ -163,7 +163,7 @@ public void activate() {
}

@Override
public void fetch() {
public void fetchFromActive() {
span = activeSpan();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Allows custom scope managers. See OTScopeManager, CustomScopeManager, and ContextualScopeManager
*/
public interface AgentScopeManager extends ManagedScopeAware {
public interface AgentScopeManager extends ScopeStateAware {

AgentScope activate(AgentSpan span, ScopeSource source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface TracerAPI
InternalTracer,
AgentPropagation,
EndpointCheckpointer,
ManagedScopeAware {
ScopeStateAware {
AgentSpan startSpan(CharSequence spanName);

AgentSpan startSpan(CharSequence spanName, long startTimeMicros);
Expand Down Expand Up @@ -386,7 +386,7 @@ public AgentSpan.Context notifyExtensionStart(Object event) {
public void notifyExtensionEnd(AgentSpan span, Object result, boolean isError) {}

@Override
public ManagedScope delegateManagedScope() {
public ScopeState newScopeState() {
return null;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog.trace.bootstrap.instrumentation.api;

public interface ManagedScope {
public interface ScopeState {
void activate();

void fetch();
void fetchFromActive();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package datadog.trace.bootstrap.instrumentation.api;

public interface ScopeStateAware {
ScopeState newScopeState();
}

0 comments on commit 079ab2c

Please sign in to comment.