Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,37 @@ public class Java8BytecodeBridge {
/**
* @see Context#root()
*/
public static Context getRootContext() {
public static Context rootContext() {
return Context.root();
}

/**
* @see Context#current()
*/
public static Context getCurrentContext() {
public static Context currentContext() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update remaining RxJava3 bridge callers

This rename removes getCurrentContext()/getRootContext(), but a repo-wide search still finds the RxJava3 instrumentations calling Java8BytecodeBridge.getCurrentContext() and Java8BytecodeBridge.getRootContext() under dd-java-agent/instrumentation/rxjava/rxjava-3.0/src/main/java. Those main sources will no longer compile against this updated bridge, so either keep compatibility aliases or update the RxJava3 callers as well.

Useful? React with 👍 / 👎.

return Context.current();
}

/**
* @see Context#from(Object)
* @see AgentSpan#current()
*/
public static Context getContextFrom(Object carrier) {
return Context.from(carrier);
public static AgentSpan currentSpan() {
return AgentSpan.current();
}

/**
* @see Context#detachFrom(Object)
* @see AgentSpan#fromContext(Context)
*/
public static Context detachContextFrom(Object carrier) {
return Context.detachFrom(carrier);
public static AgentSpan spanFromContext(Context context) {
return AgentSpan.fromContext(context);
}

/**
* @see AgentSpan#fromContext(Context)
* @see Baggage#fromContext(Context)
*/
public static AgentSpan spanFromContext(Context context) {
return AgentSpan.fromContext(context);
public static Baggage baggageFromContext(Context context) {
return Baggage.fromContext(context);
}

private Java8BytecodeBridge() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.checkpointActiveForRollback;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.rollbackActiveToCheckpoint;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;

Expand Down Expand Up @@ -71,7 +71,7 @@ public static Context enter(
checkpointActiveForRollback();
return null;
} else {
return getCurrentContext().swap();
return currentContext().swap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.checkpointActiveForRollback;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.rollbackActiveToCheckpoint;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static java.util.Collections.singletonList;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;

Expand Down Expand Up @@ -68,7 +68,7 @@ public static Context enter() {
checkpointActiveForRollback();
return null;
} else {
return getCurrentContext().swap();
return currentContext().swap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.AKKA_CLIENT_REQUEST;
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.AKKA_HTTP_CLIENT;
import static datadog.trace.instrumentation.akkahttp.AkkaHttpClientDecorator.DECORATE;
Expand Down Expand Up @@ -116,7 +116,7 @@ public static void methodEnter(
return;
}
final AkkaHttpHeaders headers = new AkkaHttpHeaders(request);
DECORATE.injectContext(getCurrentContext(), request, headers);
DECORATE.injectContext(currentContext(), request, headers);
request = headers.getRequest();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog.trace.instrumentation.akkahttp106;

import static datadog.trace.agent.tooling.InstrumenterModule.TargetSystem.CONTEXT_TRACKING;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.akkahttp106.AkkaHttpClientDecorator.DECORATE;

import akka.http.scaladsl.model.HttpRequest;
Expand All @@ -19,7 +19,7 @@ public static void methodEnter(
final AkkaHttpClientHelpers.AkkaHttpHeaders headers =
new AkkaHttpClientHelpers.AkkaHttpHeaders(request);

DECORATE.injectContext(getCurrentContext(), request, headers);
DECORATE.injectContext(currentContext(), request, headers);
request = headers.getRequest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.armeria.grpc.client.GrpcClientDecorator.COMPONENT_NAME;
import static datadog.trace.instrumentation.armeria.grpc.client.GrpcClientDecorator.DECORATE;
import static datadog.trace.instrumentation.armeria.grpc.client.GrpcClientDecorator.GRPC_MESSAGE;
Expand All @@ -21,7 +22,6 @@
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge;
import io.grpc.ClientCall;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
Expand Down Expand Up @@ -138,7 +138,7 @@ public static void after(
public static final class StartContextPropagationAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void before(@Advice.Argument(1) Metadata headers) {
DECORATE.injectContext(Java8BytecodeBridge.getCurrentContext(), headers, SETTER);
DECORATE.injectContext(currentContext(), headers, SETTER);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateNext;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closePrevious;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.rootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.bootstrap.instrumentation.api.URIUtils.urlFileName;
import static datadog.trace.instrumentation.aws.v1.sqs.MessageExtractAdapter.GETTER;
Expand Down Expand Up @@ -50,7 +50,7 @@ public boolean hasNext() {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else {
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand All @@ -71,7 +71,7 @@ protected void startNewMessageSpan(Message message) {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else if (message == null) { // previous message span was the last
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog.trace.instrumentation.aws.v1.sqs;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closePrevious;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.rootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;

import com.amazonaws.services.sqs.model.Message;
Expand All @@ -24,7 +24,7 @@ public boolean hasPrevious() {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else {
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateNext;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closePrevious;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.rootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.bootstrap.instrumentation.api.URIUtils.urlFileName;
import static datadog.trace.instrumentation.aws.v2.sqs.MessageExtractAdapter.GETTER;
Expand Down Expand Up @@ -52,7 +52,7 @@ public boolean hasNext() {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else {
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand All @@ -73,7 +73,7 @@ protected void startNewMessageSpan(Message message) {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else if (message == null) { // previous message span was the last
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datadog.trace.instrumentation.aws.v2.sqs;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.closePrevious;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.rootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;

import datadog.trace.api.InstrumenterConfig;
Expand All @@ -24,7 +24,7 @@ public boolean hasPrevious() {
if (InstrumenterConfig.get().isLegacyContextManagerEnabled()) {
closePrevious(true);
} else {
final AgentSpan previousSpan = spanFromContext(getRootContext().swap());
final AgentSpan previousSpan = spanFromContext(rootContext().swap());
if (previousSpan != null) {
previousSpan.finishWithEndToEnd();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.fromContext;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getRootContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.rootContext;
import static datadog.trace.instrumentation.axway.AxwayHTTPPluginDecorator.DECORATE;
import static datadog.trace.instrumentation.axway.AxwayHTTPPluginDecorator.SERVER_TRANSACTION_CLASS;

Expand All @@ -20,8 +20,8 @@ public static ContextScope onEnter(@Advice.Argument(value = 2) final Object serv
final AgentSpan span = startSpan("axway-http", DECORATE.spanName()).setMeasured(true);
DECORATE.afterStart(span);
// serverTransaction is like request + connection in one object:
DECORATE.onRequest(span, serverTransaction, serverTransaction, getRootContext());
return getCurrentContext().with(span).attach();
DECORATE.onRequest(span, serverTransaction, serverTransaction, rootContext());
return currentContext().with(span).attach();
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.HierarchyMatchers.isAnnotatedWith;
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentSpan.fromContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
import static datadog.trace.instrumentation.azure.functions.AzureFunctionsDecorator.DECORATE;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
Expand Down Expand Up @@ -86,7 +86,7 @@ public static ContextScope methodEnter(
@Advice.Argument(0) final HttpRequestMessage<?> request,
@Advice.Argument(1) final ExecutionContext executionContext) {
final Context parentContext =
getCurrentContext(); // parent context attached by ContextTrackingAdvice
currentContext(); // parent context attached by ContextTrackingAdvice
final Context context = DECORATE.startSpan(request, parentContext);
final AgentSpan span = fromContext(context);
DECORATE.afterStart(span, executionContext.getFunctionName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.DECORATE;
import static datadog.trace.instrumentation.commonshttpclient.CommonsHttpClientDecorator.HTTP_REQUEST;
import static datadog.trace.instrumentation.commonshttpclient.HttpHeadersInjectAdapter.SETTER;
Expand Down Expand Up @@ -105,7 +105,7 @@ public static void methodExit(
public static class ContextPropagationAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(@Advice.Argument(1) final HttpMethod httpMethod) {
DECORATE.injectContext(getCurrentContext(), httpMethod, SETTER);
DECORATE.injectContext(currentContext(), httpMethod, SETTER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.bootstrap.instrumentation.decorator.http.HttpResourceDecorator.HTTP_RESOURCE_DECORATOR;
import static datadog.trace.instrumentation.finatra.FinatraDecorator.DECORATE;
Expand Down Expand Up @@ -79,7 +79,7 @@ public static ContextScope nameSpan(
DECORATE.afterStart(span);
span.setResourceName(DECORATE.className(clazz));

return getCurrentContext().with(span).attach();
return currentContext().with(span).attach();
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.googlehttpclient.GoogleHttpClientDecorator.DECORATE;
import static datadog.trace.instrumentation.googlehttpclient.GoogleHttpClientDecorator.HTTP_REQUEST;
import static datadog.trace.instrumentation.googlehttpclient.HeadersInjectAdapter.SETTER;
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void methodExit(
public static class GoogleHttpClientContextPropagationAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(@Advice.This HttpRequest request) {
DECORATE.injectContext(getCurrentContext(), request, SETTER);
DECORATE.injectContext(currentContext(), request, SETTER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static datadog.trace.agent.tooling.InstrumenterModule.TargetSystem.CONTEXT_TRACKING;
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.spanFromContext;
import static datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator.DD_CONTEXT_ATTRIBUTE;
import static datadog.trace.instrumentation.grizzly.GrizzlyDecorator.DECORATE;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static class HandleAdvice {
}

final Context parentContext =
getCurrentContext(); // parent context attached by ContextTrackingAdvice
currentContext(); // parent context attached by ContextTrackingAdvice
final Context context = DECORATE.startSpan(request, parentContext);
final AgentSpan span = spanFromContext(context);
DECORATE.afterStart(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.getCurrentContext;
import static datadog.trace.bootstrap.instrumentation.api.Java8BytecodeBridge.currentContext;
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.DECORATE;
import static datadog.trace.instrumentation.grizzly.client.ClientDecorator.HTTP_REQUEST;
import static datadog.trace.instrumentation.grizzly.client.InjectAdapter.SETTER;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void onExit(
public static class ExecuteContextPropagationAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(@Advice.Argument(0) final Request request) {
DECORATE.injectContext(getCurrentContext(), request, SETTER);
DECORATE.injectContext(currentContext(), request, SETTER);
}
}
}
Loading