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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions .github/workflows/lambda-test.yml

This file was deleted.

4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ allprojects {
}
}
}

tasks.withType<Test> {
finalizedBy(tasks.named("cleanListedDependencies"))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ class JavaagentProvider(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"-XX:+IgnoreUnrecognizedVMOptions",
"-Dotel.javaagent.debug=true"
"-Dotel.javaagent.debug=true",
"-Dio.opentelemetry.context.enableStrictContext=true",
"-Dotel.java.experimental.span-stacktrace.min.duration=0ms",
"-Dsw.apm.profiler.enabled=true",
Comment thread
cleverchuk marked this conversation as resolved.
"-Dsw.apm.profiler.interval=10",
"-Dsw.apm.span.stacktrace.filters=thread.id,os.description,http.request.method"
Comment thread
cleverchuk marked this conversation as resolved.
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ dependencies {
compileOnly("org.springframework:spring-webmvc:3.1.0.RELEASE")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator")

testImplementation("org.springframework:spring-webmvc:5.3.30")
testImplementation("org.springframework:spring-test:5.3.30")
Comment thread
cleverchuk marked this conversation as resolved.
testImplementation("javax.servlet:javax.servlet-api:3.1.0")
}

swoJava {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* Licensed 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 com.solarwinds.opentelemetry.instrumentation.webmvc.v3_1;

import static org.junit.jupiter.api.Assertions.assertEquals;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@ExtendWith(MockitoExtension.class)
class HandlerNameInstrumentationTest {

@RegisterExtension
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create();

@Test
void verifyHandlerNameIsStampedOnServerSpan() {
testing.runWithSpan(
"server",
() -> {
try {
AnnotationConfigWebApplicationContext appContext =
new AnnotationConfigWebApplicationContext();
appContext.register(TestConfig.class);

DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext);
dispatcherServlet.init(new MockServletConfig());

MockHttpServletRequest request = new MockHttpServletRequest("GET", "/greet");
MockHttpServletResponse response = new MockHttpServletResponse();

try {
dispatcherServlet.service(request, response);
} finally {
dispatcherServlet.destroy();
appContext.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("server")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
attributes ->
assertEquals(
"TestController.greet",
attributes.get(AttributeKey.stringKey("HandlerName"))))));
}

@EnableWebMvc
@org.springframework.context.annotation.Configuration
static class TestConfig {
@org.springframework.context.annotation.Bean
public TestController testController() {
return new TestController();
}
}

@RestController
static class TestController {
@GetMapping("/greet")
public String greet() {
return "hello";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ dependencies {
compileOnly("org.springframework:spring-webmvc:6.0.0")
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator")

testImplementation("org.springframework:spring-webmvc:6.0.0")
testImplementation("org.springframework:spring-test:6.0.0")
testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0")
testImplementation("org.apache.tomcat.embed:tomcat-embed-core:10.1.0")
}

swoJava {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* Licensed 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 com.solarwinds.opentelemetry.instrumentation.webmvc.v6_0;

import static org.junit.jupiter.api.Assertions.assertEquals;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@ExtendWith(MockitoExtension.class)
class HandlerNameInstrumentationTest {

@RegisterExtension
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create();

@Test
void verifyHandlerNameIsStampedOnServerSpan() {
testing.runWithSpan(
"server",
() -> {
try {
AnnotationConfigWebApplicationContext appContext =
new AnnotationConfigWebApplicationContext();
appContext.register(TestConfig.class);

DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext);
dispatcherServlet.init(new org.springframework.mock.web.MockServletConfig());

MockHttpServletRequest request = new MockHttpServletRequest("GET", "/greet");
MockHttpServletResponse response = new MockHttpServletResponse();

try {
dispatcherServlet.service(request, response);
} finally {
dispatcherServlet.destroy();
appContext.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("server")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
attributes ->
assertEquals(
"TestController.greet",
attributes.get(AttributeKey.stringKey("HandlerName"))))));
}

@EnableWebMvc
@org.springframework.context.annotation.Configuration
static class TestConfig {
@org.springframework.context.annotation.Bean
public TestController testController() {
return new TestController();
}
}

@RestController
static class TestController {
@GetMapping("/greet")
public String greet() {
return "hello";
}
}
}
Comment thread
cleverchuk marked this conversation as resolved.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ include("libs:core")
include("libs:config")
include("libs:logging")
include("libs:sampling")
include("testing:feature-tests")

Loading
Loading