8000 Service naming: split by jee deployment by amarziali · Pull Request #8064 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content
8000

Service naming: split by jee deployment #8064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 12, 2024
Prev Previous commit
Next Next commit
collapse enter and local
  • Loading branch information
amarziali committed Dec 12, 2024
commit e9c2536f54e76bb916a7a5da114582e83166e778
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,35 @@ public void methodAdvice(MethodTransformer transformer) {

public static class ExtractPrincipalAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static boolean before(
@Advice.Argument(0) final ServletRequest request,
@Advice.Local("span") AgentSpan agentSpan) {
public static AgentSpan before(@Advice.Argument(0) final ServletRequest request) {
if (!(request instanceof HttpServletRequest)) {
return false;
return null;
}
Object span =
request.getAttribute(
"datadog.span"); // hardcode to avoid injecting HttpServiceDecorator just for this
if (span instanceof AgentSpan) {
agentSpan = (AgentSpan) span;
if (span instanceof AgentSpan
&& CallDepthThreadLocalMap.incrementCallDepth(HttpServletRequest.class) == 0) {
final AgentSpan agentSpan = (AgentSpan) span;
ClassloaderServiceNames.maybeSetToSpan(agentSpan, Thread.currentThread());
return agentSpan;
}
return CallDepthThreadLocalMap.incrementCallDepth(HttpServletRequest.class) == 0;
return null;
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void after(
@Advice.Enter boolean advice,
@Advice.Argument(0) final ServletRequest request,
@Advice.Local("span") AgentSpan span) {
if (advice) {
CallDepthThreadLocalMap.reset(HttpServletRequest.class);
final HttpServletRequest httpServletRequest =
(HttpServletRequest) request; // at this point the cast should be safe
if (span != null
&& Config.get().isServletPrincipalEnabled()
&& httpServletRequest.getUserPrincipal() != null) {
span.setTag(DDTags.USER_NAME, httpServletRequest.getUserPrincipal().getName());
}
@Advice.Enter final AgentSpan span, @Advice.Argument(0) final ServletRequest request) {
if (span == null) {
return;
}

CallDepthThreadLocalMap.reset(HttpServletRequest.class);
final HttpServletRequest httpServletRequest =
(HttpServletRequest) request; // at this point the cast should be safe
if (Config.get().isServletPrincipalEnabled()
&& httpServletRequest.getUserPrincipal() != null) {
span.setTag(DDTags.USER_NAME, httpServletRequest.getUserPrincipal().getName());
}
}
}
Expand Down
0