From 3ba28dc6174e14a59c9e930d157b89c8deca22f2 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 25 Nov 2022 18:02:30 +0100 Subject: [PATCH 01/18] WIP --- .../apm-toolkit-micrometer-registry/pom.xml | 13 +- .../SkywalkingDefaultTracingHandler.java | 59 ++++++++ .../observation/SkywalkingMeterHandler.java | 29 ++++ .../SkywalkingReceiverTracingHandler.java | 60 ++++++++ .../SkywalkingSenderTracingHandler.java | 60 ++++++++ .../SkywalkingMeterHandlerTests.java | 47 ++++++ .../trace/component/ComponentsDefine.java | 2 + .../micrometer-1.10.x-plugin/pom.xml | 51 +++++++ ...rDefaultTracingHandlerInstrumentation.java | 90 ++++++++++++ ...meterDefaultTracingHandlerInterceptor.java | 71 +++++++++ ...ReceiverTracingHandlerInstrumentation.java | 90 ++++++++++++ ...eterReceiverTracingHandlerInterceptor.java | 80 ++++++++++ ...erSenderTracingHandlerInstrumentation.java | 90 ++++++++++++ ...ometerSenderTracingHandlerInterceptor.java | 80 ++++++++++ .../src/main/resources/skywalking-plugin.def | 19 +++ .../ContextManagerExtendOverrideService.java | 26 ++++ ...rDefaultTracingHandlerInterceptorTest.java | 130 +++++++++++++++++ .../plugin/micrometer/PluginBootService.java | 43 ++++++ ...skywalking.apm.agent.core.boot.BootService | 20 +++ apm-sniffer/apm-sdk-plugin/pom.xml | 1 + .../pom.xml | 38 +++++ pom.xml | 1 + .../config/expectedData.yaml | 137 ++++++++++++++++++ .../configuration.yml | 17 +++ .../resttemplate-6.x-scenario/pom.xml | 103 +++++++++++++ .../testcase/resttemplate/BackController.java | 34 +++++ .../resttemplate/FrontController.java | 55 +++++++ .../ResttemplateConfiguration.java | 83 +++++++++++ .../src/main/resource/log4j2.xml | 31 ++++ .../webapp/WEB-INF/spring-mvc-servlet.xml | 30 ++++ .../src/main/webapp/WEB-INF/web.xml | 35 +++++ .../support-version.list | 17 +++ 32 files changed, 1641 insertions(+), 1 deletion(-) create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService create mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/web.xml create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/support-version.list diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml index 29d8220a38..a86e2b67a5 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml @@ -30,7 +30,7 @@ http://maven.apache.org - 1.5.0 + 1.10.2 @@ -39,10 +39,21 @@ apm-toolkit-meter ${project.version} + + io.micrometer + micrometer-observation + ${micrometer-core.version} + io.micrometer micrometer-core ${micrometer-core.version} + + io.micrometer + micrometer-test + ${micrometer-core.version} + test + diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java new file mode 100644 index 0000000000..4ef1e77cf8 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; + +public class SkywalkingDefaultTracingHandler implements ObservationHandler { + @Override + public boolean supportsContext(final Observation.Context context) { + return true; + } + + @Override + public void onStart(final Observation.Context context) { + + } + + @Override + public void onError(final Observation.Context context) { + + } + + @Override + public void onEvent(final Observation.Event event, final Observation.Context context) { + + } + + @Override + public void onScopeOpened(final Observation.Context context) { + + } + + @Override + public void onScopeClosed(final Observation.Context context) { + + } + + @Override + public void onStop(final Observation.Context context) { + + } +} diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java new file mode 100644 index 0000000000..493c5093b6 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler; +import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; + +public class SkywalkingMeterHandler extends DefaultMeterObservationHandler { + + public SkywalkingMeterHandler(SkywalkingMeterRegistry meterRegistry) { + super(meterRegistry); + } +} diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java new file mode 100644 index 0000000000..c63adeed13 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.transport.SenderContext; + +public class SkywalkingReceiverTracingHandler implements ObservationHandler> { + @Override + public boolean supportsContext(final Observation.Context context) { + return context instanceof SenderContext; + } + + @Override + public void onStart(final SenderContext context) { + + } + + @Override + public void onError(final SenderContext context) { + + } + + @Override + public void onEvent(final Observation.Event event, final SenderContext context) { + + } + + @Override + public void onScopeOpened(final SenderContext context) { + + } + + @Override + public void onScopeClosed(final SenderContext context) { + + } + + @Override + public void onStop(final SenderContext context) { + + } +} diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java new file mode 100644 index 0000000000..59bc3b1822 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.transport.SenderContext; + +public class SkywalkingSenderTracingHandler implements ObservationHandler> { + @Override + public boolean supportsContext(final Observation.Context context) { + return context instanceof SenderContext; + } + + @Override + public void onStart(final SenderContext context) { + + } + + @Override + public void onError(final SenderContext context) { + + } + + @Override + public void onEvent(final Observation.Event event, final SenderContext context) { + + } + + @Override + public void onScopeOpened(final SenderContext context) { + + } + + @Override + public void onScopeClosed(final SenderContext context) { + + } + + @Override + public void onStop(final SenderContext context) { + + } +} diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java new file mode 100644 index 0000000000..08fa72b0fa --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.observation.Observation; +import io.micrometer.observation.tck.TestObservationRegistry; +import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; +import org.junit.Test; + +public class SkywalkingMeterHandlerTests { + SkywalkingMeterRegistry meterRegistry = new SkywalkingMeterRegistry(); + + SkywalkingMeterHandler handler = new SkywalkingMeterHandler(meterRegistry); + + TestObservationRegistry observationRegistry = TestObservationRegistry.create(); + + @Test + public void testCreateTimer() { + observationRegistry.observationConfig().observationHandler(handler); + + Observation.createNotStarted("foo", observationRegistry) + .observe(() -> { + + }); + + MeterRegistryAssert.assertThat(meterRegistry) + .hasMeterWithName("foo") + .hasMeterWithName("foo.active"); + } +} diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index f8a578466f..614071799d 100755 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -231,4 +231,6 @@ public class ComponentsDefine { public static final OfficialComponent IMPALA_JDBC_DRIVER = new OfficialComponent(133, "Impala-jdbc-driver"); + public static final OfficialComponent MICROMETER = new OfficialComponent(134, "Micronaut"); + } diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml new file mode 100644 index 0000000000..7666431b9a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml @@ -0,0 +1,51 @@ + + + + + apm-sdk-plugin + org.apache.skywalking + 8.14.0-SNAPSHOT + + 4.0.0 + + apm-micrometer-1.10.x-plugin + jar + + apm-micrometer-1.10.x-plugin + http://maven.apache.org + + + UTF-8 + 1.10.2 + + + + + org.apache.skywalking + apm-toolkit-micrometer-registry + ${project.version} + + + io.micrometer + micrometer-core + ${micrometer.version} + provided + + + diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java new file mode 100644 index 0000000000..9e99d4595d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class MicrometerDefaultTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler"; + + public static final String INTERCEPT_START_POINT_METHOD = "onStart"; + + public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_START_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_STOP_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java new file mode 100644 index 0000000000..7caf3aa417 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.util.StringUtil; + +/** + * {@link MicrometerDefaultTracingHandlerInterceptor} define how to enhance classes + * {@link SkywalkingDefaultTracingHandler}. + */ +public class MicrometerDefaultTracingHandlerInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + String methodName = method.getName(); + if ("onStart".equals(methodName)) { + Observation.Context context = (Observation.Context) allArguments[0]; + AbstractSpan span = ContextManager.createLocalSpan(context.getName()); + span.setComponent(ComponentsDefine.MICROMETER); + // tags + } else if ("onStop".equals(methodName)) { + Observation.Context context = (Observation.Context) allArguments[0]; + ContextManager.activeSpan() + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + ContextManager.stopSpan(); + } else if ("onError".equals(methodName)) { + Observation.Context context = (Observation.Context) allArguments[0]; + ContextManager.activeSpan().log(context.getError()); + } + // TODO: Micrometer Context-Propagation with ThreadLocalAccessor for ContextManager ??? + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java new file mode 100644 index 0000000000..127be49e9d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class MicrometerReceiverTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler"; + + public static final String INTERCEPT_START_POINT_METHOD = "onStart"; + + public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_START_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_STOP_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java new file mode 100644 index 0000000000..d1138f40b4 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.transport.ReceiverContext; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.util.StringUtil; + +/** + * {@link MicrometerReceiverTracingHandlerInterceptor} define how to enhance classes + * {@link SkywalkingReceiverTracingHandler}. + */ +public class MicrometerReceiverTracingHandlerInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + String methodName = method.getName(); + if ("onStart".equals(methodName)) { + ReceiverContext context = (ReceiverContext) allArguments[0]; + final ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + next.setHeadValue(context.getGetter().get(context.getCarrier(), next.getHeadKey())); + } + AbstractSpan span = ContextManager.createEntrySpan(context.getName(), contextCarrier); + span.setPeer(context.getRemoteServiceAddress()); + span.setComponent(ComponentsDefine.MICROMETER); + // tags + } else if ("onStop".equals(methodName)) { + ReceiverContext context = (ReceiverContext) allArguments[0]; + ContextManager.activeSpan() + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + ContextManager.stopSpan(); + } else if ("onError".equals(methodName)) { + Observation.Context context = (Observation.Context) allArguments[0]; + ContextManager.activeSpan().log(context.getError()); + } + // TODO: Micrometer Context-Propagation with ThreadLocalAccessor for ContextManager ??? + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java new file mode 100644 index 0000000000..a4dba0b00c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class MicrometerSenderTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler"; + + public static final String INTERCEPT_START_POINT_METHOD = "onStart"; + + public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; + + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_START_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_STOP_POINT_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java new file mode 100644 index 0000000000..0582d612bb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.transport.SenderContext; +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.util.StringUtil; + +/** + * {@link MicrometerSenderTracingHandlerInterceptor} define how to enhance classes + * {@link SkywalkingSenderTracingHandler}. + */ +public class MicrometerSenderTracingHandlerInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + String methodName = method.getName(); + if ("onStart".equals(methodName)) { + SenderContext context = (SenderContext) allArguments[0]; + final ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan span = ContextManager.createExitSpan( + context.getContextualName(), contextCarrier, context.getRemoteServiceAddress()); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + context.getSetter().set(context.getCarrier(), next.getHeadKey(), next.getHeadValue()); + } + span.setComponent(ComponentsDefine.MICROMETER); + // tags + } else if ("onStop".equals(methodName)) { + SenderContext context = (SenderContext) allArguments[0]; + ContextManager.activeSpan() + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + ContextManager.stopSpan(); + } else if ("onError".equals(methodName)) { + Observation.Context context = (Observation.Context) allArguments[0]; + ContextManager.activeSpan().log(context.getError()); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 0000000000..079da236a3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +micrometerdefaulttracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInstrumentation +micrometersendertracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInstrumentation +micrometerreceivertracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java new file mode 100644 index 0000000000..9b462b361b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import org.apache.skywalking.apm.agent.core.boot.OverrideImplementor; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; + +@OverrideImplementor(ContextManagerExtendService.class) +public class ContextManagerExtendOverrideService extends ContextManagerExtendService { +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java new file mode 100644 index 0000000000..5873eefb6f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class MicrometerDefaultTracingHandlerInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + + @Mock + private EnhancedInstance enhancedInstance; + + @Mock + private MethodInterceptResult result; + + private MicrometerDefaultTracingHandlerInterceptor micrometerDefaultTracingHandlerInterceptor; + + private final Observation.Context context = new Observation.Context(); + + private final Object[] consumerArguments = new Object[] {context}; + + private final Class[] argumentTypes = new Class[] {Observation.Context.class}; + + private final Method onStart = ObservationHandler.class.getMethod("onStart", Observation.Context.class); + + private final Method onStop = ObservationHandler.class.getMethod("onStop", Observation.Context.class); + + private final Method onError = ObservationHandler.class.getMethod("onError", Observation.Context.class); + + public MicrometerDefaultTracingHandlerInterceptorTest() throws NoSuchMethodException { + } + + @Before + public void setUp() throws Exception { + micrometerDefaultTracingHandlerInterceptor = new MicrometerDefaultTracingHandlerInterceptor(); + + Config.Agent.SERVICE_NAME = "MicrometerTestCases-APP"; + } + + @Test + public void testServiceFromPlugin() { + PluginBootService service = ServiceManager.INSTANCE.findService( + PluginBootService.class); + + Assert.assertNotNull(service); + } + + @Test + public void testServiceOverrideFromPlugin() { + ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class); + + Assert.assertTrue(service instanceof ContextManagerExtendOverrideService); + } + + @Test + public void testDefaultStartStop() throws Throwable { + micrometerDefaultTracingHandlerInterceptor.beforeMethod( + enhancedInstance, onStart, consumerArguments, argumentTypes, result); + micrometerDefaultTracingHandlerInterceptor.beforeMethod( + enhancedInstance, onStop, consumerArguments, argumentTypes, result); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + } + + @Test + public void testDefailtStartExceptionStop() throws Throwable { + micrometerDefaultTracingHandlerInterceptor.beforeMethod( + enhancedInstance, onStart, consumerArguments, argumentTypes, result); + context.setError(new RuntimeException("BOOM")); + micrometerDefaultTracingHandlerInterceptor.beforeMethod( + enhancedInstance, onError, consumerArguments, argumentTypes, result); + micrometerDefaultTracingHandlerInterceptor.beforeMethod( + enhancedInstance, onStop, consumerArguments, argumentTypes, result); + + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java new file mode 100644 index 0000000000..47cb9824ce --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import org.apache.skywalking.apm.agent.core.boot.BootService; + +public class PluginBootService implements BootService { + @Override + public void prepare() throws Throwable { + + } + + @Override + public void boot() throws Throwable { + + } + + @Override + public void onComplete() throws Throwable { + + } + + @Override + public void shutdown() throws Throwable { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService new file mode 100644 index 0000000000..1c26780b61 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +org.apache.skywalking.apm.plugin.micrometer.PluginBootService +org.apache.skywalking.apm.plugin.micrometer.ContextManagerExtendOverrideService diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 9105865094..e9380a3a88 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -126,6 +126,7 @@ nats-2.14.x-2.15.x-plugin jedis-plugins impala-jdbc-2.6.x-plugin + micrometer-1.10.x-plugin pom diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml new file mode 100644 index 0000000000..7bb9d881ef --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml @@ -0,0 +1,38 @@ + + + + + + apm-toolkit-activation + org.apache.skywalking + 8.14.0-SNAPSHOT + + 4.0.0 + + apm-toolkit-micrometer-observation-activation + + + + org.apache.skywalking + apm-toolkit-micrometer-registry + ${project.version} + provided + + + diff --git a/pom.xml b/pom.xml index c58790f429..29f666894d 100755 --- a/pom.xml +++ b/pom.xml @@ -391,6 +391,7 @@ ${project.build.sourceDirectory} ${project.build.testSourceDirectory} +scenarios/resttemplate-6.x.0-scenario **/*.properties, diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..e969ceca38 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml @@ -0,0 +1,137 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +segmentItems: +- serviceName: resttemplate-6.x-observation-scenario + segmentSize: ge 4 + segments: + - segmentId: not null + spans: + - operationName: HEAD:/resttemplate-6.x-observation-scenario/resttemplate/case/healthcheck + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation0scenario/resttemplate/case/healthcheck'} + - {key: http.method, value: HEAD} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/asyncback + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/asyncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + refs: + - {parentEndpoint: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate, + networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, + parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-observation-scenario, + traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/syncback + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + refs: + - {parentEndpoint: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate, + networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 3, + parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-observation-scenario, + traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: /resttemplate-6.x-observation-scenario/resttemplate/asyncback + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:8080 + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/asyncback'} + - {key: http.method, value: GET} + skipAnalysis: 'false' + - operationName: 'future/get:/resttemplate-6.x-observation-scenario/resttemplate/asyncback' + parentSpanId: 0 + spanId: 2 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + isError: false + spanType: Local + peer: '' + skipAnalysis: 'false' + - operationName: /resttemplate-6.x-observation-scenario/resttemplate/syncback + parentSpanId: 0 + spanId: 3 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:8080 + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' + - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: not null + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml b/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml new file mode 100644 index 0000000000..13c6c03caa --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +type: tomcat +entryService: http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate +healthCheck: http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/healthcheck diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml new file mode 100644 index 0000000000..0a4f443244 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -0,0 +1,103 @@ + + + + 4.0.0 + + org.apache.skywalking + resttemplate-6.x-observation-scenario + 6.5.0 + war + + + UTF-8 + UTF-8 + 17 + 6.0.2 + ${test.framework.version} + 2.8.1 + + + + + + + skywalking-resttemplate-6.x-observation-scenario + + + + org.apache.skywalking + apm-toolkit-micrometer-registry + ${sw.version} + + + org.springframework + spring-webmvc + ${test.framework.version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + provided + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + provided + + + + + resttemplate-6.x-observation-scenario + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java new file mode 100644 index 0000000000..c86705b56a --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/resttemplate") +public class BackController { + @GetMapping("/syncback") + public String syncBack() { + return "Hello back"; + } + +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java new file mode 100644 index 0000000000..aff7d7fae9 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +@RequestMapping("/resttemplate/case") +public class FrontController { + + private static final Logger LOGGER = LogManager.getLogger(FrontController.class); + + @Autowired + private RestTemplate restTemplate; + + @GetMapping(value = "/healthcheck") + public String healthcheck() { + return "Success"; + } + + @GetMapping( "/resttemplate") + public String front() { + syncRequest("http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback"); + return "Success"; + } + + private String syncRequest(String url) { + restTemplate.getForObject(url, String.class); + + return "Success"; + } +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java new file mode 100644 index 0000000000..1ab0ef3cca --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.observation.MeterObservationHandler; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.ObservationRegistry; +import jakarta.annotation.PreDestroy; +import java.util.List; +import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingMeterHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class ResttemplateConfiguration { + + @Bean + public RestTemplate restTemplate(ObservationRegistry observationRegistry) { + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setObservationRegistry(observationRegistry); + return restTemplate; + } + + @Configuration(proxyBeanMethods = false) + static class ObservationConfiguration { + + @Bean + ObservationRegistry observationRegistry(List> handlers) { + ObservationRegistry registry = ObservationRegistry.create(); + registry.observationConfig().observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers)); + return registry; + } + + @Bean + SkywalkingMeterRegistry meterRegistry() { + return new SkywalkingMeterRegistry(); + } + + @Bean + MeterObservationHandler meterObservationHandler(SkywalkingMeterRegistry skywalkingMeterRegistry) { + return new SkywalkingMeterHandler(skywalkingMeterRegistry); + } + + @Bean + MetricsDumper metricsDumper(MeterRegistry meterRegistry) { + return new MetricsDumper(meterRegistry); + } + + static class MetricsDumper { + private final MeterRegistry meterRegistry; + + MetricsDumper(MeterRegistry meterRegistry) { + this.meterRegistry = meterRegistry; + } + + @PreDestroy + void dumpMetrics() { + System.out.println("==== METRICS ===="); + this.meterRegistry.getMeters().forEach(meter -> System.out.println(" - Metric type \t[" + meter.getId().getType() + "],\tname [" + meter.getId().getName() + "],\ttags " + meter.getId().getTags() + ",\tmeasurements " + meter.measure())); + System.out.println("================="); + } + } + } +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml new file mode 100644 index 0000000000..985bd03bf3 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml new file mode 100644 index 0000000000..1ede76abd1 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/web.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..e01cd01791 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + skywalking-resttemplate-6.x-observation-scenario + + + spring-mvc + org.springframework.web.servlet.DispatcherServlet + 1 + + + spring-mvc + / + + diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/support-version.list b/test/plugin/scenarios/resttemplate-6.x-scenario/support-version.list new file mode 100644 index 0000000000..ed0abbe6d7 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/support-version.list @@ -0,0 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +6.0.2 From a2b0151a0f0cc86a251594c8fe60ec7c17bec64c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 28 Nov 2022 18:43:20 +0100 Subject: [PATCH 02/18] Polish --- .../apm-toolkit-micrometer-registry/pom.xml | 6 + ...ingContextSnapshotThreadLocalAccessor.java | 55 +++++++ .../SkywalkingReceiverTracingHandler.java | 18 +-- .../io.micrometer.context.ThreadLocalAccessor | 1 + ...gerThreadLocalAccessorInstrumentation.java | 76 +++++++++ ...napshotThreadLocalAccessorInterceptor.java | 66 ++++++++ ...rDefaultTracingHandlerInstrumentation.java | 28 ++-- ...meterDefaultTracingHandlerInterceptor.java | 18 ++- ...ReceiverTracingHandlerInstrumentation.java | 25 +-- ...eterReceiverTracingHandlerInterceptor.java | 37 ++++- ...erSenderTracingHandlerInstrumentation.java | 25 +-- ...ometerSenderTracingHandlerInterceptor.java | 30 +++- .../src/main/resources/skywalking-plugin.def | 7 +- .../micrometer/AbstractTracingSpanHelper.java | 47 ++++++ ...hotThreadLocalAccessorInterceptorTest.java | 147 ++++++++++++++++++ ...rDefaultTracingHandlerInterceptorTest.java | 106 ++++++++----- ...ReceiverTracingHandlerInterceptorTest.java | 138 ++++++++++++++++ ...erSenderTracingHandlerInterceptorTest.java | 137 ++++++++++++++++ .../service-agent/java-agent/Plugin-list.md | 1 + .../resttemplate-6.x-scenario/pom.xml | 2 +- .../testcase/resttemplate/BackController.java | 10 +- .../ResttemplateConfiguration.java | 4 + 22 files changed, 863 insertions(+), 121 deletions(-) create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml index a86e2b67a5..9c6f40129f 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml @@ -31,6 +31,7 @@ 1.10.2 + 1.0.0 @@ -49,6 +50,11 @@ micrometer-core ${micrometer-core.version} + + io.micrometer + context-propagation + ${context-propagation.version} + io.micrometer micrometer-test diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java new file mode 100644 index 0000000000..be31cc02d2 --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.meter.micrometer.observation; + +import io.micrometer.context.ThreadLocalAccessor; + +/** + * A {@link ThreadLocalAccessor} to put and restore current {@code ContextSnapshot} from APM agent. + */ +public class SkywalkingContextSnapshotThreadLocalAccessor implements ThreadLocalAccessor { + + /** + * Key under which ContextSnapshot is being registered. + */ + public static final String KEY = "skywalking.contextsnapshot"; + + @Override + public Object key() { + return KEY; + } + + // Type will be ContextSnapshot + @Override + public Object getValue() { + return null; + } + + // Object to set will be ContextSnapshot + @Override + public void setValue(Object value) { + + } + + @Override + public void reset() { + + } + +} diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java index c63adeed13..29f686a2f5 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java @@ -20,41 +20,41 @@ import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; -import io.micrometer.observation.transport.SenderContext; +import io.micrometer.observation.transport.ReceiverContext; -public class SkywalkingReceiverTracingHandler implements ObservationHandler> { +public class SkywalkingReceiverTracingHandler implements ObservationHandler> { @Override public boolean supportsContext(final Observation.Context context) { - return context instanceof SenderContext; + return context instanceof ReceiverContext; } @Override - public void onStart(final SenderContext context) { + public void onStart(final ReceiverContext context) { } @Override - public void onError(final SenderContext context) { + public void onError(final ReceiverContext context) { } @Override - public void onEvent(final Observation.Event event, final SenderContext context) { + public void onEvent(final Observation.Event event, final ReceiverContext context) { } @Override - public void onScopeOpened(final SenderContext context) { + public void onScopeOpened(final ReceiverContext context) { } @Override - public void onScopeClosed(final SenderContext context) { + public void onScopeClosed(final ReceiverContext context) { } @Override - public void onStop(final SenderContext context) { + public void onStop(final ReceiverContext context) { } } diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor new file mode 100644 index 0000000000..9a467be5ea --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor @@ -0,0 +1 @@ +org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java new file mode 100644 index 0000000000..c8e9bced5f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +public class MicrometerContextManagerThreadLocalAccessorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor"; + + public static final String INTERCEPT_GET_VALUE_POINT_METHOD = "getValue"; + + public static final String INTERCEPT_SET_VALUE_POINT_METHOD = "setValue"; + + public static final String INTERCEPT_RESET_POINT_METHOD = "reset"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerContextSnapshotThreadLocalAccessorInterceptor"; + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(INTERCEPT_GET_VALUE_POINT_METHOD) + .or(named(INTERCEPT_SET_VALUE_POINT_METHOD)) + .or(named(INTERCEPT_RESET_POINT_METHOD)); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java new file mode 100644 index 0000000000..72c695eba1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * {@link MicrometerContextSnapshotThreadLocalAccessorInterceptor} define how to enhance classes + * {@link SkywalkingContextSnapshotThreadLocalAccessor}. + */ +public class MicrometerContextSnapshotThreadLocalAccessorInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + String methodName = method.getName(); + if ("getValue".equals(methodName)) { + return ContextManager.capture(); + } else if ("setValue".equals(methodName)) { + ContextSnapshot context = (ContextSnapshot) allArguments[0]; + // TODO: I want to continue an existing span, what should be the name? + AbstractSpan span = ContextManager.createLocalSpan("continued"); + span.setComponent(ComponentsDefine.MICROMETER); + ContextManager.continued(context); + } else if ("reset".equals(methodName)) { + // TODO: Can't do much about resetting + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java index 9e99d4595d..bbb2e05f53 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java @@ -36,6 +36,10 @@ public class MicrometerDefaultTracingHandlerInstrumentation extends ClassInstanc public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; + public static final String INTERCEPT_ERROR_POINT_METHOD = "onError"; + + public static final String INTERCEPT_EVENT_POINT_METHOD = "onEvent"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInterceptor"; @Override @@ -45,7 +49,7 @@ protected ClassMatch enhanceClass() { @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; + return new ConstructorInterceptPoint[0]; } @Override @@ -54,24 +58,10 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_START_POINT_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_STOP_POINT_METHOD); + return named(INTERCEPT_START_POINT_METHOD) + .or(named(INTERCEPT_STOP_POINT_METHOD)) + .or(named(INTERCEPT_ERROR_POINT_METHOD)) + .or(named(INTERCEPT_EVENT_POINT_METHOD)); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java index 7caf3aa417..c0e0121d66 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java @@ -20,7 +20,10 @@ import io.micrometer.observation.Observation; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; @@ -46,15 +49,22 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr // tags } else if ("onStop".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; - ContextManager.activeSpan() - .setOperationName(StringUtil.isBlank( - context.getContextualName()) ? context.getName() : context.getContextualName()); + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + context.getAllKeyValues() + .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; ContextManager.activeSpan().log(context.getError()); + } else if ("onEvent".equals(methodName)) { + Observation.Event event = (Observation.Event) allArguments[0]; + Map map = new HashMap<>(); + map.put("event", event.getContextualName() != null ? event.getContextualName() : event.getName()); + ContextManager.activeSpan().log(System.currentTimeMillis(), map); } - // TODO: Micrometer Context-Propagation with ThreadLocalAccessor for ContextManager ??? } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java index 127be49e9d..98d8f36f55 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java @@ -34,6 +34,8 @@ public class MicrometerReceiverTracingHandlerInstrumentation extends ClassInstan public static final String INTERCEPT_START_POINT_METHOD = "onStart"; + public static final String INTERCEPT_ERROR_POINT_METHOD = "onError"; + public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInterceptor"; @@ -45,7 +47,7 @@ protected ClassMatch enhanceClass() { @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; + return new ConstructorInterceptPoint[0]; } @Override @@ -54,24 +56,9 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_START_POINT_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_STOP_POINT_METHOD); + return named(INTERCEPT_START_POINT_METHOD) + .or(named(INTERCEPT_STOP_POINT_METHOD)) + .or(named(INTERCEPT_ERROR_POINT_METHOD)); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index d1138f40b4..ed96b225f2 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -18,12 +18,14 @@ package org.apache.skywalking.apm.plugin.micrometer; +import io.micrometer.common.KeyValue; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.ReceiverContext; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; @@ -51,20 +53,43 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr next.setHeadValue(context.getGetter().get(context.getCarrier(), next.getHeadKey())); } AbstractSpan span = ContextManager.createEntrySpan(context.getName(), contextCarrier); - span.setPeer(context.getRemoteServiceAddress()); span.setComponent(ComponentsDefine.MICROMETER); - // tags + // TODO: We can't really set these because ReceiverContext is super generic. We don't know what the protocol will be. We can guess it from the tags maybe? But there's no certainty that same tags will be used everywhere. OTOH + // entrySpan.setLayer(SpanLayer.HTTP); + // Tags.URL.set(entrySpan, httpRequest.path()); + // Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); + } else if ("onStop".equals(methodName)) { ReceiverContext context = (ReceiverContext) allArguments[0]; - ContextManager.activeSpan() - .setOperationName(StringUtil.isBlank( - context.getContextualName()) ? context.getName() : context.getContextualName()); + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan + .setPeer(tryToGetPeer(context)) + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + context.getAllKeyValues() + .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; ContextManager.activeSpan().log(context.getError()); } - // TODO: Micrometer Context-Propagation with ThreadLocalAccessor for ContextManager ??? + } + + private String tryToGetPeer(ReceiverContext context) { + if (context.getRemoteServiceAddress() != null) { + return context.getRemoteServiceAddress(); + } + KeyValue uri = context.getLowCardinalityKeyValue("uri"); + if (uri != null) { + return uri.getValue(); + } + return context.getAllKeyValues() + .stream() + .filter(keyValue -> "uri".equalsIgnoreCase(keyValue.getKey()) || "http.url".equalsIgnoreCase( + keyValue.getKey())) + .findFirst() + .map(KeyValue::getValue) + .orElse("unknown"); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java index a4dba0b00c..2804400035 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java @@ -34,6 +34,8 @@ public class MicrometerSenderTracingHandlerInstrumentation extends ClassInstance public static final String INTERCEPT_START_POINT_METHOD = "onStart"; + public static final String INTERCEPT_ERROR_POINT_METHOD = "onError"; + public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInterceptor"; @@ -45,7 +47,7 @@ protected ClassMatch enhanceClass() { @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; + return new ConstructorInterceptPoint[0]; } @Override @@ -54,24 +56,9 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_START_POINT_METHOD); - } - - @Override - public String getMethodsInterceptor() { - return INTERCEPT_CLASS; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, - - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named(INTERCEPT_STOP_POINT_METHOD); + return named(INTERCEPT_START_POINT_METHOD) + .or(named(INTERCEPT_STOP_POINT_METHOD)) + .or(named(INTERCEPT_ERROR_POINT_METHOD)); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java index 0582d612bb..ffca86eec7 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -18,12 +18,14 @@ package org.apache.skywalking.apm.plugin.micrometer; +import io.micrometer.common.KeyValue; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.SenderContext; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; @@ -53,12 +55,15 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr context.getSetter().set(context.getCarrier(), next.getHeadKey(), next.getHeadValue()); } span.setComponent(ComponentsDefine.MICROMETER); - // tags } else if ("onStop".equals(methodName)) { SenderContext context = (SenderContext) allArguments[0]; - ContextManager.activeSpan() - .setOperationName(StringUtil.isBlank( - context.getContextualName()) ? context.getName() : context.getContextualName()); + AbstractSpan abstractSpan = ContextManager.activeSpan(); + abstractSpan + .setPeer(tryToGetPeer(context)) + .setOperationName(StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName()); + context.getAllKeyValues() + .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; @@ -66,6 +71,23 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr } } + private String tryToGetPeer(SenderContext context) { + if (context.getRemoteServiceAddress() != null) { + return context.getRemoteServiceAddress(); + } + KeyValue uri = context.getLowCardinalityKeyValue("uri"); + if (uri != null) { + return uri.getValue(); + } + return context.getAllKeyValues() + .stream() + .filter(keyValue -> "uri".equalsIgnoreCase(keyValue.getKey()) || "http.url".equalsIgnoreCase( + keyValue.getKey())) + .findFirst() + .map(KeyValue::getValue) + .orElse("unknown"); + } + @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def index 079da236a3..3ca7e2e410 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -micrometerdefaulttracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInstrumentation -micrometersendertracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInstrumentation -micrometerreceivertracing=org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerContextManagerThreadLocalAccessorInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java new file mode 100644 index 0000000000..0494d96fa8 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import java.util.Collections; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.test.helper.FieldGetter; + +// TODO: Make a commonly used utility class out of this? +public class AbstractTracingSpanHelper { + + public static List getParentFieldLogs(AbstractTracingSpan tracingSpan) { + try { + return FieldGetter.getParentFieldValue(tracingSpan, "logs"); + } catch (Exception e) { + } + + return Collections.emptyList(); + } + + public static List get2LevelParentFieldLogs(AbstractTracingSpan tracingSpan) { + try { + return FieldGetter.get2LevelParentFieldValue(tracingSpan, "logs"); + } catch (Exception e) { + } + + return Collections.emptyList(); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java new file mode 100644 index 0000000000..9974fbfe1c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import java.lang.reflect.Method; +import java.util.List; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +@RunWith(TracingSegmentRunner.class) +public class MicrometerContextSnapshotThreadLocalAccessorInterceptorTest { + + private final Class[] argumentTypes = new Class[] {Object.class}; + private final Method get = SkywalkingContextSnapshotThreadLocalAccessor.class.getMethod("getValue"); + private final Method set = SkywalkingContextSnapshotThreadLocalAccessor.class.getMethod("setValue", Object.class); + private final Method reset = SkywalkingContextSnapshotThreadLocalAccessor.class.getMethod("reset"); + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Mock + private EnhancedInstance enhancedInstance; + @Mock + private MethodInterceptResult result; + private MicrometerContextSnapshotThreadLocalAccessorInterceptor interceptor; + private ContextSnapshot context; + private Object[] consumerArguments; + private AbstractSpan testSpan; + + public MicrometerContextSnapshotThreadLocalAccessorInterceptorTest() throws NoSuchMethodException { + } + + @Before + public void setUp() throws Exception { + interceptor = new MicrometerContextSnapshotThreadLocalAccessorInterceptor(); + + Config.Agent.SERVICE_NAME = "MicrometerContextSnapshotThreadLocalAccessorTestCases-APP"; + + testSpan = ContextManager.createLocalSpan("test from threadlocalaccessor test"); + context = ContextManager.capture(); + consumerArguments = new Object[] {context}; + } + + @After + public void clear() { + assertThat(ContextManager.isActive(), is(false)); + } + + @AfterClass + public static void clearAfterAll() { + // test from threadlocalaccessor test x 2 TODO: I have no idea what is going on + ContextManager.stopSpan(); + ContextManager.stopSpan(); + assertThat(ContextManager.isActive(), is(false)); + } + + @Test + public void testServiceFromPlugin() { + PluginBootService service = ServiceManager.INSTANCE.findService( + PluginBootService.class); + + Assert.assertNotNull(service); + } + + @Test + public void testServiceOverrideFromPlugin() { + ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class); + + Assert.assertTrue(service instanceof ContextManagerExtendOverrideService); + } + + @Test + public void testGetSetReset() throws Throwable { + ContextSnapshot contextSnapshot = (ContextSnapshot) interceptor.afterMethod( + enhancedInstance, get, new Object[0], new Class[0], result); + + ContextSnapshot currentCapturedContext = ContextManager.capture(); + assertThat(currentCapturedContext, not(equalTo(contextSnapshot))); + assertThat(currentCapturedContext.getTraceId(), equalTo(contextSnapshot.getTraceId())); + + ContextManager.stopSpan(); + + interceptor.afterMethod( + enhancedInstance, set, consumerArguments, argumentTypes, result); + + ContextManager.stopSpan(); + + assertThat(segmentStorage.getTraceSegments().size(), is(2)); + TraceSegment parent = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(parent); + assertThat(spans.size(), is(1)); + String operationName = spans.get(0).getOperationName(); + assertThat(operationName, is("test from threadlocalaccessor test")); + + TraceSegment continuedParent = segmentStorage.getTraceSegments().get(1); + assertThat(continuedParent.getRef().getParentEndpoint(), is(operationName)); + + interceptor.afterMethod( + enhancedInstance, reset, new Object[0], new Class[0], result); + + assertThat(ContextManager.isActive(), is(false)); + } + +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java index 5873eefb6f..7a34d0b4ff 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java @@ -26,7 +26,9 @@ import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; @@ -40,48 +42,60 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@RunWith(TracingSegmentRunner.class) public class MicrometerDefaultTracingHandlerInterceptorTest { - @SegmentStoragePoint - private SegmentStorage segmentStorage; - - @Rule - public AgentServiceRule agentServiceRule = new AgentServiceRule(); - - @Mock - private EnhancedInstance enhancedInstance; - - @Mock - private MethodInterceptResult result; - - private MicrometerDefaultTracingHandlerInterceptor micrometerDefaultTracingHandlerInterceptor; - private final Observation.Context context = new Observation.Context(); - + private final Observation.Event event = new Observation.Event() { + @Override + public String getContextualName() { + return "eventContextualName"; + } + + @Override + public String getName() { + return "eventName"; + } + }; private final Object[] consumerArguments = new Object[] {context}; - + private final Object[] eventArguments = new Object[] { + event, + context + }; private final Class[] argumentTypes = new Class[] {Observation.Context.class}; - + private final Class[] eventArgumentTypes = new Class[] { + Observation.Event.class, + Observation.Context.class + }; private final Method onStart = ObservationHandler.class.getMethod("onStart", Observation.Context.class); - private final Method onStop = ObservationHandler.class.getMethod("onStop", Observation.Context.class); - private final Method onError = ObservationHandler.class.getMethod("onError", Observation.Context.class); + private final Method onEvent = ObservationHandler.class.getMethod( + "onEvent", Observation.Event.class, Observation.Context.class); + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Mock + private EnhancedInstance enhancedInstance; + @Mock + private MethodInterceptResult result; + private MicrometerDefaultTracingHandlerInterceptor interceptor; public MicrometerDefaultTracingHandlerInterceptorTest() throws NoSuchMethodException { } @Before public void setUp() throws Exception { - micrometerDefaultTracingHandlerInterceptor = new MicrometerDefaultTracingHandlerInterceptor(); + context.setName("name"); + context.setContextualName("contextualName"); + + interceptor = new MicrometerDefaultTracingHandlerInterceptor(); Config.Agent.SERVICE_NAME = "MicrometerTestCases-APP"; } @@ -102,29 +116,51 @@ public void testServiceOverrideFromPlugin() { } @Test - public void testDefaultStartStop() throws Throwable { - micrometerDefaultTracingHandlerInterceptor.beforeMethod( + public void testDefaultStartEventStop() throws Throwable { + interceptor.beforeMethod( enhancedInstance, onStart, consumerArguments, argumentTypes, result); - micrometerDefaultTracingHandlerInterceptor.beforeMethod( + interceptor.beforeMethod( + enhancedInstance, onEvent, eventArguments, eventArgumentTypes, result); + interceptor.beforeMethod( enhancedInstance, onStop, consumerArguments, argumentTypes, result); - assertThat(segmentStorage.getTraceSegments().size(), is(1)); - TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); - List spans = SegmentHelper.getSpans(traceSegment); - assertThat(spans.size(), is(1)); + AbstractTracingSpan abstractTracingSpan = onlySpan(); + assertThat(abstractTracingSpan.getOperationName(), equalTo("contextualName")); + List logs = AbstractTracingSpanHelper.getParentFieldLogs(abstractTracingSpan); + assertThat(logs.size(), is(1)); + LogDataEntity logDataEntity = logs.get(0); + assertThat(logDataEntity.getLogs().size(), is(1)); + KeyValuePair keyValuePair = logDataEntity.getLogs().get(0); + assertThat(keyValuePair.getKey(), equalTo("event")); + assertThat(keyValuePair.getValue(), equalTo("eventContextualName")); } @Test - public void testDefailtStartExceptionStop() throws Throwable { - micrometerDefaultTracingHandlerInterceptor.beforeMethod( + public void testDefaultStartExceptionStop() throws Throwable { + interceptor.beforeMethod( enhancedInstance, onStart, consumerArguments, argumentTypes, result); context.setError(new RuntimeException("BOOM")); - micrometerDefaultTracingHandlerInterceptor.beforeMethod( + interceptor.beforeMethod( enhancedInstance, onError, consumerArguments, argumentTypes, result); - micrometerDefaultTracingHandlerInterceptor.beforeMethod( + interceptor.beforeMethod( enhancedInstance, onStop, consumerArguments, argumentTypes, result); + AbstractTracingSpan abstractTracingSpan = onlySpan(); + assertThat(abstractTracingSpan.getOperationName(), equalTo("contextualName")); + List logs = AbstractTracingSpanHelper.getParentFieldLogs(abstractTracingSpan); + assertThat(logs.size(), is(1)); + assertThat(logs.get(0).getLogs().size(), is(4)); // 4 events represent an exception + KeyValuePair errorLog = logs.get(0).getLogs().get(0); + assertThat(errorLog.getKey(), equalTo("event")); + assertThat(errorLog.getValue(), equalTo("error")); + } + + private AbstractTracingSpan onlySpan() { assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + AbstractTracingSpan abstractTracingSpan = spans.get(0); + return abstractTracingSpan; } } diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java new file mode 100644 index 0000000000..d7ac1d4e61 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.transport.ReceiverContext; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(TracingSegmentRunner.class) +public class MicrometerReceiverTracingHandlerInterceptorTest { + + private final ReceiverContext> context = new ReceiverContext<>( + (carrier, key) -> carrier.get(key)); + private final Object[] consumerArguments = new Object[] {context}; + private final Class[] argumentTypes = new Class[] {ReceiverContext.class}; + private final Method onStart = ObservationHandler.class.getMethod("onStart", Observation.Context.class); + private final Method onStop = ObservationHandler.class.getMethod("onStop", Observation.Context.class); + private final Method onError = ObservationHandler.class.getMethod("onError", Observation.Context.class); + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Mock + private EnhancedInstance enhancedInstance; + @Mock + private MethodInterceptResult result; + private MicrometerReceiverTracingHandlerInterceptor interceptor; + + public MicrometerReceiverTracingHandlerInterceptorTest() throws NoSuchMethodException { + } + + @Before + public void setUp() throws Exception { + context.setName("name"); + context.setContextualName("contextualName"); + Map map = new HashMap<>(); + map.put( + "sw8", + "sw8 -> 1-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMQ==-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMA==-0-TWljcm9tZXRlclJlY2VpdmVyVGVzdENhc2VzLUFQUA==-YWU5YWZkM2YxMDg0NGYzMzg1MGZlOGQwYzRkNzYwYTdAMTAuMTUuMTguMTE1-Y29udGV4dHVhbE5hbWU=-aHR0cDovL2xvY2FsaG9zdDo4MDgw" + ); + map.put("sw8-correlation", ""); + map.put("sw8-x", "0- "); + context.setCarrier(map); + + interceptor = new MicrometerReceiverTracingHandlerInterceptor(); + + Config.Agent.SERVICE_NAME = "MicrometerReceiverTestCases-APP"; + } + + @Test + public void testServiceFromPlugin() { + PluginBootService service = ServiceManager.INSTANCE.findService( + PluginBootService.class); + + Assert.assertNotNull(service); + } + + @Test + public void testServiceOverrideFromPlugin() { + ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class); + + Assert.assertTrue(service instanceof ContextManagerExtendOverrideService); + } + + @Test + public void testDefaultStartExceptionStop() throws Throwable { + interceptor.beforeMethod( + enhancedInstance, onStart, consumerArguments, argumentTypes, result); + context.setError(new RuntimeException("BOOM")); + interceptor.beforeMethod( + enhancedInstance, onError, consumerArguments, argumentTypes, result); + interceptor.beforeMethod( + enhancedInstance, onStop, consumerArguments, argumentTypes, result); + + AbstractTracingSpan abstractTracingSpan = onlySpan(); + assertThat(abstractTracingSpan.getOperationName(), equalTo("contextualName")); + assertThat(abstractTracingSpan.isEntry(), is(true)); + List logs = AbstractTracingSpanHelper.get2LevelParentFieldLogs(abstractTracingSpan); + assertThat(logs.size(), is(1)); + assertThat(logs.get(0).getLogs().size(), is(4)); // 4 events represent an exception + KeyValuePair errorLog = logs.get(0).getLogs().get(0); + assertThat(errorLog.getKey(), equalTo("event")); + assertThat(errorLog.getValue(), equalTo("error")); + } + + private AbstractTracingSpan onlySpan() { + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + AbstractTracingSpan abstractTracingSpan = spans.get(0); + return abstractTracingSpan; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java new file mode 100644 index 0000000000..d88f740837 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.transport.ReceiverContext; +import io.micrometer.observation.transport.SenderContext; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.agent.core.boot.ServiceManager; +import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.hamcrest.CoreMatchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(TracingSegmentRunner.class) +public class MicrometerSenderTracingHandlerInterceptorTest { + + private final SenderContext> context = new SenderContext<>( + (carrier, key, value) -> carrier.put(key, value)); + private final Map carrier = new HashMap<>(); + private final Object[] consumerArguments = new Object[] {context}; + private final Class[] argumentTypes = new Class[] {ReceiverContext.class}; + private final Method onStart = ObservationHandler.class.getMethod("onStart", Observation.Context.class); + private final Method onStop = ObservationHandler.class.getMethod("onStop", Observation.Context.class); + private final Method onError = ObservationHandler.class.getMethod("onError", Observation.Context.class); + @Rule + public AgentServiceRule agentServiceRule = new AgentServiceRule(); + @SegmentStoragePoint + private SegmentStorage segmentStorage; + @Mock + private EnhancedInstance enhancedInstance; + @Mock + private MethodInterceptResult result; + private MicrometerSenderTracingHandlerInterceptor interceptor; + + public MicrometerSenderTracingHandlerInterceptorTest() throws NoSuchMethodException { + } + + @Before + public void setUp() throws Exception { + context.setName("name"); + context.setContextualName("contextualName"); + context.setCarrier(carrier); + context.setRemoteServiceAddress("http://localhost:8080"); + + interceptor = new MicrometerSenderTracingHandlerInterceptor(); + + Config.Agent.SERVICE_NAME = "MicrometerSenderTestCases-APP"; + } + + @Test + public void testServiceFromPlugin() { + PluginBootService service = ServiceManager.INSTANCE.findService( + PluginBootService.class); + + Assert.assertNotNull(service); + } + + @Test + public void testServiceOverrideFromPlugin() { + ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class); + + Assert.assertTrue(service instanceof ContextManagerExtendOverrideService); + } + + @Test + public void testDefaultStartExceptionStop() throws Throwable { + interceptor.beforeMethod( + enhancedInstance, onStart, consumerArguments, argumentTypes, result); + context.setError(new RuntimeException("BOOM")); + interceptor.beforeMethod( + enhancedInstance, onError, consumerArguments, argumentTypes, result); + interceptor.beforeMethod( + enhancedInstance, onStop, consumerArguments, argumentTypes, result); + + AbstractTracingSpan abstractTracingSpan = onlySpan(); + assertThat(abstractTracingSpan.getOperationName(), equalTo("contextualName")); + assertThat(abstractTracingSpan.isExit(), is(true)); + List logs = AbstractTracingSpanHelper.get2LevelParentFieldLogs(abstractTracingSpan); + assertThat(logs.size(), is(1)); + assertThat(logs.get(0).getLogs().size(), is(4)); // 4 events represent an exception + KeyValuePair errorLog = logs.get(0).getLogs().get(0); + assertThat(errorLog.getKey(), equalTo("event")); + assertThat(errorLog.getValue(), equalTo("error")); + assertThat( + carrier.keySet(), CoreMatchers.hasItems("sw8", "sw8-correlation", "sw8-x")); // headers got instrumented + } + + private AbstractTracingSpan onlySpan() { + assertThat(segmentStorage.getTraceSegments().size(), is(1)); + TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + AbstractTracingSpan abstractTracingSpan = spans.get(0); + return abstractTracingSpan; + } +} diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index 748cd380cc..9d5ff07a43 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -56,6 +56,7 @@ - lettuce-5.x - light4j - mariadb-2.x +- micrometer-1.10.x - memcache-2.x - mongodb-2.x - mongodb-3.x diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml index 0a4f443244..db88ccc81b 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -39,7 +39,7 @@ (if you build from command line, just use ./mvnw -Dsw.version=x.y.z), but make sure not to check it into the code base / git --> - + 8.14.0-SNAPSHOT diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java index c86705b56a..075bc0e997 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java @@ -18,16 +18,22 @@ package org.apache.skywalking.testcase.resttemplate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/resttemplate") public class BackController { + private static final Logger LOGGER = LogManager.getLogger(BackController.class); + @GetMapping("/syncback") - public String syncBack() { + public String syncBack(@RequestHeader HttpHeaders httpHeaders) { + LOGGER.info("Got following headers [" + httpHeaders + "]"); return "Hello back"; } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java index 1ab0ef3cca..c87443fd17 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java @@ -25,7 +25,10 @@ import jakarta.annotation.PreDestroy; import java.util.List; import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler; import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingMeterHandler; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler; +import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @@ -47,6 +50,7 @@ static class ObservationConfiguration { ObservationRegistry observationRegistry(List> handlers) { ObservationRegistry registry = ObservationRegistry.create(); registry.observationConfig().observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers)); + registry.observationConfig().observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), new SkywalkingDefaultTracingHandler())); return registry; } From 64ccece167b00208a4091a00ec6088a46d2f2fc3 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 29 Nov 2022 13:02:47 +0100 Subject: [PATCH 03/18] Moved the code around, added tags and layer setting --- ...ingContextSnapshotThreadLocalAccessor.java | 2 +- .../SkywalkingDefaultTracingHandler.java | 2 +- .../observation/SkywalkingMeterHandler.java | 2 +- .../SkywalkingReceiverTracingHandler.java | 2 +- .../SkywalkingSenderTracingHandler.java | 2 +- .../SkywalkingMeterHandlerTests.java | 2 +- ...gerThreadLocalAccessorInstrumentation.java | 2 +- ...napshotThreadLocalAccessorInterceptor.java | 2 +- ...rDefaultTracingHandlerInstrumentation.java | 2 +- ...meterDefaultTracingHandlerInterceptor.java | 7 ++- ...ReceiverTracingHandlerInstrumentation.java | 2 +- ...eterReceiverTracingHandlerInterceptor.java | 26 ++++++---- ...erSenderTracingHandlerInstrumentation.java | 2 +- ...ometerSenderTracingHandlerInterceptor.java | 7 ++- .../apm/plugin/micrometer/TaggingHelper.java | 50 +++++++++++++++++++ ...hotThreadLocalAccessorInterceptorTest.java | 2 +- 16 files changed, 89 insertions(+), 25 deletions(-) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java (95%) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingDefaultTracingHandler.java (96%) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingMeterHandler.java (94%) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingReceiverTracingHandler.java (96%) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingSenderTracingHandler.java (96%) rename apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/{meter => toolkit}/micrometer/observation/SkywalkingMeterHandlerTests.java (96%) create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java similarity index 95% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java index be31cc02d2..0de5923eb4 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.context.ThreadLocalAccessor; diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java similarity index 96% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java index 4ef1e77cf8..ccf9662c7f 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingDefaultTracingHandler.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java similarity index 94% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java index 493c5093b6..066a181708 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandler.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler; import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java similarity index 96% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java index 29f686a2f5..fe32c88940 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingReceiverTracingHandler.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java similarity index 96% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java index 59bc3b1822..c16e8debed 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingSenderTracingHandler.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java similarity index 96% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java rename to apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java index 08fa72b0fa..df8115a3de 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/meter/micrometer/observation/SkywalkingMeterHandlerTests.java +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.meter.micrometer.observation; +package org.apache.skywalking.apm.toolkit.micrometer.observation; import io.micrometer.core.tck.MeterRegistryAssert; import io.micrometer.observation.Observation; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java index c8e9bced5f..a73c9f4dd0 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java @@ -30,7 +30,7 @@ public class MicrometerContextManagerThreadLocalAccessorInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor"; public static final String INTERCEPT_GET_VALUE_POINT_METHOD = "getValue"; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java index 72c695eba1..2b2a076ef9 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java @@ -25,7 +25,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java index bbb2e05f53..a7ea50f133 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java @@ -30,7 +30,7 @@ public class MicrometerDefaultTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingDefaultTracingHandler"; public static final String INTERCEPT_START_POINT_METHOD = "onStart"; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java index c0e0121d66..96f1657167 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java @@ -25,10 +25,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingDefaultTracingHandler; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.util.StringUtil; @@ -49,12 +50,16 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr // tags } else if ("onStop".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; + SpanLayer spanLayer = TaggingHelper.toLayer(context.getAllKeyValues()); AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan .setOperationName(StringUtil.isBlank( context.getContextualName()) ? context.getName() : context.getContextualName()); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); + if (spanLayer != null) { + abstractSpan.setLayer(spanLayer); + } ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java index 98d8f36f55..8f29334bee 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java @@ -30,7 +30,7 @@ public class MicrometerReceiverTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingReceiverTracingHandler"; public static final String INTERCEPT_START_POINT_METHOD = "onStart"; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index ed96b225f2..e713fa7c1a 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -27,10 +27,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingReceiverTracingHandler; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.util.StringUtil; @@ -40,6 +41,14 @@ */ public class MicrometerReceiverTracingHandlerInterceptor implements InstanceMethodsAroundInterceptor { + private static final String DB_TAG_PREFIX = "jdbc"; + + private static final String HTTP_TAG_PREFIX = "http"; + + private static final String RPC_TAG_PREFIX = "rpc"; + + private static final String MESSAGING_TAG_PREFIX = "rpc"; + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { @@ -54,13 +63,10 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr } AbstractSpan span = ContextManager.createEntrySpan(context.getName(), contextCarrier); span.setComponent(ComponentsDefine.MICROMETER); - // TODO: We can't really set these because ReceiverContext is super generic. We don't know what the protocol will be. We can guess it from the tags maybe? But there's no certainty that same tags will be used everywhere. OTOH - // entrySpan.setLayer(SpanLayer.HTTP); - // Tags.URL.set(entrySpan, httpRequest.path()); - // Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name()); } else if ("onStop".equals(methodName)) { ReceiverContext context = (ReceiverContext) allArguments[0]; + SpanLayer spanLayer = TaggingHelper.toLayer(context.getAllKeyValues()); AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan .setPeer(tryToGetPeer(context)) @@ -68,6 +74,9 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr context.getContextualName()) ? context.getName() : context.getContextualName()); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); + if (spanLayer != null) { + abstractSpan.setLayer(spanLayer); + } ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; @@ -79,14 +88,9 @@ private String tryToGetPeer(ReceiverContext context) { if (context.getRemoteServiceAddress() != null) { return context.getRemoteServiceAddress(); } - KeyValue uri = context.getLowCardinalityKeyValue("uri"); - if (uri != null) { - return uri.getValue(); - } return context.getAllKeyValues() .stream() - .filter(keyValue -> "uri".equalsIgnoreCase(keyValue.getKey()) || "http.url".equalsIgnoreCase( - keyValue.getKey())) + .filter(keyValue -> "http.url".equalsIgnoreCase(keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey())) .findFirst() .map(KeyValue::getValue) .orElse("unknown"); diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java index 2804400035..8b0f6986a2 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java @@ -30,7 +30,7 @@ public class MicrometerSenderTracingHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler"; + public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingSenderTracingHandler"; public static final String INTERCEPT_START_POINT_METHOD = "onStart"; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java index ffca86eec7..9349ef7929 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -27,10 +27,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingSenderTracingHandler; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.util.StringUtil; @@ -57,6 +58,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr span.setComponent(ComponentsDefine.MICROMETER); } else if ("onStop".equals(methodName)) { SenderContext context = (SenderContext) allArguments[0]; + SpanLayer spanLayer = TaggingHelper.toLayer(context.getAllKeyValues()); AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan .setPeer(tryToGetPeer(context)) @@ -64,6 +66,9 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr context.getContextualName()) ? context.getName() : context.getContextualName()); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); + if (spanLayer != null) { + abstractSpan.setLayer(spanLayer); + } ContextManager.stopSpan(); } else if ("onError".equals(methodName)) { Observation.Context context = (Observation.Context) allArguments[0]; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java new file mode 100644 index 0000000000..974b476468 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.common.KeyValue; +import io.micrometer.common.KeyValues; +import java.util.Locale; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; + +class TaggingHelper { + + private static final String DB_TAG_PREFIX = "jdbc"; + + private static final String HTTP_TAG_PREFIX = "http"; + + private static final String RPC_TAG_PREFIX = "rpc"; + + private static final String MESSAGING_TAG_PREFIX = "messaging"; + + static SpanLayer toLayer(KeyValues keyValues) { + for (KeyValue keyValue : keyValues) { + if (keyValue.getKey().toLowerCase(Locale.ROOT).startsWith(DB_TAG_PREFIX)) { + return SpanLayer.DB; + } else if (keyValue.getKey().toLowerCase(Locale.ROOT).startsWith(HTTP_TAG_PREFIX)) { + return SpanLayer.HTTP; + } else if (keyValue.getKey().toLowerCase(Locale.ROOT).startsWith(RPC_TAG_PREFIX)) { + return SpanLayer.RPC_FRAMEWORK; + } else if (keyValue.getKey().toLowerCase(Locale.ROOT).startsWith(MESSAGING_TAG_PREFIX)) { + return SpanLayer.MQ; + } + } + return null; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java index 9974fbfe1c..bac2365716 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java @@ -35,7 +35,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; From 6ac6b3f07eb9e7474ae1ce43bfdb7517da0cb76c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 30 Nov 2022 17:03:04 +0100 Subject: [PATCH 04/18] Added scenario --- .../trace/component/ComponentsDefine.java | 2 +- pom.xml | 1 - test/plugin/agent-test-tools/pom.xml | 2 +- .../tomcat-container/src/main/docker/run.sh | 2 +- test/plugin/run.sh | 2 +- .../resttemplate-6.x-scenario/bin/startup.sh | 21 ++++ .../config/expectedData.yaml | 107 ++++-------------- .../configuration.yml | 7 +- .../resttemplate-6.x-scenario/pom.xml | 68 ++++++----- .../WEB-INF/web.xml => assembly/assembly.xml} | 38 ++++--- .../testcase/resttemplate/BackController.java | 2 +- .../resttemplate/FrontController.java | 7 +- .../resttemplate/MyWebAppInitializer.java | 47 ++++++++ .../ObservationConfiguration.java | 84 ++++++++++++++ .../ResttemplateConfiguration.java | 51 --------- .../resttemplate/ServerConfiguration.java | 39 +++++++ .../resttemplate/SkywalkingApplication.java | 33 ++++++ .../src/main/resources/application.yml | 21 ++++ .../main/{resource => resources}/log4j2.xml | 0 .../webapp/WEB-INF/spring-mvc-servlet.xml | 30 ----- 20 files changed, 336 insertions(+), 228 deletions(-) create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh rename test/plugin/scenarios/resttemplate-6.x-scenario/src/main/{webapp/WEB-INF/web.xml => assembly/assembly.xml} (51%) create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/SkywalkingApplication.java create mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/application.yml rename test/plugin/scenarios/resttemplate-6.x-scenario/src/main/{resource => resources}/log4j2.xml (100%) delete mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index 614071799d..475219cb69 100755 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -231,6 +231,6 @@ public class ComponentsDefine { public static final OfficialComponent IMPALA_JDBC_DRIVER = new OfficialComponent(133, "Impala-jdbc-driver"); - public static final OfficialComponent MICROMETER = new OfficialComponent(134, "Micronaut"); + public static final OfficialComponent MICROMETER = new OfficialComponent(134, "Micrometer"); } diff --git a/pom.xml b/pom.xml index 29f666894d..c58790f429 100755 --- a/pom.xml +++ b/pom.xml @@ -391,7 +391,6 @@ ${project.build.sourceDirectory} ${project.build.testSourceDirectory} -scenarios/resttemplate-6.x.0-scenario **/*.properties, diff --git a/test/plugin/agent-test-tools/pom.xml b/test/plugin/agent-test-tools/pom.xml index 7238da230c..374263e7f4 100644 --- a/test/plugin/agent-test-tools/pom.xml +++ b/test/plugin/agent-test-tools/pom.xml @@ -35,7 +35,7 @@ pom - 1c0bef2dd1d828e07889302bea980b24900b0db5 + cf62c1b733fe2861229201a67b9cc0075ac3e236 ${project.basedir}/target/agent-test-tools https://github.com/apache/skywalking-agent-test-tool.git diff --git a/test/plugin/containers/tomcat-container/src/main/docker/run.sh b/test/plugin/containers/tomcat-container/src/main/docker/run.sh index 9219055478..7ec99dc966 100644 --- a/test/plugin/containers/tomcat-container/src/main/docker/run.sh +++ b/test/plugin/containers/tomcat-container/src/main/docker/run.sh @@ -57,7 +57,7 @@ export LOGS_HOME=${SCENARIO_HOME}/logs # share to catalina.sh # Speed up launch tomcat rm /usr/local/tomcat/webapps/* -rf # remove needn't app -sed -i "s%securerandom.source=file:/dev/random%securerandom.source=file:/dev/urandom%g" $JAVA_HOME/jre/lib/security/java.security +sed -i "s%securerandom.source=file:/dev/random%securerandom.source=file:/dev/urandom%g" $JAVA_HOME/jre/lib/security/java.security || echo "Failed to speed up tomcat launch - will continue" # To deploy testcase cp ${SCENARIO_HOME}/*.war /usr/local/tomcat/webapps/ diff --git a/test/plugin/run.sh b/test/plugin/run.sh index 3d3e164839..25dc8da643 100755 --- a/test/plugin/run.sh +++ b/test/plugin/run.sh @@ -33,7 +33,7 @@ num_of_testcases= container_image_version="1.0.0" base_image_java="eclipse-temurin:8-jdk" base_image_tomcat="tomcat:8.5-jdk8-openjdk" -jacoco_version="${JACOCO_VERSION:-0.8.6}" +jacoco_version="${JACOCO_VERSION:-0.8.8}" os="$(uname)" diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh new file mode 100644 index 0000000000..a1ca8efd71 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +home="$(cd "$(dirname $0)"; pwd)" + +java -jar ${agent_opts} ${home}/../libs/resttemplate-6.x-scenario.jar & diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml index e969ceca38..70c95f1a6d 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml @@ -14,124 +14,57 @@ # See the License for the specific language governing permissions and # limitations under the License. segmentItems: -- serviceName: resttemplate-6.x-observation-scenario - segmentSize: ge 4 +- serviceName: resttemplate-6.x-scenario + segmentSize: ge 2 segments: - segmentId: not null spans: - - operationName: HEAD:/resttemplate-6.x-observation-scenario/resttemplate/case/healthcheck + - operationName: http head /resttemplate/case/healthcheck parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: nq 0 isError: false spanType: Entry - peer: '' + peer: '/resttemplate-6.x-scenario/resttemplate/case/healthcheck' tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation0scenario/resttemplate/case/healthcheck'} - - {key: http.method, value: HEAD} - - {key: http.status_code, value: '200'} + - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/case/healthcheck'} + - {key: method, value: HEAD} + - {key: status, value: '200'} skipAnalysis: 'false' - segmentId: not null spans: - - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/asyncback + - operationName: http get /resttemplate/syncback parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: nq 0 isError: false spanType: Entry - peer: '' + peer: '/resttemplate-6.x-scenario/resttemplate/syncback' tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/asyncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} - refs: - - {parentEndpoint: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate, - networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, - parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-observation-scenario, - traceId: not null} + - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: method, value: GET} + - {key: status, value: '200'} skipAnalysis: 'false' - segmentId: not null spans: - - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/syncback - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: 1 - isError: false - spanType: Entry - peer: '' - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} - refs: - - {parentEndpoint: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate, - networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 3, - parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-observation-scenario, - traceId: not null} - skipAnalysis: 'false' - - segmentId: not null - spans: - - operationName: /resttemplate-6.x-observation-scenario/resttemplate/asyncback + - operationName: http get parentSpanId: 0 spanId: 1 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 13 + componentId: isError: false spanType: Exit - peer: localhost:8080 - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/asyncback'} - - {key: http.method, value: GET} - skipAnalysis: 'false' - - operationName: 'future/get:/resttemplate-6.x-observation-scenario/resttemplate/asyncback' - parentSpanId: 0 - spanId: 2 - spanLayer: Unknown - startTime: nq 0 - endTime: nq 0 - componentId: 0 - isError: false - spanType: Local - peer: '' - skipAnalysis: 'false' - - operationName: /resttemplate-6.x-observation-scenario/resttemplate/syncback - parentSpanId: 0 - spanId: 3 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: 13 - isError: false - spanType: Exit - peer: localhost:8080 - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} - skipAnalysis: 'false' - - operationName: GET:/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: not null - isError: false - spanType: Entry - peer: '' + peer: http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: http.url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: method, value: GET} + - {key: status, value: '200'} skipAnalysis: 'false' diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml b/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml index 13c6c03caa..6c36262563 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/configuration.yml @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -type: tomcat -entryService: http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/resttemplate -healthCheck: http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/case/healthcheck +type: jvm +entryService: http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/resttemplate +healthCheck: http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/healthcheck +startScript: ./bin/startup.sh diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml index db88ccc81b..c1e6c00ca7 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -22,9 +22,9 @@ 4.0.0 org.apache.skywalking - resttemplate-6.x-observation-scenario + resttemplate-6.x-scenario 6.5.0 - war + jar UTF-8 @@ -32,7 +32,7 @@ 17 6.0.2 ${test.framework.version} - 2.8.1 + 3.0.0 + + + zip + - - skywalking-resttemplate-6.x-observation-scenario + + + ./bin + 0775 + + - - spring-mvc - org.springframework.web.servlet.DispatcherServlet - 1 - - - spring-mvc - / - - + + + ./target/resttemplate-6.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java index 075bc0e997..7adf11ae00 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java @@ -33,7 +33,7 @@ public class BackController { @GetMapping("/syncback") public String syncBack(@RequestHeader HttpHeaders httpHeaders) { - LOGGER.info("Got following headers [" + httpHeaders + "]"); + LOGGER.info("Got following headers " + httpHeaders ); return "Hello back"; } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java index aff7d7fae9..18c1b45c3a 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -31,8 +30,6 @@ @RequestMapping("/resttemplate/case") public class FrontController { - private static final Logger LOGGER = LogManager.getLogger(FrontController.class); - @Autowired private RestTemplate restTemplate; @@ -41,9 +38,9 @@ public String healthcheck() { return "Success"; } - @GetMapping( "/resttemplate") + @GetMapping("/resttemplate") public String front() { - syncRequest("http://localhost:8080/resttemplate-6.x-observation-scenario/resttemplate/syncback"); + syncRequest("http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback"); return "Success"; } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java new file mode 100644 index 0000000000..8e140c3297 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import io.micrometer.observation.ObservationRegistry; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletRegistration; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.filter.ServerHttpObservationFilter; +import org.springframework.web.servlet.DispatcherServlet; + +public class MyWebAppInitializer implements WebApplicationInitializer { + @Override + public void onStartup(ServletContext container) { + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); + context.setConfigLocation("org.apache.skywalking.testcase.resttemplate"); + + container.addListener(new ContextLoaderListener(context)); + + ServletRegistration.Dynamic dispatcher = container + .addServlet("dispatcher", new DispatcherServlet(context)); + + dispatcher.setLoadOnStartup(1); + dispatcher.addMapping("/"); + + container.addFilter( + "observation-filter", new ServerHttpObservationFilter(context.getBean(ObservationRegistry.class))); + } +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java new file mode 100644 index 0000000000..34e15cf54a --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.observation.MeterObservationHandler; +import io.micrometer.observation.ObservationHandler; +import io.micrometer.observation.ObservationRegistry; +import jakarta.annotation.PreDestroy; +import java.util.List; +import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingDefaultTracingHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingMeterHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingReceiverTracingHandler; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingSenderTracingHandler; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +class ObservationConfiguration { + + @Bean + ObservationRegistry observationRegistry(List> handlers) { + ObservationRegistry registry = ObservationRegistry.create(); + registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers)); + registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( + new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), + new SkywalkingDefaultTracingHandler() + )); + return registry; + } + + @Bean + SkywalkingMeterRegistry meterRegistry() { + return new SkywalkingMeterRegistry(); + } + + @Bean + MeterObservationHandler meterObservationHandler(SkywalkingMeterRegistry skywalkingMeterRegistry) { + return new SkywalkingMeterHandler(skywalkingMeterRegistry); + } + + @Bean + MetricsDumper metricsDumper(MeterRegistry meterRegistry) { + return new MetricsDumper(meterRegistry); + } + + static class MetricsDumper { + private final MeterRegistry meterRegistry; + + MetricsDumper(MeterRegistry meterRegistry) { + this.meterRegistry = meterRegistry; + } + + @PreDestroy + void dumpMetrics() { + System.out.println("==== METRICS ===="); + this.meterRegistry.getMeters() + .forEach(meter -> System.out.println( + " - Metric type \t[" + meter.getId().getType() + "],\tname [" + meter.getId() + .getName() + "],\ttags " + meter.getId() + .getTags() + ",\tmeasurements " + meter.measure())); + System.out.println("================="); + } + } +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java index c87443fd17..136929f9e9 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ResttemplateConfiguration.java @@ -18,17 +18,7 @@ package org.apache.skywalking.testcase.resttemplate; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.observation.MeterObservationHandler; -import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationRegistry; -import jakarta.annotation.PreDestroy; -import java.util.List; -import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingDefaultTracingHandler; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingMeterHandler; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingReceiverTracingHandler; -import org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingSenderTracingHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @@ -43,45 +33,4 @@ public RestTemplate restTemplate(ObservationRegistry observationRegistry) { return restTemplate; } - @Configuration(proxyBeanMethods = false) - static class ObservationConfiguration { - - @Bean - ObservationRegistry observationRegistry(List> handlers) { - ObservationRegistry registry = ObservationRegistry.create(); - registry.observationConfig().observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(handlers)); - registry.observationConfig().observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler(new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), new SkywalkingDefaultTracingHandler())); - return registry; - } - - @Bean - SkywalkingMeterRegistry meterRegistry() { - return new SkywalkingMeterRegistry(); - } - - @Bean - MeterObservationHandler meterObservationHandler(SkywalkingMeterRegistry skywalkingMeterRegistry) { - return new SkywalkingMeterHandler(skywalkingMeterRegistry); - } - - @Bean - MetricsDumper metricsDumper(MeterRegistry meterRegistry) { - return new MetricsDumper(meterRegistry); - } - - static class MetricsDumper { - private final MeterRegistry meterRegistry; - - MetricsDumper(MeterRegistry meterRegistry) { - this.meterRegistry = meterRegistry; - } - - @PreDestroy - void dumpMetrics() { - System.out.println("==== METRICS ===="); - this.meterRegistry.getMeters().forEach(meter -> System.out.println(" - Metric type \t[" + meter.getId().getType() + "],\tname [" + meter.getId().getName() + "],\ttags " + meter.getId().getTags() + ",\tmeasurements " + meter.measure())); - System.out.println("================="); - } - } - } } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java new file mode 100644 index 0000000000..46c56d06fd --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import io.micrometer.observation.ObservationRegistry; +import jakarta.servlet.DispatcherType; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.web.filter.ServerHttpObservationFilter; + +@Configuration +public class ServerConfiguration { + @Bean + FilterRegistrationBean testServerHttpObservationFilter(ObservationRegistry observationRegistry) { + FilterRegistrationBean registration = new FilterRegistrationBean( + new ServerHttpObservationFilter(observationRegistry)); + registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1); + registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC); + return registration; + } +} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/SkywalkingApplication.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/SkywalkingApplication.java new file mode 100644 index 0000000000..3c5584891b --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/SkywalkingApplication.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.testcase.resttemplate; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SkywalkingApplication { + + public static void main(String[] args) { + SpringApplication.run(SkywalkingApplication.class, args); + } + +} + + diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/application.yml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/application.yml new file mode 100644 index 0000000000..dde3d2be03 --- /dev/null +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/application.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +server: + port: 8080 + servlet: + context-path: /resttemplate-6.x-scenario + diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/log4j2.xml similarity index 100% rename from test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resource/log4j2.xml rename to test/plugin/scenarios/resttemplate-6.x-scenario/src/main/resources/log4j2.xml diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml deleted file mode 100644 index 1ede76abd1..0000000000 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/webapp/WEB-INF/spring-mvc-servlet.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - \ No newline at end of file From 72e0c0307ced3809e6dcc084136c03298d7dc0fe Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 1 Dec 2022 18:27:24 +0100 Subject: [PATCH 05/18] Polish --- ...eterReceiverTracingHandlerInterceptor.java | 42 +++-- ...ometerSenderTracingHandlerInterceptor.java | 37 ++-- ...ReceiverTracingHandlerInterceptorTest.java | 2 +- .../resttemplate-6.x-scenario/bin/startup.sh | 3 + .../config/expectedData.yaml | 175 ++++++++++++------ .../resttemplate-6.x-scenario/pom.xml | 15 +- .../resttemplate/FrontController.java | 2 - .../resttemplate/ServerConfiguration.java | 3 + 8 files changed, 189 insertions(+), 90 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index e713fa7c1a..fffb10914c 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -22,6 +22,7 @@ import io.micrometer.observation.Observation; import io.micrometer.observation.transport.ReceiverContext; import java.lang.reflect.Method; +import java.net.URI; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -31,8 +32,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingReceiverTracingHandler; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingReceiverTracingHandler; import org.apache.skywalking.apm.util.StringUtil; /** @@ -41,14 +42,6 @@ */ public class MicrometerReceiverTracingHandlerInterceptor implements InstanceMethodsAroundInterceptor { - private static final String DB_TAG_PREFIX = "jdbc"; - - private static final String HTTP_TAG_PREFIX = "http"; - - private static final String RPC_TAG_PREFIX = "rpc"; - - private static final String MESSAGING_TAG_PREFIX = "rpc"; - @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { @@ -61,7 +54,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr next = next.next(); next.setHeadValue(context.getGetter().get(context.getCarrier(), next.getHeadKey())); } - AbstractSpan span = ContextManager.createEntrySpan(context.getName(), contextCarrier); + AbstractSpan span = ContextManager.createEntrySpan(getOperationName(context), contextCarrier); span.setComponent(ComponentsDefine.MICROMETER); } else if ("onStop".equals(methodName)) { @@ -70,8 +63,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan .setPeer(tryToGetPeer(context)) - .setOperationName(StringUtil.isBlank( - context.getContextualName()) ? context.getName() : context.getContextualName()); + .setOperationName(getOperationName(context)); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); if (spanLayer != null) { @@ -84,16 +76,30 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr } } + private static String getOperationName(final ReceiverContext context) { + return StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName(); + } + private String tryToGetPeer(ReceiverContext context) { if (context.getRemoteServiceAddress() != null) { return context.getRemoteServiceAddress(); } - return context.getAllKeyValues() - .stream() - .filter(keyValue -> "http.url".equalsIgnoreCase(keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey())) - .findFirst() - .map(KeyValue::getValue) - .orElse("unknown"); + String result = context.getAllKeyValues() + .stream() + .filter(keyValue -> "http.url".equalsIgnoreCase( + keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey()) + || keyValue.getKey().contains("uri") || keyValue.getKey().contains("url") + ) + .findFirst() + .map(KeyValue::getValue) + .orElse("unknown"); + try { + URI uri = URI.create(result); + return uri.getHost() + ":" + uri.getPort(); + } catch (Exception ex) { + return "unknown"; + } } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java index 9349ef7929..7e77b59d3b 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -22,6 +22,7 @@ import io.micrometer.observation.Observation; import io.micrometer.observation.transport.SenderContext; import java.lang.reflect.Method; +import java.net.URI; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -31,8 +32,8 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; -import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingSenderTracingHandler; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingSenderTracingHandler; import org.apache.skywalking.apm.util.StringUtil; /** @@ -49,7 +50,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr SenderContext context = (SenderContext) allArguments[0]; final ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan( - context.getContextualName(), contextCarrier, context.getRemoteServiceAddress()); + getOperationName(context), contextCarrier, context.getRemoteServiceAddress()); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); @@ -62,8 +63,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan .setPeer(tryToGetPeer(context)) - .setOperationName(StringUtil.isBlank( - context.getContextualName()) ? context.getName() : context.getContextualName()); + .setOperationName(getOperationName(context)); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); if (spanLayer != null) { @@ -76,21 +76,30 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr } } + private static String getOperationName(final SenderContext context) { + return StringUtil.isBlank( + context.getContextualName()) ? context.getName() : context.getContextualName(); + } + private String tryToGetPeer(SenderContext context) { if (context.getRemoteServiceAddress() != null) { return context.getRemoteServiceAddress(); } - KeyValue uri = context.getLowCardinalityKeyValue("uri"); - if (uri != null) { - return uri.getValue(); + String result = context.getAllKeyValues() + .stream() + .filter(keyValue -> "http.url".equalsIgnoreCase( + keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey()) + || keyValue.getKey().contains("uri") || keyValue.getKey().contains("url") + ) + .findFirst() + .map(KeyValue::getValue) + .orElse("unknown"); + try { + URI uri = URI.create(result); + return uri.getHost() + ":" + uri.getPort(); + } catch (Exception ex) { + return "unknown"; } - return context.getAllKeyValues() - .stream() - .filter(keyValue -> "uri".equalsIgnoreCase(keyValue.getKey()) || "http.url".equalsIgnoreCase( - keyValue.getKey())) - .findFirst() - .map(KeyValue::getValue) - .orElse("unknown"); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java index d7ac1d4e61..e85754aebc 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java @@ -80,7 +80,7 @@ public void setUp() throws Exception { Map map = new HashMap<>(); map.put( "sw8", - "sw8 -> 1-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMQ==-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMA==-0-TWljcm9tZXRlclJlY2VpdmVyVGVzdENhc2VzLUFQUA==-YWU5YWZkM2YxMDg0NGYzMzg1MGZlOGQwYzRkNzYwYTdAMTAuMTUuMTguMTE1-Y29udGV4dHVhbE5hbWU=-aHR0cDovL2xvY2FsaG9zdDo4MDgw" + "1-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMQ==-Njc3OTM1ZDM4ZTFiNDAwMzk3NDU4MjI2OTM4YWU3MmIuMS4xNjY5NjM5MDI1ODE1MDAwMA==-0-TWljcm9tZXRlclJlY2VpdmVyVGVzdENhc2VzLUFQUA==-YWU5YWZkM2YxMDg0NGYzMzg1MGZlOGQwYzRkNzYwYTdAMTAuMTUuMTguMTE1-Y29udGV4dHVhbE5hbWU=-aHR0cDovL2xvY2FsaG9zdDo4MDgw" ); map.put("sw8-correlation", ""); map.put("sw8-x", "0- "); diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh index a1ca8efd71..20dd565e15 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh @@ -18,4 +18,7 @@ home="$(cd "$(dirname $0)"; pwd)" +export SW_EXCLUDE_PLUGINS=spring-mvc-annotation,spring-mvc-annotation-3.x,spring-mvc-annotation-4.x,spring-mvc-annotation-5.x,spring-resttemplate-4.x,tomcat-7.x/8.x,tomcat-10.x +export SW_AGENT_KEEP_TRACING=true + java -jar ${agent_opts} ${home}/../libs/resttemplate-6.x-scenario.jar & diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml index 70c95f1a6d..c61eecc11b 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml @@ -14,57 +14,124 @@ # See the License for the specific language governing permissions and # limitations under the License. segmentItems: -- serviceName: resttemplate-6.x-scenario - segmentSize: ge 2 - segments: - - segmentId: not null - spans: - - operationName: http head /resttemplate/case/healthcheck - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: nq 0 - isError: false - spanType: Entry - peer: '/resttemplate-6.x-scenario/resttemplate/case/healthcheck' - tags: - - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/case/healthcheck'} - - {key: method, value: HEAD} - - {key: status, value: '200'} - skipAnalysis: 'false' - - segmentId: not null - spans: - - operationName: http get /resttemplate/syncback - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: nq 0 - isError: false - spanType: Entry - peer: '/resttemplate-6.x-scenario/resttemplate/syncback' - tags: - - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/syncback'} - - {key: method, value: GET} - - {key: status, value: '200'} - skipAnalysis: 'false' - - segmentId: not null - spans: - - operationName: http get - parentSpanId: 0 - spanId: 1 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: - isError: false - spanType: Exit - peer: http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback - tags: - - {key: http.url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} - - {key: method, value: GET} - - {key: status, value: '200'} - skipAnalysis: 'false' + - serviceName: resttemplate-6.x-scenario + segmentSize: ge 4 + segments: + - segmentId: not null + spans: + - operationName: HEAD:/resttemplate-6.x-scenario/resttemplate/case/healthcheck + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/healthcheck'} + - {key: http.method, value: HEAD} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: GET:/resttemplate-6.x-scenario/resttemplate/asyncback + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/asyncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + refs: + - {parentEndpoint: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate, + networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, + parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-scenario, + traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: GET:/resttemplate-6.x-scenario/resttemplate/syncback + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + refs: + - {parentEndpoint: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate, + networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 3, + parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-scenario, + traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: /resttemplate-6.x-scenario/resttemplate/asyncback + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:8080 + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/asyncback'} + - {key: http.method, value: GET} + skipAnalysis: 'false' + - operationName: 'future/get:/resttemplate-6.x-scenario/resttemplate/asyncback' + parentSpanId: 0 + spanId: 2 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 0 + isError: false + spanType: Local + peer: '' + skipAnalysis: 'false' + - operationName: /resttemplate-6.x-scenario/resttemplate/syncback + parentSpanId: 0 + spanId: 3 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 13 + isError: false + spanType: Exit + peer: localhost:8080 + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' + - operationName: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: not null + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/resttemplate'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml index c1e6c00ca7..15945dd118 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -39,7 +39,7 @@ (if you build from command line, just use ./mvnw -Dsw.version=x.y.z), but make sure not to check it into the code base / git --> - 8.14.0-SNAPSHOT + @@ -56,6 +56,19 @@ apm-toolkit-micrometer-registry ${sw.version} + + + org.apache.skywalking + apm-micrometer-1.10.x-plugin + ${sw.version} + runtime + + + org.apache.skywalking + apm-agent-core + ${sw.version} + runtime + org.springframework spring-webmvc diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java index 18c1b45c3a..c1fd1ee1bc 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java @@ -18,8 +18,6 @@ package org.apache.skywalking.testcase.resttemplate; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java index 46c56d06fd..e48f713945 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java @@ -20,6 +20,7 @@ import io.micrometer.observation.ObservationRegistry; import jakarta.servlet.DispatcherType; +import java.util.Collections; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,12 +29,14 @@ @Configuration public class ServerConfiguration { + @Bean FilterRegistrationBean testServerHttpObservationFilter(ObservationRegistry observationRegistry) { FilterRegistrationBean registration = new FilterRegistrationBean( new ServerHttpObservationFilter(observationRegistry)); registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1); registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC); + registration.setUrlPatterns(Collections.singletonList("/resttemplate/syncback")); return registration; } } From e4f61641aa58d3aadee2c04a214fab858bd02cba Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 2 Dec 2022 16:09:42 +0100 Subject: [PATCH 06/18] Added e2e scenario for resttemplate + mvc with spring framework 6 --- ...eterReceiverTracingHandlerInterceptor.java | 5 +- ...ometerSenderTracingHandlerInterceptor.java | 7 +- .../resttemplate-6.x-scenario/bin/startup.sh | 1 - .../config/expectedData.yaml | 108 +++++------------- .../resttemplate/FrontController.java | 6 +- .../resttemplate/MyWebAppInitializer.java | 47 -------- .../resttemplate/ServerConfiguration.java | 3 +- 7 files changed, 43 insertions(+), 134 deletions(-) delete mode 100644 test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index fffb10914c..083fd693d1 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -96,9 +96,12 @@ private String tryToGetPeer(ReceiverContext context) { .orElse("unknown"); try { URI uri = URI.create(result); + if (uri.getHost() == null) { + return null; + } return uri.getHost() + ":" + uri.getPort(); } catch (Exception ex) { - return "unknown"; + return null; } } diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java index 7e77b59d3b..4b7a8f841f 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -50,7 +50,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr SenderContext context = (SenderContext) allArguments[0]; final ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan( - getOperationName(context), contextCarrier, context.getRemoteServiceAddress()); + getOperationName(context), contextCarrier, tryToGetPeer(context)); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); @@ -96,9 +96,12 @@ private String tryToGetPeer(SenderContext context) { .orElse("unknown"); try { URI uri = URI.create(result); + if (uri.getHost() == null) { + return null; + } return uri.getHost() + ":" + uri.getPort(); } catch (Exception ex) { - return "unknown"; + return null; } } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh index 20dd565e15..197feca45a 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/bin/startup.sh @@ -19,6 +19,5 @@ home="$(cd "$(dirname $0)"; pwd)" export SW_EXCLUDE_PLUGINS=spring-mvc-annotation,spring-mvc-annotation-3.x,spring-mvc-annotation-4.x,spring-mvc-annotation-5.x,spring-resttemplate-4.x,tomcat-7.x/8.x,tomcat-10.x -export SW_AGENT_KEEP_TRACING=true java -jar ${agent_opts} ${home}/../libs/resttemplate-6.x-scenario.jar & diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml index c61eecc11b..07ba1a0599 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml @@ -15,123 +15,69 @@ # limitations under the License. segmentItems: - serviceName: resttemplate-6.x-scenario - segmentSize: ge 4 + segmentSize: ge 2 segments: - segmentId: not null spans: - - operationName: HEAD:/resttemplate-6.x-scenario/resttemplate/case/healthcheck + - operationName: http get /resttemplate/syncback parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: 134 isError: false spanType: Entry peer: '' tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/healthcheck'} - - {key: http.method, value: HEAD} - - {key: http.status_code, value: '200'} - skipAnalysis: 'false' - - segmentId: not null - spans: - - operationName: GET:/resttemplate-6.x-scenario/resttemplate/asyncback - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: 1 - isError: false - spanType: Entry - peer: '' - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/asyncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: exception, value: none} + - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: method, value: GET} + - {key: outcome, value: SUCCESS} + - {key: status, value: '200'} + - {key: uri, value: '/resttemplate/syncback'} refs: - - {parentEndpoint: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate, + - {parentEndpoint: http.server.requests, networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-scenario, traceId: not null} skipAnalysis: 'false' - segmentId: not null spans: - - operationName: GET:/resttemplate-6.x-scenario/resttemplate/syncback - parentSpanId: -1 - spanId: 0 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: 1 - isError: false - spanType: Entry - peer: '' - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} - refs: - - {parentEndpoint: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate, - networkAddress: 'localhost:8080', refType: CrossProcess, parentSpanId: 3, - parentTraceSegmentId: not null, parentServiceInstance: not null, parentService: resttemplate-6.x-scenario, - traceId: not null} - skipAnalysis: 'false' - - segmentId: not null - spans: - - operationName: /resttemplate-6.x-scenario/resttemplate/asyncback + - operationName: http get parentSpanId: 0 spanId: 1 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 13 - isError: false - spanType: Exit - peer: localhost:8080 - tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/asyncback'} - - {key: http.method, value: GET} - skipAnalysis: 'false' - - operationName: 'future/get:/resttemplate-6.x-scenario/resttemplate/asyncback' - parentSpanId: 0 - spanId: 2 - spanLayer: Unknown - startTime: nq 0 - endTime: nq 0 - componentId: 0 - isError: false - spanType: Local - peer: '' - skipAnalysis: 'false' - - operationName: /resttemplate-6.x-scenario/resttemplate/syncback - parentSpanId: 0 - spanId: 3 - spanLayer: Http - startTime: nq 0 - endTime: nq 0 - componentId: 13 + componentId: 134 isError: false spanType: Exit peer: localhost:8080 tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: client.name, value: 'localhost'} + - {key: exception, value: none} + - {key: http.url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} + - {key: method, value: GET} + - {key: outcome, value: SUCCESS} + - {key: status, value: '200'} + - {key: uri, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback'} skipAnalysis: 'false' - - operationName: GET:/resttemplate-6.x-scenario/resttemplate/case/resttemplate + - operationName: http get /resttemplate/case/resttemplate parentSpanId: -1 spanId: 0 spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: not null + componentId: 134 isError: false spanType: Entry peer: '' tags: - - {key: url, value: 'http://localhost:8080/resttemplate-6.x-scenario/resttemplate/case/resttemplate'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: exception, value: none} + - {key: http.url, value: '/resttemplate-6.x-scenario/resttemplate/case/resttemplate'} + - {key: method, value: GET} + - {key: outcome, value: SUCCESS} + - {key: status, value: '200'} + - {key: uri, value: '/resttemplate/case/resttemplate'} skipAnalysis: 'false' diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java index c1fd1ee1bc..eb46b9aa7c 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/FrontController.java @@ -19,6 +19,7 @@ package org.apache.skywalking.testcase.resttemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -28,6 +29,9 @@ @RequestMapping("/resttemplate/case") public class FrontController { + @Value("${server.port:8080}") + int port; + @Autowired private RestTemplate restTemplate; @@ -38,7 +42,7 @@ public String healthcheck() { @GetMapping("/resttemplate") public String front() { - syncRequest("http://localhost:8080/resttemplate-6.x-scenario/resttemplate/syncback"); + syncRequest("http://localhost:" + port + "/resttemplate-6.x-scenario/resttemplate/syncback"); return "Success"; } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java deleted file mode 100644 index 8e140c3297..0000000000 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/MyWebAppInitializer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.skywalking.testcase.resttemplate; - -import io.micrometer.observation.ObservationRegistry; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletRegistration; -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.filter.ServerHttpObservationFilter; -import org.springframework.web.servlet.DispatcherServlet; - -public class MyWebAppInitializer implements WebApplicationInitializer { - @Override - public void onStartup(ServletContext container) { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.setConfigLocation("org.apache.skywalking.testcase.resttemplate"); - - container.addListener(new ContextLoaderListener(context)); - - ServletRegistration.Dynamic dispatcher = container - .addServlet("dispatcher", new DispatcherServlet(context)); - - dispatcher.setLoadOnStartup(1); - dispatcher.addMapping("/"); - - container.addFilter( - "observation-filter", new ServerHttpObservationFilter(context.getBean(ObservationRegistry.class))); - } -} diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java index e48f713945..6db042656c 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java @@ -20,6 +20,7 @@ import io.micrometer.observation.ObservationRegistry; import jakarta.servlet.DispatcherType; +import java.util.Arrays; import java.util.Collections; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -36,7 +37,7 @@ FilterRegistrationBean testServerHttpObservationFilter(ObservationRegistry obser new ServerHttpObservationFilter(observationRegistry)); registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1); registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC); - registration.setUrlPatterns(Collections.singletonList("/resttemplate/syncback")); + registration.setUrlPatterns(Arrays.asList("/resttemplate/syncback", "/resttemplate/case/resttemplate")); return registration; } } From da3bfe2ee26f7ed4af526ccb009e2a4d47300695 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 2 Dec 2022 16:43:46 +0100 Subject: [PATCH 07/18] Updated changes.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 376dbd9ee2..8a55816f1e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Release Notes. * Report the agent version to OAP as an instance attribute * Polish jedis-4.x-plugin to change command to lowercase, which is consistent with jedis-2.x-3.x-plugin * Add micronauthttpclient,micronauthttpserver,memcached,ehcache,guavacache,jedis,redisson plugin config properties to agent.config +* Add [Micrometer Observation](https://micrometer.io/docs/observation) support #### Documentation From 534d3f2f15d440f3e67eb6384b4571f91d7f53d0 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 2 Dec 2022 17:02:48 +0100 Subject: [PATCH 08/18] Updated the component number --- .../apm/network/trace/component/ComponentsDefine.java | 2 +- .../resttemplate-6.x-scenario/config/expectedData.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index 475219cb69..283d642c34 100755 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -231,6 +231,6 @@ public class ComponentsDefine { public static final OfficialComponent IMPALA_JDBC_DRIVER = new OfficialComponent(133, "Impala-jdbc-driver"); - public static final OfficialComponent MICROMETER = new OfficialComponent(134, "Micrometer"); + public static final OfficialComponent MICROMETER = new OfficialComponent(141, "Micrometer"); } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml index 07ba1a0599..3f43202211 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/config/expectedData.yaml @@ -25,7 +25,7 @@ segmentItems: spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 134 + componentId: 141 isError: false spanType: Entry peer: '' @@ -50,7 +50,7 @@ segmentItems: spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 134 + componentId: 141 isError: false spanType: Exit peer: localhost:8080 @@ -69,7 +69,7 @@ segmentItems: spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 134 + componentId: 141 isError: false spanType: Entry peer: '' From 5f306e6d6bb55bc0c093783468e9a61bab4d3e5a Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 2 Dec 2022 17:06:55 +0100 Subject: [PATCH 09/18] polish --- ...eterReceiverTracingHandlerInterceptor.java | 28 +---------- ...ometerSenderTracingHandlerInterceptor.java | 30 +---------- .../apm/plugin/micrometer/SpanHelper.java | 50 +++++++++++++++++++ 3 files changed, 53 insertions(+), 55 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index 083fd693d1..3825584102 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -18,11 +18,9 @@ package org.apache.skywalking.apm.plugin.micrometer; -import io.micrometer.common.KeyValue; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.ReceiverContext; import java.lang.reflect.Method; -import java.net.URI; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -62,7 +60,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr SpanLayer spanLayer = TaggingHelper.toLayer(context.getAllKeyValues()); AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan - .setPeer(tryToGetPeer(context)) + .setPeer(SpanHelper.tryToGetPeer(context.getRemoteServiceAddress(), context.getAllKeyValues())) .setOperationName(getOperationName(context)); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); @@ -81,30 +79,6 @@ private static String getOperationName(final ReceiverContext context) { context.getContextualName()) ? context.getName() : context.getContextualName(); } - private String tryToGetPeer(ReceiverContext context) { - if (context.getRemoteServiceAddress() != null) { - return context.getRemoteServiceAddress(); - } - String result = context.getAllKeyValues() - .stream() - .filter(keyValue -> "http.url".equalsIgnoreCase( - keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey()) - || keyValue.getKey().contains("uri") || keyValue.getKey().contains("url") - ) - .findFirst() - .map(KeyValue::getValue) - .orElse("unknown"); - try { - URI uri = URI.create(result); - if (uri.getHost() == null) { - return null; - } - return uri.getHost() + ":" + uri.getPort(); - } catch (Exception ex) { - return null; - } - } - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java index 4b7a8f841f..00f948cf3c 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -18,11 +18,9 @@ package org.apache.skywalking.apm.plugin.micrometer; -import io.micrometer.common.KeyValue; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.SenderContext; import java.lang.reflect.Method; -import java.net.URI; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -50,7 +48,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr SenderContext context = (SenderContext) allArguments[0]; final ContextCarrier contextCarrier = new ContextCarrier(); AbstractSpan span = ContextManager.createExitSpan( - getOperationName(context), contextCarrier, tryToGetPeer(context)); + getOperationName(context), contextCarrier, SpanHelper.tryToGetPeer(context.getRemoteServiceAddress(), context.getAllKeyValues())); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); @@ -62,7 +60,7 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr SpanLayer spanLayer = TaggingHelper.toLayer(context.getAllKeyValues()); AbstractSpan abstractSpan = ContextManager.activeSpan(); abstractSpan - .setPeer(tryToGetPeer(context)) + .setPeer(SpanHelper.tryToGetPeer(context.getRemoteServiceAddress(), context.getAllKeyValues())) .setOperationName(getOperationName(context)); context.getAllKeyValues() .forEach(keyValue -> abstractSpan.tag(Tags.ofKey(keyValue.getKey()), keyValue.getValue())); @@ -81,30 +79,6 @@ private static String getOperationName(final SenderContext context) { context.getContextualName()) ? context.getName() : context.getContextualName(); } - private String tryToGetPeer(SenderContext context) { - if (context.getRemoteServiceAddress() != null) { - return context.getRemoteServiceAddress(); - } - String result = context.getAllKeyValues() - .stream() - .filter(keyValue -> "http.url".equalsIgnoreCase( - keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey()) - || keyValue.getKey().contains("uri") || keyValue.getKey().contains("url") - ) - .findFirst() - .map(KeyValue::getValue) - .orElse("unknown"); - try { - URI uri = URI.create(result); - if (uri.getHost() == null) { - return null; - } - return uri.getHost() + ":" + uri.getPort(); - } catch (Exception ex) { - return null; - } - } - @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java new file mode 100644 index 0000000000..7da3843f0b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.micrometer; + +import io.micrometer.common.KeyValue; +import io.micrometer.common.KeyValues; +import java.net.URI; + +class SpanHelper { + + static String tryToGetPeer(String remoteAddress, KeyValues allKeyValues) { + if (remoteAddress != null) { + return remoteAddress; + } + String result = allKeyValues + .stream() + .filter(keyValue -> "http.url".equalsIgnoreCase( + keyValue.getKey()) || "uri".equalsIgnoreCase(keyValue.getKey()) + || keyValue.getKey().contains("uri") || keyValue.getKey().contains("url") + ) + .findFirst() + .map(KeyValue::getValue) + .orElse("unknown"); + try { + URI uri = URI.create(result); + if (uri.getHost() == null) { + return null; + } + return uri.getHost() + ":" + uri.getPort(); + } catch (Exception ex) { + return null; + } + } +} From 97c2fc780fd175360b8f351ee1c22850e442626e Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 09:35:18 +0100 Subject: [PATCH 10/18] Added missing headers + added test to CI --- .github/workflows/plugins-jdk17-test.0.yaml | 1 + .../io.micrometer.context.ThreadLocalAccessor | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.github/workflows/plugins-jdk17-test.0.yaml b/.github/workflows/plugins-jdk17-test.0.yaml index 45edcbac48..ddd07cfa3e 100644 --- a/.github/workflows/plugins-jdk17-test.0.yaml +++ b/.github/workflows/plugins-jdk17-test.0.yaml @@ -59,6 +59,7 @@ jobs: matrix: case: - jdk17-with-gson-scenario + - resttemplate-6.x-scenario steps: - uses: actions/checkout@v2 with: diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor index 9a467be5ea..2e15685aae 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor From 20a9ef253728cffad3d6e524b51e56c0150b08db Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 10:16:27 +0100 Subject: [PATCH 11/18] Fixed checkstyle --- .../skywalking/testcase/resttemplate/BackController.java | 2 +- .../testcase/resttemplate/ObservationConfiguration.java | 9 ++++++--- .../testcase/resttemplate/ServerConfiguration.java | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java index 7adf11ae00..963c7f389f 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/BackController.java @@ -33,7 +33,7 @@ public class BackController { @GetMapping("/syncback") public String syncBack(@RequestHeader HttpHeaders httpHeaders) { - LOGGER.info("Got following headers " + httpHeaders ); + LOGGER.info("Got following headers " + httpHeaders); return "Hello back"; } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java index 34e15cf54a..e171c41204 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ObservationConfiguration.java @@ -24,6 +24,8 @@ import io.micrometer.observation.ObservationRegistry; import jakarta.annotation.PreDestroy; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry; import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingDefaultTracingHandler; import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingMeterHandler; @@ -34,6 +36,7 @@ @Configuration(proxyBeanMethods = false) class ObservationConfiguration { + private static final Logger LOGGER = LogManager.getLogger(ObservationConfiguration.class); @Bean ObservationRegistry observationRegistry(List> handlers) { @@ -72,13 +75,13 @@ static class MetricsDumper { @PreDestroy void dumpMetrics() { - System.out.println("==== METRICS ===="); + LOGGER.info("==== METRICS ===="); this.meterRegistry.getMeters() - .forEach(meter -> System.out.println( + .forEach(meter -> LOGGER.info( " - Metric type \t[" + meter.getId().getType() + "],\tname [" + meter.getId() .getName() + "],\ttags " + meter.getId() .getTags() + ",\tmeasurements " + meter.measure())); - System.out.println("================="); + LOGGER.info("================="); } } } diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java index 6db042656c..a73bad9565 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/src/main/java/org/apache/skywalking/testcase/resttemplate/ServerConfiguration.java @@ -21,7 +21,6 @@ import io.micrometer.observation.ObservationRegistry; import jakarta.servlet.DispatcherType; import java.util.Arrays; -import java.util.Collections; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; From 0156eaaad088ca8be4982606552f4b23212c6ba8 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 10:18:02 +0100 Subject: [PATCH 12/18] Changed the link to micrometer - the other one is failing due to having 30x status code --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 8a55816f1e..ae40dbde4c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,7 @@ Release Notes. * Report the agent version to OAP as an instance attribute * Polish jedis-4.x-plugin to change command to lowercase, which is consistent with jedis-2.x-3.x-plugin * Add micronauthttpclient,micronauthttpserver,memcached,ehcache,guavacache,jedis,redisson plugin config properties to agent.config -* Add [Micrometer Observation](https://micrometer.io/docs/observation) support +* Add [Micrometer Observation](https://github.com/micrometer-metrics/micrometer/) support #### Documentation From 07834e3426c92d812a0d6876769b31c7b29150f8 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 10:35:49 +0100 Subject: [PATCH 13/18] Excluded resttemplate 6.x from CI --- .github/workflows/plugins-jdk17-test.0.yaml | 3 ++- .../scenarios/resttemplate-6.x-scenario/pom.xml | 13 ------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/plugins-jdk17-test.0.yaml b/.github/workflows/plugins-jdk17-test.0.yaml index ddd07cfa3e..d496c158ab 100644 --- a/.github/workflows/plugins-jdk17-test.0.yaml +++ b/.github/workflows/plugins-jdk17-test.0.yaml @@ -59,7 +59,8 @@ jobs: matrix: case: - jdk17-with-gson-scenario - - resttemplate-6.x-scenario +# TODO: We can't test it just yet, because it requires a Skywalking release +# - resttemplate-6.x-scenario steps: - uses: actions/checkout@v2 with: diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml index 15945dd118..068108a168 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -56,19 +56,6 @@ apm-toolkit-micrometer-registry ${sw.version} - - - org.apache.skywalking - apm-micrometer-1.10.x-plugin - ${sw.version} - runtime - - - org.apache.skywalking - apm-agent-core - ${sw.version} - runtime - org.springframework spring-webmvc From dde1a24631ac1def09fc7b970f5e3967a8796905 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 10:55:58 +0100 Subject: [PATCH 14/18] Added docs --- .../Application-toolkit-micrometer.md | 35 +++++++++++++++++++ .../java-agent/advanced-features.md | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md index 63e49cafaf..b87f5d7091 100644 --- a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md +++ b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md @@ -1,3 +1,5 @@ +# Metrics + * Dependency the toolkit, such as using maven or gradle ```xml @@ -53,3 +55,36 @@ compositeRegistry.add(new SkywalkingMeterRegistry()); |Micrometer data type|Data type| |----- |----- | |LongTaskTimer|Histogram| + +# Observations + +* Dependency the toolkit, such as using maven or gradle +```xml + + org.apache.skywalking + apm-toolkit-micrometer-registry + ${skywalking.version} + +``` + +* To use the [Micrometer Observation](https://micrometer.io/docs/observation) Registry with Skywalking, you need to add handlers to the registry. Skywalking comes +with dedicated `SkywalkingMeterHandler` (for metrics) and `SkywalkingSenderTracingHandler`, `SkywalkingReceiverTracingHandler` +`SkywalkingDefaultTracingHandler` (for traces). + +```java +// Here we create the Observation Registry with attached handlers +ObservationRegistry registry = ObservationRegistry.create(); +// Here we add a meter handler +registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( + new SkywalkingMeterHandler(new SkywalkingMeterRegistry()) +); +// Here we add tracing handlers +registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( + new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), + new SkywalkingDefaultTracingHandler() + )); +``` + +With such setup metrics and traces will be created for any Micrometer Observation based instrumentations. diff --git a/docs/en/setup/service-agent/java-agent/advanced-features.md b/docs/en/setup/service-agent/java-agent/advanced-features.md index 518bf51163..96302df680 100644 --- a/docs/en/setup/service-agent/java-agent/advanced-features.md +++ b/docs/en/setup/service-agent/java-agent/advanced-features.md @@ -7,7 +7,7 @@ * If you want your codes to interact with SkyWalking agent, including `getting trace id`, `setting tags`, `propagating custom data` etc.. Try [SkyWalking manual APIs](Application-toolkit-trace.md). * If you require customized metrics, try [SkyWalking Meter System Toolkit](Application-toolkit-meter.md). * If you want to continue traces across thread manually, use [across thread solution APIs](Application-toolkit-trace-cross-thread.md). - * If you want to forward MicroMeter/Spring Sleuth metrics to Meter System, use [SkyWalking MicroMeter Register](Application-toolkit-micrometer.md). + * If you want to forward Micrometer metrics / observations, use [SkyWalking Micrometer Register](Application-toolkit-micrometer.md). * If you want to use OpenTracing Java APIs, try [SkyWalking OpenTracing compatible tracer](Opentracing.md). More details you could find at http://opentracing.io * If you want to tolerate some exceptions, read [tolerate custom exception doc](How-to-tolerate-exceptions.md). * If you want to print trace context(e.g. traceId) in your logs, or collect logs, choose the log frameworks, [log4j](Application-toolkit-log4j-1.x.md), [log4j2](Application-toolkit-log4j-2.x.md), [logback](Application-toolkit-logback-1.x.md). From 336a98738833cdd190498a66e05746c6d8055395 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 12:01:48 +0100 Subject: [PATCH 15/18] Update Application-toolkit-micrometer.md --- .../service-agent/java-agent/Application-toolkit-micrometer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md index b87f5d7091..149375e299 100644 --- a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md +++ b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md @@ -67,7 +67,7 @@ compositeRegistry.add(new SkywalkingMeterRegistry()); ``` -* To use the [Micrometer Observation](https://micrometer.io/docs/observation) Registry with Skywalking, you need to add handlers to the registry. Skywalking comes +* To use the Micrometer Observation Registry with Skywalking, you need to add handlers to the registry. Skywalking comes with dedicated `SkywalkingMeterHandler` (for metrics) and `SkywalkingSenderTracingHandler`, `SkywalkingReceiverTracingHandler` `SkywalkingDefaultTracingHandler` (for traces). From 297210b5f074125f088fb6c5af80a123d7326455 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sat, 3 Dec 2022 13:37:35 +0100 Subject: [PATCH 16/18] Moved micrometer-1.10.x-plugin to apm-toolkit-activation --- apm-sniffer/apm-sdk-plugin/pom.xml | 1 - .../pom.xml | 6 +-- ...gerThreadLocalAccessorInstrumentation.java | 2 +- ...napshotThreadLocalAccessorInterceptor.java | 2 +- ...rDefaultTracingHandlerInstrumentation.java | 2 +- ...meterDefaultTracingHandlerInterceptor.java | 2 +- ...ReceiverTracingHandlerInstrumentation.java | 2 +- ...eterReceiverTracingHandlerInterceptor.java | 2 +- ...erSenderTracingHandlerInstrumentation.java | 2 +- ...ometerSenderTracingHandlerInterceptor.java | 2 +- .../activation}/micrometer/SpanHelper.java | 2 +- .../activation}/micrometer/TaggingHelper.java | 2 +- .../src/main/resources/skywalking-plugin.def | 8 ++-- .../micrometer/AbstractTracingSpanHelper.java | 0 .../ContextManagerExtendOverrideService.java | 0 ...hotThreadLocalAccessorInterceptorTest.java | 1 + ...rDefaultTracingHandlerInterceptorTest.java | 1 + ...ReceiverTracingHandlerInterceptorTest.java | 1 + ...erSenderTracingHandlerInterceptorTest.java | 1 + .../plugin/micrometer/PluginBootService.java | 0 ...skywalking.apm.agent.core.boot.BootService | 0 .../pom.xml | 38 ------------------- apm-sniffer/apm-toolkit-activation/pom.xml | 1 + 23 files changed, 22 insertions(+), 56 deletions(-) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/pom.xml (91%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java (97%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java (97%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerDefaultTracingHandlerInterceptor.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java (97%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerReceiverTracingHandlerInterceptor.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerSenderTracingHandlerInstrumentation.java (97%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/MicrometerSenderTracingHandlerInterceptor.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/SpanHelper.java (96%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation}/micrometer/TaggingHelper.java (96%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/main/resources/skywalking-plugin.def (61%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java (100%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java (100%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java (98%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java (100%) rename apm-sniffer/{apm-sdk-plugin/micrometer-1.10.x-plugin => apm-toolkit-activation/apm-toolkit-micrometer-activation}/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService (100%) delete mode 100644 apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index e9380a3a88..9105865094 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -126,7 +126,6 @@ nats-2.14.x-2.15.x-plugin jedis-plugins impala-jdbc-2.6.x-plugin - micrometer-1.10.x-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml similarity index 91% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml index 7666431b9a..da4d3fc8cc 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/pom.xml +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml @@ -18,16 +18,16 @@ - apm-sdk-plugin + apm-toolkit-activation org.apache.skywalking 8.14.0-SNAPSHOT 4.0.0 - apm-micrometer-1.10.x-plugin + apm-toolkit-micrometer-activation jar - apm-micrometer-1.10.x-plugin + apm-toolkit-micrometer-activation http://maven.apache.org diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java index a73c9f4dd0..ab5a22d6af 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java index 2b2a076ef9..57ae92701c 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java index a7ea50f133..fbc78608b6 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptor.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptor.java index 96f1657167..006c8002e4 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java index 8f29334bee..2bb5242dbb 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptor.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptor.java index 3825584102..4f9ebafebd 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.ReceiverContext; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java index 8b0f6986a2..61632167e6 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptor.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptor.java index 00f948cf3c..1aeee1eeea 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import io.micrometer.observation.transport.SenderContext; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/SpanHelper.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/SpanHelper.java index 7da3843f0b..f98fe3d82a 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/SpanHelper.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/SpanHelper.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/TaggingHelper.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/TaggingHelper.java index 974b476468..306be5201d 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/micrometer/TaggingHelper.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/TaggingHelper.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/resources/skywalking-plugin.def similarity index 61% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/resources/skywalking-plugin.def index 3ca7e2e410..4554becc22 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/resources/skywalking-plugin.def @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerContextManagerThreadLocalAccessorInstrumentation -micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInstrumentation -micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInstrumentation -micrometer-1.10.x=org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerContextManagerThreadLocalAccessorInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerDefaultTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerSenderTracingHandlerInstrumentation +micrometer-1.10.x=org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerReceiverTracingHandlerInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java index bac2365716..beb94cea6a 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java @@ -35,6 +35,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerContextSnapshotThreadLocalAccessorInterceptor; import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; import org.junit.After; import org.junit.AfterClass; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java index 7a34d0b4ff..15dd1e5c53 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java @@ -36,6 +36,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerDefaultTracingHandlerInterceptor; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java index e85754aebc..d3c535d6e5 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java @@ -39,6 +39,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerReceiverTracingHandlerInterceptor; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java index d88f740837..7d2b6dab11 100644 --- a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java @@ -40,6 +40,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerSenderTracingHandlerInterceptor; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java diff --git a/apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService similarity index 100% rename from apm-sniffer/apm-sdk-plugin/micrometer-1.10.x-plugin/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml deleted file mode 100644 index 7bb9d881ef..0000000000 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-observation-activation/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - apm-toolkit-activation - org.apache.skywalking - 8.14.0-SNAPSHOT - - 4.0.0 - - apm-toolkit-micrometer-observation-activation - - - - org.apache.skywalking - apm-toolkit-micrometer-registry - ${project.version} - provided - - - diff --git a/apm-sniffer/apm-toolkit-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/pom.xml index ee30825677..d89eb12f78 100644 --- a/apm-sniffer/apm-toolkit-activation/pom.xml +++ b/apm-sniffer/apm-toolkit-activation/pom.xml @@ -33,6 +33,7 @@ apm-toolkit-opentracing-activation apm-toolkit-trace-activation apm-toolkit-meter-activation + apm-toolkit-micrometer-activation apm-toolkit-webflux-activation apm-toolkit-logging-common From 972e2ba7b52bf461bd6d19d14feb72cd4feff538 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 5 Dec 2022 07:38:46 +0100 Subject: [PATCH 17/18] Moved micrometer observation to a separate module --- .../apm-toolkit-micrometer-1.10/pom.xml | 65 +++++++++++++++++++ ...ingContextSnapshotThreadLocalAccessor.java | 0 .../SkywalkingDefaultTracingHandler.java | 0 .../observation/SkywalkingMeterHandler.java | 0 .../SkywalkingReceiverTracingHandler.java | 0 .../SkywalkingSenderTracingHandler.java | 0 .../io.micrometer.context.ThreadLocalAccessor | 0 .../SkywalkingMeterHandlerTests.java | 0 .../apm-toolkit-micrometer-registry/pom.xml | 19 +----- apm-application-toolkit/pom.xml | 1 + .../apm-toolkit-micrometer-activation/pom.xml | 2 +- ...gerThreadLocalAccessorInstrumentation.java | 2 +- ...napshotThreadLocalAccessorInterceptor.java | 7 +- ...rDefaultTracingHandlerInstrumentation.java | 2 +- ...ReceiverTracingHandlerInstrumentation.java | 2 +- ...erSenderTracingHandlerInstrumentation.java | 2 +- .../micrometer/AbstractTracingSpanHelper.java | 2 +- .../ContextManagerExtendOverrideService.java | 2 +- ...hotThreadLocalAccessorInterceptorTest.java | 3 +- ...rDefaultTracingHandlerInterceptorTest.java | 3 +- ...ReceiverTracingHandlerInterceptorTest.java | 3 +- ...erSenderTracingHandlerInterceptorTest.java | 3 +- .../micrometer/PluginBootService.java | 2 +- ...skywalking.apm.agent.core.boot.BootService | 4 +- .../Application-toolkit-micrometer-1.10.md | 32 +++++++++ .../Application-toolkit-micrometer.md | 33 ---------- docs/menu.yml | 4 +- pom.xml | 1 + .../resttemplate-6.x-scenario/pom.xml | 2 +- 29 files changed, 122 insertions(+), 74 deletions(-) create mode 100644 apm-application-toolkit/apm-toolkit-micrometer-1.10/pom.xml rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor (100%) rename apm-application-toolkit/{apm-toolkit-micrometer-registry => apm-toolkit-micrometer-1.10}/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java (100%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/AbstractTracingSpanHelper.java (96%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/ContextManagerExtendOverrideService.java (94%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java (97%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java (97%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java (97%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java (97%) rename apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/{plugin => toolkit/activation}/micrometer/PluginBootService.java (94%) create mode 100644 docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer-1.10.md diff --git a/apm-application-toolkit/apm-toolkit-micrometer-1.10/pom.xml b/apm-application-toolkit/apm-toolkit-micrometer-1.10/pom.xml new file mode 100644 index 0000000000..2fea532c5c --- /dev/null +++ b/apm-application-toolkit/apm-toolkit-micrometer-1.10/pom.xml @@ -0,0 +1,65 @@ + + + + + apm-application-toolkit + org.apache.skywalking + 8.14.0-SNAPSHOT + + 4.0.0 + + apm-toolkit-micrometer-1.10 + jar + + http://maven.apache.org + + + 1.10.2 + 1.0.0 + + + + + org.apache.skywalking + apm-toolkit-micrometer-registry + ${project.version} + + + io.micrometer + micrometer-observation + ${micrometer-core.version} + + + io.micrometer + micrometer-core + ${micrometer-core.version} + + + io.micrometer + context-propagation + ${context-propagation.version} + + + io.micrometer + micrometer-test + ${micrometer-core.version} + test + + + diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingContextSnapshotThreadLocalAccessor.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingDefaultTracingHandler.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandler.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingReceiverTracingHandler.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingSenderTracingHandler.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java similarity index 100% rename from apm-application-toolkit/apm-toolkit-micrometer-registry/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java rename to apm-application-toolkit/apm-toolkit-micrometer-1.10/src/test/java/org/apache/skywalking/apm/toolkit/micrometer/observation/SkywalkingMeterHandlerTests.java diff --git a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml index 9c6f40129f..29d8220a38 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml +++ b/apm-application-toolkit/apm-toolkit-micrometer-registry/pom.xml @@ -30,8 +30,7 @@ http://maven.apache.org - 1.10.2 - 1.0.0 + 1.5.0 @@ -40,26 +39,10 @@ apm-toolkit-meter ${project.version} - - io.micrometer - micrometer-observation - ${micrometer-core.version} - io.micrometer micrometer-core ${micrometer-core.version} - - io.micrometer - context-propagation - ${context-propagation.version} - - - io.micrometer - micrometer-test - ${micrometer-core.version} - test - diff --git a/apm-application-toolkit/pom.xml b/apm-application-toolkit/pom.xml index 19314a30b9..8d2baea6d0 100644 --- a/apm-application-toolkit/pom.xml +++ b/apm-application-toolkit/pom.xml @@ -34,6 +34,7 @@ apm-toolkit-trace apm-toolkit-meter apm-toolkit-micrometer-registry + apm-toolkit-micrometer-1.10 apm-toolkit-kafka apm-toolkit-webflux diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml index da4d3fc8cc..6b850e7748 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/pom.xml @@ -38,7 +38,7 @@ org.apache.skywalking - apm-toolkit-micrometer-registry + apm-toolkit-micrometer-1.10 ${project.version} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java index ab5a22d6af..25157cca8d 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextManagerThreadLocalAccessorInstrumentation.java @@ -37,7 +37,7 @@ public class MicrometerContextManagerThreadLocalAccessorInstrumentation extends public static final String INTERCEPT_SET_VALUE_POINT_METHOD = "setValue"; public static final String INTERCEPT_RESET_POINT_METHOD = "reset"; - public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerContextSnapshotThreadLocalAccessorInterceptor"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerContextSnapshotThreadLocalAccessorInterceptor"; @Override protected ClassMatch enhanceClass() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java index 57ae92701c..8ea6e33db8 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptor.java @@ -48,12 +48,13 @@ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allA return ContextManager.capture(); } else if ("setValue".equals(methodName)) { ContextSnapshot context = (ContextSnapshot) allArguments[0]; - // TODO: I want to continue an existing span, what should be the name? - AbstractSpan span = ContextManager.createLocalSpan("continued"); + AbstractSpan span = ContextManager.createLocalSpan("Thread"); span.setComponent(ComponentsDefine.MICROMETER); ContextManager.continued(context); } else if ("reset".equals(methodName)) { - // TODO: Can't do much about resetting + if (ContextManager.isActive()) { + ContextManager.stopSpan(); + } } return ret; } diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java index fbc78608b6..2e32418eed 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInstrumentation.java @@ -40,7 +40,7 @@ public class MicrometerDefaultTracingHandlerInstrumentation extends ClassInstanc public static final String INTERCEPT_EVENT_POINT_METHOD = "onEvent"; - public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerDefaultTracingHandlerInterceptor"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerDefaultTracingHandlerInterceptor"; @Override protected ClassMatch enhanceClass() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java index 2bb5242dbb..573356e160 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInstrumentation.java @@ -38,7 +38,7 @@ public class MicrometerReceiverTracingHandlerInstrumentation extends ClassInstan public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; - public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerReceiverTracingHandlerInterceptor"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerReceiverTracingHandlerInterceptor"; @Override protected ClassMatch enhanceClass() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java index 61632167e6..d528f1e2b7 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInstrumentation.java @@ -38,7 +38,7 @@ public class MicrometerSenderTracingHandlerInstrumentation extends ClassInstance public static final String INTERCEPT_STOP_POINT_METHOD = "onStop"; - public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.micrometer.MicrometerSenderTracingHandlerInterceptor"; + public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerSenderTracingHandlerInterceptor"; @Override protected ClassMatch enhanceClass() { diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/AbstractTracingSpanHelper.java similarity index 96% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/AbstractTracingSpanHelper.java index 0494d96fa8..8e87305e74 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/AbstractTracingSpanHelper.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/AbstractTracingSpanHelper.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import java.util.Collections; import java.util.List; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/ContextManagerExtendOverrideService.java similarity index 94% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/ContextManagerExtendOverrideService.java index 9b462b361b..ee08457247 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/ContextManagerExtendOverrideService.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/ContextManagerExtendOverrideService.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import org.apache.skywalking.apm.agent.core.boot.OverrideImplementor; import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java similarity index 97% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java index beb94cea6a..3e3f66c844 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerContextSnapshotThreadLocalAccessorInterceptorTest.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import java.lang.reflect.Method; import java.util.List; @@ -35,7 +35,6 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerContextSnapshotThreadLocalAccessorInterceptor; import org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor; import org.junit.After; import org.junit.AfterClass; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java similarity index 97% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java index 15dd1e5c53..9fc3f6bf58 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerDefaultTracingHandlerInterceptorTest.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -36,7 +36,6 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerDefaultTracingHandlerInterceptor; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java similarity index 97% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java index d3c535d6e5..440e632f8d 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerReceiverTracingHandlerInterceptorTest.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -39,7 +39,6 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerReceiverTracingHandlerInterceptor; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java similarity index 97% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java index 7d2b6dab11..7acfed95b9 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/MicrometerSenderTracingHandlerInterceptorTest.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; @@ -40,7 +40,6 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.toolkit.activation.micrometer.MicrometerSenderTracingHandlerInterceptor; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/PluginBootService.java similarity index 94% rename from apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java rename to apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/PluginBootService.java index 47cb9824ce..48d8a4bbb4 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/plugin/micrometer/PluginBootService.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/java/org/apache/skywalking/apm/toolkit/activation/micrometer/PluginBootService.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.micrometer; +package org.apache.skywalking.apm.toolkit.activation.micrometer; import org.apache.skywalking.apm.agent.core.boot.BootService; diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService index 1c26780b61..65298a217f 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-micrometer-activation/src/test/resources/META-INF/services/org.apache.skywalking.apm.agent.core.boot.BootService @@ -16,5 +16,5 @@ # # -org.apache.skywalking.apm.plugin.micrometer.PluginBootService -org.apache.skywalking.apm.plugin.micrometer.ContextManagerExtendOverrideService +org.apache.skywalking.apm.toolkit.activation.micrometer.PluginBootService +org.apache.skywalking.apm.toolkit.activation.micrometer.ContextManagerExtendOverrideService diff --git a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer-1.10.md b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer-1.10.md new file mode 100644 index 0000000000..840cbb5db9 --- /dev/null +++ b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer-1.10.md @@ -0,0 +1,32 @@ +# Observations + +* Dependency the toolkit, such as using maven or gradle +```xml + + org.apache.skywalking + apm-toolkit-micrometer-1.10 + ${skywalking.version} + +``` + +* To use the Micrometer Observation Registry with Skywalking, you need to add handlers to the registry. Skywalking comes +with dedicated `SkywalkingMeterHandler` (for metrics) and `SkywalkingSenderTracingHandler`, `SkywalkingReceiverTracingHandler` +`SkywalkingDefaultTracingHandler` (for traces). + +```java +// Here we create the Observation Registry with attached handlers +ObservationRegistry registry = ObservationRegistry.create(); +// Here we add a meter handler +registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( + new SkywalkingMeterHandler(new SkywalkingMeterRegistry()) +); +// Here we add tracing handlers +registry.observationConfig() + .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( + new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), + new SkywalkingDefaultTracingHandler() + )); +``` + +With such setup metrics and traces will be created for any Micrometer Observation based instrumentations. diff --git a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md index 149375e299..06de225d6a 100644 --- a/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md +++ b/docs/en/setup/service-agent/java-agent/Application-toolkit-micrometer.md @@ -55,36 +55,3 @@ compositeRegistry.add(new SkywalkingMeterRegistry()); |Micrometer data type|Data type| |----- |----- | |LongTaskTimer|Histogram| - -# Observations - -* Dependency the toolkit, such as using maven or gradle -```xml - - org.apache.skywalking - apm-toolkit-micrometer-registry - ${skywalking.version} - -``` - -* To use the Micrometer Observation Registry with Skywalking, you need to add handlers to the registry. Skywalking comes -with dedicated `SkywalkingMeterHandler` (for metrics) and `SkywalkingSenderTracingHandler`, `SkywalkingReceiverTracingHandler` -`SkywalkingDefaultTracingHandler` (for traces). - -```java -// Here we create the Observation Registry with attached handlers -ObservationRegistry registry = ObservationRegistry.create(); -// Here we add a meter handler -registry.observationConfig() - .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( - new SkywalkingMeterHandler(new SkywalkingMeterRegistry()) -); -// Here we add tracing handlers -registry.observationConfig() - .observationHandler(new ObservationHandler.FirstMatchingCompositeObservationHandler( - new SkywalkingSenderTracingHandler(), new SkywalkingReceiverTracingHandler(), - new SkywalkingDefaultTracingHandler() - )); -``` - -With such setup metrics and traces will be created for any Micrometer Observation based instrumentations. diff --git a/docs/menu.yml b/docs/menu.yml index 13ca93a3b5..3ee510f3a7 100644 --- a/docs/menu.yml +++ b/docs/menu.yml @@ -44,8 +44,10 @@ catalog: path: "/en/setup/service-agent/java-agent/application-toolkit-meter" - name: "Across Thread Solution" path: "/en/setup/service-agent/java-agent/application-toolkit-trace-cross-thread" - - name: "MicroMeter Registry" + - name: "Micrometer Registry" path: "/en/setup/service-agent/java-agent/application-toolkit-micrometer" + - name: "Micrometer 1.10 Observation" + path: "/en/setup/service-agent/java-agent/application-toolkit-micrometer-1.10" - name: "Webflux Tracing Assistant APIs" path: "/en/setup/service-agent/java-agent/application-toolkit-webflux" - name: "Kafka Tracing Assistant APIs" diff --git a/pom.xml b/pom.xml index c58790f429..1e64fc68c9 100755 --- a/pom.xml +++ b/pom.xml @@ -391,6 +391,7 @@ ${project.build.sourceDirectory} ${project.build.testSourceDirectory} +scenarios/resttemplate-6.x-scenario **/*.properties, diff --git a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml index 068108a168..93eeeb38f6 100644 --- a/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml +++ b/test/plugin/scenarios/resttemplate-6.x-scenario/pom.xml @@ -53,7 +53,7 @@ org.apache.skywalking - apm-toolkit-micrometer-registry + apm-toolkit-micrometer-1.10 ${sw.version} From 0539ebef79fb6d07b594a84148a4262a977c7f57 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 5 Dec 2022 12:06:06 +0100 Subject: [PATCH 18/18] Update io.micrometer.context.ThreadLocalAccessor --- .../META-INF/services/io.micrometer.context.ThreadLocalAccessor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor index 2e15685aae..94b4d89dd0 100644 --- a/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor +++ b/apm-application-toolkit/apm-toolkit-micrometer-1.10/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -org.apache.skywalking.apm.meter.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor +org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor