Skip to content

Commit

Permalink
bug: replace opentelemetry-extension-aws (#2439)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo authored Apr 15, 2024
1 parent 7a8d1c1 commit f2cde30
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,34 @@

@Singleton
public class OpenTelemetryXray extends AbstractOpenTelemetry {

private static final Dependency.Builder OPEN_TELEMETRY_EXTENSION_AWS =
OpenTelemetryDependencyUtils.openTelemetryDependency()
.artifactId("opentelemetry-extension-aws")
.compile();

public static final String NAME = "tracing-opentelemetry-xray";
private static final Dependency.Builder OPEN_TELEMETRY_INSTRUMENTATION_AWS_SDK =
OpenTelemetryDependencyUtils.openTelemetryInstrumentationDependency()
.artifactId("opentelemetry-aws-sdk-2.2")
.compile();

private static final Dependency.Builder OPEN_TELEMETRY_CONTRIB_XRAY = Dependency.builder()
.groupId("io.opentelemetry.contrib")
private static final String GROUP_ID_IO_OPENTELEMETRY_CONTRIB = "io.opentelemetry.contrib";
private static final Dependency OPEN_TELEMETRY_CONTRIB_XRAY = Dependency.builder()
.groupId(GROUP_ID_IO_OPENTELEMETRY_CONTRIB)
.artifactId("opentelemetry-aws-xray")
.compile();

.compile()
.build();
private static final String ARTIFACT_ID_OPENTELEMETRY_AWS_RESOURCES = "opentelemetry-aws-resources";
private static final String ARTIFACT_ID_OPENTELEMETRY_AWS_XRAY_PROPAGATOR = "opentelemetry-aws-xray-propagator";
private static final Dependency OPEN_TELEMETRY_CONTRIB_XRAY_RESOURCES = Dependency.builder()
.groupId(GROUP_ID_IO_OPENTELEMETRY_CONTRIB)
.artifactId(ARTIFACT_ID_OPENTELEMETRY_AWS_RESOURCES)
.compile()
.build();
private static final Dependency OPEN_TELEMETRY_CONTRIB_XRAY_PROPAGATOR = Dependency.builder()
.groupId(GROUP_ID_IO_OPENTELEMETRY_CONTRIB)
.artifactId(ARTIFACT_ID_OPENTELEMETRY_AWS_XRAY_PROPAGATOR)
.version("1.34.0-alpha") //TODO remove once it is managed https://github.com/micronaut-projects/micronaut-tracing/pull/541
.compile()
.build();
private static final Dependency.Builder OPEN_TELEMETRY_BOM_ALPHA = Dependency.builder()
.lookupArtifactId("opentelemetry-instrumentation-bom-alpha")
.compile();

public OpenTelemetryXray(OpenTelemetry otel,
OpenTelemetryHttp otelHttp,
OpenTelemetryAnnotations otelAnnotations,
Expand All @@ -54,7 +62,7 @@ public OpenTelemetryXray(OpenTelemetry otel,
@NonNull
@Override
public String getName() {
return "tracing-opentelemetry-xray";
return NAME;
}

@Override
Expand All @@ -70,8 +78,9 @@ public String getDescription() {

@Override
public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(OPEN_TELEMETRY_EXTENSION_AWS);
generatorContext.addDependency(OPEN_TELEMETRY_CONTRIB_XRAY);
generatorContext.addDependency(OPEN_TELEMETRY_CONTRIB_XRAY_RESOURCES);
generatorContext.addDependency(OPEN_TELEMETRY_CONTRIB_XRAY_PROPAGATOR);
if (generatorContext.getFeatures().isFeaturePresent(AwsV2Sdk.class)) {
generatorContext.addDependency(OPEN_TELEMETRY_BOM_ALPHA);
generatorContext.addDependency(OPEN_TELEMETRY_INSTRUMENTATION_AWS_SDK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import io.micronaut.starter.ApplicationContextSpec
import io.micronaut.starter.BuildBuilder
import io.micronaut.starter.application.ApplicationType
import io.micronaut.starter.application.generator.GeneratorContext
import io.micronaut.starter.build.BuildTestUtil
import io.micronaut.starter.build.BuildTestVerifier
import io.micronaut.starter.feature.Category
import io.micronaut.starter.fixture.CommandOutputFixture
import io.micronaut.starter.options.BuildTool
Expand Down Expand Up @@ -58,7 +60,7 @@ class OpenTelemetryXraySpec extends ApplicationContextSpec implements CommandOut

then:
template.contains('implementation("io.opentelemetry.contrib:opentelemetry-aws-xray")')
template.contains('implementation("io.opentelemetry:opentelemetry-extension-aws")')
!template.contains('implementation("io.opentelemetry:opentelemetry-extension-aws")')

where:
language << Language.values().toList()
Expand All @@ -67,16 +69,20 @@ class OpenTelemetryXraySpec extends ApplicationContextSpec implements CommandOut
@See("https://aws-otel.github.io/docs/getting-started/java-sdk/trace-manual-instr#instrumenting-the-aws-sdk")
void 'test gradle tracing-opentelemetry-xray dynamodb features for language=#language include aws-sdk instrumentation opentelemetry dependency'(Language language) {
when:
String template = new BuildBuilder(beanContext, BuildTool.GRADLE)
BuildTool buildTool = BuildTool.GRADLE
String template = new BuildBuilder(beanContext, buildTool)
.language(language)
.features(['tracing-opentelemetry-xray', 'dynamodb'])
.render()
BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, language, template)

then:
verifier.hasDependency("io.opentelemetry.instrumentation", "opentelemetry-aws-sdk-2.2")
verifier.hasDependency("io.opentelemetry.contrib", "opentelemetry-aws-xray")
verifier.hasDependency("io.opentelemetry.contrib", "opentelemetry-aws-xray-propagator")
verifier.hasDependency("io.opentelemetry.contrib", "opentelemetry-aws-resources")
template.contains('implementation platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.14.0-alpha")')
template.contains('implementation("io.opentelemetry.instrumentation:opentelemetry-aws-sdk-2.2")')
template.contains('implementation("io.opentelemetry.contrib:opentelemetry-aws-xray")')
template.contains('implementation("io.opentelemetry:opentelemetry-extension-aws")')
!verifier.hasDependency('io.opentelemetry:opentelemetry-extension-aws')

where:
language << Language.values().toList()
Expand Down Expand Up @@ -159,7 +165,7 @@ class OpenTelemetryXraySpec extends ApplicationContextSpec implements CommandOut
<scope>compile</scope>
</dependency>
""")
template.contains("""
!template.contains("""
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-aws</artifactId>
Expand Down Expand Up @@ -207,7 +213,7 @@ class OpenTelemetryXraySpec extends ApplicationContextSpec implements CommandOut
<scope>compile</scope>
</dependency>
""")
template.contains("""
!template.contains("""
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-aws</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.micronaut.starter.core.test.cloud.aws

import io.micronaut.starter.application.ApplicationType
import io.micronaut.starter.feature.opentelemetry.OpenTelemetryXray
import io.micronaut.starter.options.BuildTool
import io.micronaut.starter.options.Language
import io.micronaut.starter.options.TestFramework
import io.micronaut.starter.test.CommandSpec

class TracingOpentelemetryXrayIntegrationSpec extends CommandSpec {

@Override
String getTempDirectoryPrefix() {
"tracing-opentelemetry-xray-function"
}

void 'App with tracing-opentelemetry-xray features builds successfully'() {
given:
ApplicationType applicationType = ApplicationType.DEFAULT
Language lang = Language.JAVA
BuildTool build = BuildTool.GRADLE_KOTLIN
TestFramework testFramework = TestFramework.JUNIT

List<String> features = [OpenTelemetryXray.NAME]
generateProject(lang, build, features, applicationType, testFramework)

when:
String output = executeBuild(build, "test")

then:
output.contains("BUILD SUCCESS")
}
}

0 comments on commit f2cde30

Please sign in to comment.