From a69704071101fa9e136366550f25378d65741c78 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Fri, 27 Sep 2024 10:57:16 -0400 Subject: [PATCH] NH-91749: use the new extended span processor to leverage mutating span before it's ended. refactor the test because some stuff don't make sense anymore. --- .github/workflows/push.yml | 10 ++++ custom/lambda/build.gradle | 1 + .../InboundMeasurementMetricsGenerator.java | 18 ++++++- .../extensions/LambdaAgentListener.java | 9 ---- .../extensions/TransactionNameManager.java | 50 +++++-------------- smoke-tests/k6/basic.js | 3 +- .../test/java/com/solarwinds/LambdaTest.java | 48 +++++++++++------- .../test/java/com/solarwinds/SmokeTest.java | 8 +-- .../solarwinds/containers/K6Container.java | 5 +- .../containers/PetClinicRestContainer.java | 9 +--- .../containers/SpringBootWebMvcContainer.java | 32 ++++++++++-- .../com/solarwinds/util/NamingConvention.java | 18 ------- solarwinds-otel-sdk/build.gradle | 2 - .../com/solarwinds/api/ext/Transaction.java | 19 +------ 14 files changed, 106 insertions(+), 126 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index aac6478f..24844c89 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -207,6 +207,16 @@ jobs: cd smoke-tests ./gradlew build -x test + - name: Build webmvc jar + run: | + cd smoke-tests + ./gradlew :spring-boot-webmvc:build + + - name: Build webmvc image + run: | + cd smoke-tests/spring-boot-webmvc + docker image build --tag smt:webmvc . + - name: Docker login run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin diff --git a/custom/lambda/build.gradle b/custom/lambda/build.gradle index 9042fcd4..805e639a 100644 --- a/custom/lambda/build.gradle +++ b/custom/lambda/build.gradle @@ -34,6 +34,7 @@ dependencies { compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagent}") compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}") + compileOnly project(path: ":bootstrap") testImplementation project(path: ":custom:shared") testImplementation "org.json:json:${versions.json}" diff --git a/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGenerator.java b/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGenerator.java index 03720a4c..ca1a878b 100644 --- a/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGenerator.java +++ b/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGenerator.java @@ -31,11 +31,11 @@ import io.opentelemetry.context.Context; import io.opentelemetry.sdk.trace.ReadWriteSpan; import io.opentelemetry.sdk.trace.ReadableSpan; -import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.internal.ExtendedSpanProcessor; import io.opentelemetry.semconv.SemanticAttributes; -public class InboundMeasurementMetricsGenerator implements SpanProcessor { +public class InboundMeasurementMetricsGenerator implements ExtendedSpanProcessor { private LongHistogram responseTime; private static final Logger logger = LoggerFactory.getLogger(); @@ -109,4 +109,18 @@ public void onEnd(ReadableSpan span) { public boolean isEndRequired() { return true; } + + @Override + public void onEnding(ReadWriteSpan span) { + SpanData spanData = span.toSpanData(); + final SpanContext parentSpanContext = spanData.getParentSpanContext(); + if (!parentSpanContext.isValid() || parentSpanContext.isRemote()) { + span.setAttribute(TRANSACTION_NAME_KEY, TransactionNameManager.getTransactionName(spanData)); + } + } + + @Override + public boolean isOnEndingRequired() { + return true; + } } diff --git a/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaAgentListener.java b/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaAgentListener.java index c47dacfb..0395f9fa 100644 --- a/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaAgentListener.java +++ b/custom/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaAgentListener.java @@ -23,7 +23,6 @@ import com.solarwinds.joboe.logging.Logger; import com.solarwinds.joboe.logging.LoggerFactory; import com.solarwinds.joboe.sampling.SettingsManager; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.javaagent.extension.AgentListener; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import io.opentelemetry.sdk.trace.samplers.Sampler; @@ -42,14 +41,6 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk openTelemetrySdk) { SettingsManager.initialize( new AwsLambdaSettingsFetcher(new FileSettingsReader("/tmp/solarwinds-apm-settings.json")), SamplingConfigProvider.getSamplingConfiguration()); - - TransactionNameManager.setRuntimeNameGenerator( - spanData -> - new TransactionNameManager.TransactionNameResult( - spanData - .getAttributes() - .get(AttributeKey.stringKey(SharedNames.TRANSACTION_NAME_KEY)), - true)); logger.info("Successfully submitted SolarwindsAPM OpenTelemetry extensions settings"); } else { logger.info("SolarwindsAPM OpenTelemetry extensions is disabled"); diff --git a/custom/shared/src/main/java/com/solarwinds/opentelemetry/extensions/TransactionNameManager.java b/custom/shared/src/main/java/com/solarwinds/opentelemetry/extensions/TransactionNameManager.java index c19e1dc1..91c083c0 100644 --- a/custom/shared/src/main/java/com/solarwinds/opentelemetry/extensions/TransactionNameManager.java +++ b/custom/shared/src/main/java/com/solarwinds/opentelemetry/extensions/TransactionNameManager.java @@ -36,10 +36,6 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.Value; public class TransactionNameManager { private static final Logger logger = LoggerFactory.getLogger(); @@ -64,11 +60,6 @@ public class TransactionNameManager { private static NamingScheme namingScheme = new DefaultNamingScheme(null); - @Getter @Setter - private static RuntimeNameGenerator runtimeNameGenerator = - (SpanData spanData) -> - new TransactionNameResult(CustomTransactionNameDict.get(spanData.getTraceId()), false); - static { customTransactionNamePattern = getTransactionNamePattern(); addNameCountChangeListener(); @@ -128,12 +119,7 @@ static String[] parseTransactionNamePattern(String pattern) { * @return transaction name */ public static String getTransactionName(SpanData spanData) { - TransactionNameResult transactionNameResult = buildTransactionName(spanData); - String transactionName = transactionNameResult.name; - - if (transactionNameResult.isLambda()) { - return transactionName; - } + String transactionName = buildTransactionName(spanData); if (transactionName != null) { Boolean domainPrefixedTransactionName = @@ -203,19 +189,19 @@ static String transformTransactionName(String inputTransactionName) { return transactionName; } - static TransactionNameResult buildTransactionName(SpanData spanData) { + static String buildTransactionName(SpanData spanData) { Attributes spanAttributes = spanData.getAttributes(); - TransactionNameResult transactionNameResult = runtimeNameGenerator.generateName(spanData); + String custName = CustomTransactionNameDict.get(spanData.getTraceId()); - if (transactionNameResult.name != null) { - logger.trace(String.format("Using custom transaction name -> %s", transactionNameResult)); - return transactionNameResult; + if (custName != null) { + logger.trace(String.format("Using custom transaction name -> %s", custName)); + return custName; } String name = namingScheme.createName(spanAttributes); if (name != null && !name.isEmpty()) { logger.trace(String.format("Using scheme derived transaction name -> %s", name)); - return new TransactionNameResult(name, false); + return name; } // use HandlerName which may be injected by some MVC instrumentations (currently only Spring @@ -223,14 +209,14 @@ static TransactionNameResult buildTransactionName(SpanData spanData) { String handlerName = spanAttributes.get(AttributeKey.stringKey("HandlerName")); if (handlerName != null) { logger.trace(String.format("Using HandlerName(%s) as the transaction name", handlerName)); - return new TransactionNameResult(handlerName, false); + return handlerName; } // use "http.route" String httpRoute = spanAttributes.get(SemanticAttributes.HTTP_ROUTE); if (httpRoute != null) { logger.trace(String.format("Using http.route (%s) as the transaction name", httpRoute)); - return new TransactionNameResult(httpRoute, false); + return httpRoute; } // get transaction name from url @@ -246,7 +232,7 @@ static TransactionNameResult buildTransactionName(SpanData spanData) { String.format( "Using custom configure pattern to extract transaction name: (%s)", transactionName)); - return new TransactionNameResult(transactionName, false); + return transactionName; } } @@ -261,12 +247,12 @@ static TransactionNameResult buildTransactionName(SpanData spanData) { logger.trace( String.format( "Using token name pattern to extract transaction name: (%s)", transactionNameByUrl)); - return new TransactionNameResult(transactionNameByUrl, false); + return transactionNameByUrl; } String spanName = spanData.getName(); logger.trace(String.format("Using span name as the transaction name: (%s)", spanName)); - return new TransactionNameResult(spanName, false); + return spanName; } /** @@ -379,16 +365,4 @@ static void reset() { URL_TRANSACTION_NAME_CACHE.invalidateAll(); maxNameCount = DEFAULT_MAX_NAME_COUNT; } - - @Value - @RequiredArgsConstructor - public static class TransactionNameResult { - String name; - boolean lambda; - } - - @FunctionalInterface - public interface RuntimeNameGenerator { - TransactionNameResult generateName(SpanData spanData); - } } diff --git a/smoke-tests/k6/basic.js b/smoke-tests/k6/basic.js index cdbb34dc..6184c3ab 100644 --- a/smoke-tests/k6/basic.js +++ b/smoke-tests/k6/basic.js @@ -552,6 +552,8 @@ function silence(fn) { } export default function () { + silence(verify_that_span_data_is_persisted_0) + if (`${__ENV.LAMBDA}` === "true") { const request_count = (measurement) => check(measurement, {"request_count": mrs => mrs.value > 0}) const tracecount = (measurement) => check(measurement, {"tracecount": mrs => mrs.value > 0}) @@ -585,7 +587,6 @@ export default function () { }) silence(verify_logs_export) silence(verify_that_specialty_path_is_not_sampled) - silence(verify_that_span_data_is_persisted_0) silence(verify_that_span_data_is_persisted) silence(verify_that_trace_is_persisted) diff --git a/smoke-tests/src/test/java/com/solarwinds/LambdaTest.java b/smoke-tests/src/test/java/com/solarwinds/LambdaTest.java index 1e3fc436..acdfd2b0 100644 --- a/smoke-tests/src/test/java/com/solarwinds/LambdaTest.java +++ b/smoke-tests/src/test/java/com/solarwinds/LambdaTest.java @@ -16,32 +16,32 @@ package com.solarwinds; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import com.solarwinds.agents.Agent; -import com.solarwinds.agents.SwoAgentResolver; import com.solarwinds.agents.SwoLambdaAgentResolver; import com.solarwinds.config.Configs; import com.solarwinds.config.TestConfig; import com.solarwinds.containers.K6Container; import com.solarwinds.containers.PetClinicRestContainer; import com.solarwinds.containers.PostgresContainer; +import com.solarwinds.containers.SpringBootWebMvcContainer; import com.solarwinds.results.ResultsCollector; import com.solarwinds.util.LogStreamAnalyzer; import com.solarwinds.util.NamingConventions; -import java.io.IOException; -import java.nio.file.Files; -import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.containers.output.Slf4jLogConsumer; +import java.io.IOException; +import java.nio.file.Files; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + @EnabledIfEnvironmentVariable(named = "LAMBDA", matches = "true") public class LambdaTest { private static final Network NETWORK = Network.newNetwork(); @@ -64,34 +64,37 @@ static void runTestConfig() { .forEach( agent -> { try { - runAppOnce(config, agent); + runAppOnce(agent); } catch (Exception e) { fail("Unhandled exception in " + config.name(), e); } }); } - static void runAppOnce(TestConfig config, Agent agent) throws Exception { + static void runAppOnce(Agent agent) throws Exception { GenericContainer postgres = new PostgresContainer(NETWORK).build(); postgres.start(); - GenericContainer petClinic = new PetClinicRestContainer(new SwoLambdaAgentResolver(), NETWORK, - agent, namingConventions).build(); + GenericContainer webMvc = new SpringBootWebMvcContainer(new SwoLambdaAgentResolver(), NETWORK, agent).build(); + webMvc.start(); + + GenericContainer petClinic = new PetClinicRestContainer(new SwoLambdaAgentResolver(), NETWORK, agent).build(); petClinic.start(); petClinic.followOutput(logStreamAnalyzer); - GenericContainer k6 = new K6Container(NETWORK, agent, config, namingConventions).build(); + GenericContainer k6 = new K6Container(NETWORK, agent, namingConventions).build(); k6.start(); k6.followOutput(new Slf4jLogConsumer(LoggerFactory.getLogger("k6"))); petClinic.execInContainer("kill", "1"); + webMvc.execInContainer("kill", "1"); postgres.stop(); } @Test void assertThatRequestCountMetricIsReported() throws IOException { String resultJson = new String( - Files.readAllBytes(namingConventions.local.k6Results(Configs.E2E.config.agents().get(0)))); + Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['request_count'].passes"); assertTrue(passes > 1, "Expects a count > 1 "); @@ -100,7 +103,7 @@ void assertThatRequestCountMetricIsReported() throws IOException { @Test void assertThatTraceCountMetricIsReported() throws IOException { String resultJson = new String( - Files.readAllBytes(namingConventions.local.k6Results(Configs.E2E.config.agents().get(0)))); + Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['tracecount'].passes"); assertTrue(passes > 1, "Expects a count > 1 "); @@ -109,7 +112,7 @@ void assertThatTraceCountMetricIsReported() throws IOException { @Test void assertThatSampleCountMetricIsReported() throws IOException { String resultJson = new String( - Files.readAllBytes(namingConventions.local.k6Results(Configs.E2E.config.agents().get(0)))); + Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['samplecount'].passes"); assertTrue(passes > 1, "Expects a count > 1 "); @@ -118,7 +121,7 @@ void assertThatSampleCountMetricIsReported() throws IOException { @Test void assertThatResponseTimeMetricIsReported() throws IOException { String resultJson = new String( - Files.readAllBytes(namingConventions.local.k6Results(Configs.E2E.config.agents().get(0)))); + Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['response_time'].passes"); assertTrue(passes > 1, "Expects a count > 1 "); @@ -127,10 +130,10 @@ void assertThatResponseTimeMetricIsReported() throws IOException { @Test void assertThatCustomTransactionNameTakesEffect() throws IOException { String resultJson = new String( - Files.readAllBytes(namingConventions.local.k6Results(Configs.E2E.config.agents().get(0)))); + Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['transaction-name'].passes"); - assertTrue(passes > 1, "Expects a count > 1 "); + assertTrue(passes > 1, "Environment based transaction naming is broken "); } @Test @@ -144,4 +147,11 @@ void assertThatJDBCInstrumentationIsApplied() { Boolean actual = logStreamAnalyzer.getAnswer().get("Applying instrumentation: sw-jdbc"); assertTrue(actual, "sw-jdbc instrumentation is not applied"); } + + @Test + void assertSDKTransactionNaming() throws IOException { + String resultJson = new String(Files.readAllBytes(namingConventions.local.k6Results(Configs.LAMBDA_E2E.config.agents().get(0)))); + double passes = ResultsCollector.read(resultJson, "$.root_group.checks.['custom transaction name'].passes"); + assertTrue(passes > 1, "SDK transaction naming is broken"); + } } diff --git a/smoke-tests/src/test/java/com/solarwinds/SmokeTest.java b/smoke-tests/src/test/java/com/solarwinds/SmokeTest.java index 0137ebbe..b682767b 100644 --- a/smoke-tests/src/test/java/com/solarwinds/SmokeTest.java +++ b/smoke-tests/src/test/java/com/solarwinds/SmokeTest.java @@ -72,14 +72,14 @@ static void runTestConfig() { .forEach( agent -> { try { - runAppOnce(config, agent); + runAppOnce(agent); } catch (Exception e) { fail("Unhandled exception in " + config.name(), e); } }); } - static void runAppOnce(TestConfig config, Agent agent) throws Exception { + static void runAppOnce(Agent agent) throws Exception { GenericContainer webMvc = new SpringBootWebMvcContainer(new SwoAgentResolver(), NETWORK, agent).build(); webMvc.start(); webMvc.followOutput(logStreamAnalyzer); @@ -91,11 +91,11 @@ static void runAppOnce(TestConfig config, Agent agent) throws Exception { GenericContainer postgres = new PostgresContainer(NETWORK).build(); postgres.start(); - GenericContainer petClinic = new PetClinicRestContainer(new SwoAgentResolver(), NETWORK, agent, namingConventions).build(); + GenericContainer petClinic = new PetClinicRestContainer(new SwoAgentResolver(), NETWORK, agent).build(); petClinic.start(); petClinic.followOutput(logStreamAnalyzer); - GenericContainer k6 = new K6Container(NETWORK, agent, config, namingConventions).build(); + GenericContainer k6 = new K6Container(NETWORK, agent, namingConventions).build(); k6.start(); k6.followOutput(new Slf4jLogConsumer(LoggerFactory.getLogger("k6")), OutputFrame.OutputType.STDOUT); diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/K6Container.java b/smoke-tests/src/test/java/com/solarwinds/containers/K6Container.java index a029f99a..c7ae4e51 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/K6Container.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/K6Container.java @@ -17,7 +17,6 @@ package com.solarwinds.containers; import com.solarwinds.agents.Agent; -import com.solarwinds.config.TestConfig; import com.solarwinds.util.NamingConventions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,14 +34,12 @@ public class K6Container { private static final Logger logger = LoggerFactory.getLogger(K6Container.class); private final Network network; private final Agent agent; - private final TestConfig config; private final NamingConventions namingConventions; public K6Container( - Network network, Agent agent, TestConfig config, NamingConventions namingConvention) { + Network network, Agent agent, NamingConventions namingConvention) { this.network = network; this.agent = agent; - this.config = config; this.namingConventions = namingConvention; } diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java b/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java index 54cb9660..5f0b635b 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java @@ -18,7 +18,7 @@ import com.solarwinds.agents.Agent; import com.solarwinds.agents.AgentResolver; -import com.solarwinds.util.NamingConventions; + import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; @@ -42,14 +42,12 @@ public class PetClinicRestContainer implements Container { private final Network network; private final Agent agent; - private final NamingConventions namingConventions; - public PetClinicRestContainer(AgentResolver agentResolver, Network network, Agent agent, NamingConventions namingConventions) { + public PetClinicRestContainer(AgentResolver agentResolver, Network network, Agent agent) { this.agentResolver = agentResolver; this.network = network; this.agent = agent; - this.namingConventions = namingConventions; } public GenericContainer build() { @@ -62,8 +60,6 @@ public GenericContainer build() { .withNetworkAliases("petclinic") .withLogConsumer(new Slf4jLogConsumer(logger)) .withExposedPorts(PETCLINIC_PORT) - .withFileSystemBind(namingConventions.localResults(), - namingConventions.containerResults()) .withFileSystemBind("./solarwinds-apm-settings.json", "/tmp/solarwinds-apm-settings.json") .withEnv("OTEL_JAVAAGENT_DEBUG", "true") .withEnv("SW_APM_SQL_TAG", "true") @@ -99,7 +95,6 @@ public GenericContainer build() { .withNetworkAliases("petclinic") .withLogConsumer(new Slf4jLogConsumer(logger)) .withExposedPorts(PETCLINIC_PORT) - .withFileSystemBind(namingConventions.localResults(), namingConventions.containerResults()) .withFileSystemBind("./apm-config.json", "/app/apm-config.json") .withEnv("SW_APM_CONFIG_FILE", "/app/apm-config.json") .withEnv("OTEL_JAVAAGENT_DEBUG", "true") diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java b/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java index ba1e2112..328ecc86 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java @@ -18,7 +18,6 @@ import com.solarwinds.agents.Agent; import com.solarwinds.agents.AgentResolver; -import com.solarwinds.util.NamingConventions; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +32,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class SpringBootWebMvcContainer implements Container { @@ -51,6 +51,28 @@ public SpringBootWebMvcContainer(AgentResolver agentResolver, Network network, A public GenericContainer build() { Path agentPath = agentResolver.resolve(this.agent).orElseThrow(); + if (Objects.equals(System.getenv("LAMBDA"), "true")) { + return new GenericContainer<>(DockerImageName.parse("smt:webmvc")) + .withNetwork(network) + .withNetworkAliases("webmvc") + .withLogConsumer(new Slf4jLogConsumer(logger)) + .withExposedPorts(SERVER_PORT) + .waitingFor(Wait.forHttp("/actuator/health").withReadTimeout(Duration.ofMinutes(5)).forPort(SERVER_PORT)) + .withFileSystemBind("./solarwinds-apm-settings.json", "/tmp/solarwinds-apm-settings.json") + .withEnv("SERVER_PORT", String.format("%d", SERVER_PORT)) + .withEnv("SW_APM_CONFIG_FILE", "/app/apm-config.json") + .withEnv("SW_APM_DEBUG_LEVEL", "trace") + .withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", System.getenv("OTEL_EXPORTER_OTLP_ENDPOINT")) + .withEnv("OTEL_EXPORTER_OTLP_HEADERS", + String.format("authorization=Bearer %s", System.getenv("SW_APM_SERVICE_KEY"))) + .withEnv("OTEL_SERVICE_NAME", "java-apm-smoke-test-webmvc-lambda") + .withStartupTimeout(Duration.ofMinutes(5)) + .withCopyFileToContainer( + MountableFile.forHostPath(agentPath), + "/app/" + agentPath.getFileName()) + .withCommand(buildCommandline(agentPath, true)); + } + return new GenericContainer<>(DockerImageName.parse("smt:webmvc")) .withNetwork(network) .withNetworkAliases("webmvc") @@ -66,14 +88,16 @@ public GenericContainer build() { .withCopyFileToContainer( MountableFile.forHostPath(agentPath), "/app/" + agentPath.getFileName()) - .withCommand(buildCommandline(agentPath)); + .withCommand(buildCommandline(agentPath, false)); } @NotNull - private String[] buildCommandline(Path agentJarPath) { + private String[] buildCommandline(Path agentJarPath, boolean isLambda) { List result = new ArrayList<>(); result.add("java"); - result.add("-Dotel.javaagent.extensions=/app/custom-extensions.jar"); + if (!isLambda) { + result.add("-Dotel.javaagent.extensions=/app/custom-extensions.jar"); + } result.addAll(this.agent.getAdditionalJvmArgs()); result.add("-javaagent:/app/" + agentJarPath.getFileName()); diff --git a/smoke-tests/src/test/java/com/solarwinds/util/NamingConvention.java b/smoke-tests/src/test/java/com/solarwinds/util/NamingConvention.java index 3ab8895c..aae13e02 100644 --- a/smoke-tests/src/test/java/com/solarwinds/util/NamingConvention.java +++ b/smoke-tests/src/test/java/com/solarwinds/util/NamingConvention.java @@ -43,24 +43,6 @@ public Path k6Results(Agent agent) { return Paths.get(dir, "k6_out_" + agent.getName() + ".json"); } - /** - * Returns a path to the location of the jfr output file for a given agent run. - * - * @param agent The agent to get the jfr file path for. - */ - public Path jfrFile(Agent agent) { - return Paths.get(dir, "petclinic-" + agent.getName() + ".jfr"); - } - - /** - * Returns the path to the file that contains the startup duration for a given agent run. - * - * @param agent The agent to get the startup duration for. - */ - public Path startupDurationFile(Agent agent) { - return Paths.get(dir, "startup-time-" + agent.getName() + ".txt"); - } - /** Returns the root path that this naming convention was configured with. */ public String root() { return dir; diff --git a/solarwinds-otel-sdk/build.gradle b/solarwinds-otel-sdk/build.gradle index f87a78f7..6d080949 100644 --- a/solarwinds-otel-sdk/build.gradle +++ b/solarwinds-otel-sdk/build.gradle @@ -36,8 +36,6 @@ dependencies { compileOnly("io.opentelemetry:opentelemetry-context:${versions.opentelemetry}") compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap:${versions.opentelemetryJavaagentAlpha}") - compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagent}") - testImplementation 'org.mockito:mockito-core:5.3.0' testImplementation 'org.mockito:mockito-junit-jupiter:5.3.0' diff --git a/solarwinds-otel-sdk/src/main/java/com/solarwinds/api/ext/Transaction.java b/solarwinds-otel-sdk/src/main/java/com/solarwinds/api/ext/Transaction.java index 52f0e8ee..237785ce 100644 --- a/solarwinds-otel-sdk/src/main/java/com/solarwinds/api/ext/Transaction.java +++ b/solarwinds-otel-sdk/src/main/java/com/solarwinds/api/ext/Transaction.java @@ -20,7 +20,6 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; import java.util.regex.Pattern; /** @@ -48,23 +47,7 @@ static boolean setName(String name) { return false; } - CustomTransactionNameDict.set(spanContext.getTraceId(), transformTransactionName(name)); - LocalRootSpan.fromContext(Context.current()) - .setAttribute("sw.transaction", transformTransactionName(name)); - + CustomTransactionNameDict.set(spanContext.getTraceId(), name); return true; } - - private static String transformTransactionName(String transactionName) { - - if (transactionName.length() > 255) { - transactionName = transactionName.substring(0, 252) + "..."; - } else if (transactionName.isEmpty()) { - transactionName = " "; // ensure that it at least has 1 character - } - - transactionName = REPLACE_PATTERN.matcher(transactionName).replaceAll("_"); - transactionName = transactionName.toLowerCase(); - return transactionName; - } }