From ea4be26d56acce8f958f2a2a4026f25f97c73ce0 Mon Sep 17 00:00:00 2001 From: Robert Munteanu Date: Thu, 14 Sep 2023 16:57:10 +0200 Subject: [PATCH] sling: spotless fix-up --- .../sling/ServletResolverInstrumentation.java | 26 +++++++++++-------- .../sling/SlingInstrumentationModule.java | 8 +++++- ...lingSafeMethodsServletInstrumentation.java | 17 ++++++++---- .../sling/SlingSingletons.java | 11 +++++--- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/ServletResolverInstrumentation.java b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/ServletResolverInstrumentation.java index 03103bcbbcb0..14c784f2a939 100644 --- a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/ServletResolverInstrumentation.java +++ b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/ServletResolverInstrumentation.java @@ -1,24 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.sling; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; +import static io.opentelemetry.javaagent.instrumentation.sling.SlingSingletons.REQUEST_ATTR_RESOLVED_SERVLET_NAME; +import static net.bytebuddy.matcher.ElementMatchers.isMethod; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.servlet.Servlet; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.sling.api.SlingHttpServletRequest; -import javax.servlet.Servlet; - -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; -import static io.opentelemetry.javaagent.instrumentation.sling.SlingSingletons.REQUEST_ATTR_RESOLVED_SERVLET_NAME; -import static net.bytebuddy.matcher.ElementMatchers.isMethod; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; - -public class ServletResolverInstrumentation implements TypeInstrumentation { +public class ServletResolverInstrumentation implements TypeInstrumentation { @Override public ElementMatcher typeMatcher() { @@ -32,7 +36,7 @@ public void transform(TypeTransformer transformer) { .and(named("resolveServlet")) .and(takesArguments(1)) .and(takesArgument(0, named("org.apache.sling.api.SlingHttpServletRequest"))), - this.getClass().getName()+"$ResolveServletAdvice"); + this.getClass().getName() + "$ResolveServletAdvice"); } @SuppressWarnings("unused") diff --git a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingInstrumentationModule.java b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingInstrumentationModule.java index af3d02aedb9e..a282313fec38 100644 --- a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingInstrumentationModule.java +++ b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingInstrumentationModule.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.sling; import com.google.auto.service.AutoService; @@ -15,6 +20,7 @@ public SlingInstrumentationModule() { @Override public List typeInstrumentations() { - return Arrays.asList(new ServletResolverInstrumentation(), new SlingSafeMethodsServletInstrumentation()); + return Arrays.asList( + new ServletResolverInstrumentation(), new SlingSafeMethodsServletInstrumentation()); } } diff --git a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSafeMethodsServletInstrumentation.java b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSafeMethodsServletInstrumentation.java index c0b23283ad9a..598879c4deec 100644 --- a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSafeMethodsServletInstrumentation.java +++ b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSafeMethodsServletInstrumentation.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.sling; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; @@ -15,11 +20,11 @@ import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.servlet.ServletRequest; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; import org.apache.sling.api.SlingHttpServletRequest; -import javax.servlet.ServletRequest; public class SlingSafeMethodsServletInstrumentation implements TypeInstrumentation { @Override @@ -52,7 +57,7 @@ public static void onEnter( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { - if ( !(request instanceof SlingHttpServletRequest) ) { + if (!(request instanceof SlingHttpServletRequest)) { return; } @@ -66,18 +71,20 @@ public static void onEnter( // written by ServletResolverInstrumentation Object servletName = request.getAttribute(REQUEST_ATTR_RESOLVED_SERVLET_NAME); - if ( !(servletName instanceof String) ) { + if (!(servletName instanceof String)) { return; } - // TODO - figure out why don't we have matches for all requests and find a better way to filter + // TODO - figure out why don't we have matches for all requests and find a better way to + // filter context = helper().start(parentContext, slingRequest); scope = context.makeCurrent(); // ensure that the top-level route is Sling-specific HttpServerRoute.update(context, HttpServerRouteSource.CONTROLLER, (String) servletName); - // cleanup and ensure we don't have reuse the resolved Servlet name by accident for other requests + // cleanup and ensure we don't have reuse the resolved Servlet name by accident for other + // requests request.removeAttribute(REQUEST_ATTR_RESOLVED_SERVLET_NAME); } diff --git a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSingletons.java b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSingletons.java index 5b0775780617..659afd51858b 100644 --- a/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSingletons.java +++ b/instrumentation/sling/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/sling/SlingSingletons.java @@ -13,11 +13,14 @@ public final class SlingSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.sling-1.0"; - static final String REQUEST_ATTR_RESOLVED_SERVLET_NAME = INSTRUMENTATION_NAME + ".resolvedServletName"; + static final String REQUEST_ATTR_RESOLVED_SERVLET_NAME = + INSTRUMENTATION_NAME + ".resolvedServletName"; - private static final SpanNameExtractor SPAN_NAME_EXTRACTOR = s -> (String) s.getAttribute(REQUEST_ATTR_RESOLVED_SERVLET_NAME); - private static final Instrumenter - INSTRUMENTER = Instrumenter. builder(GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, SPAN_NAME_EXTRACTOR) + private static final SpanNameExtractor SPAN_NAME_EXTRACTOR = + s -> (String) s.getAttribute(REQUEST_ATTR_RESOLVED_SERVLET_NAME); + private static final Instrumenter INSTRUMENTER = + Instrumenter.builder( + GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, SPAN_NAME_EXTRACTOR) .buildInstrumenter(); public static Instrumenter helper() {