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
36 changes: 36 additions & 0 deletions itests/tomee-microprofile-itests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,47 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>apache-tomee</artifactId>
<version>${project.version}</version>
<type>tar.gz</type>
<classifier>plus</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>apache-tomee</artifactId>
<version>${project.version}</version>
<type>tar.gz</type>
<classifier>plume</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>jakartaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.openapi</groupId>
<artifactId>microprofile-openapi-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.tomee.microprofile.telemetry;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationScoped
@ApplicationPath("/api")
public class TelemetryApp extends Application {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.tomee.microprofile.telemetry;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;

@RequestScoped
public class WeatherGateway {

@Inject
private Span span;

@WithSpan("weather.forecast")
public String forecast(@SpanAttribute("weather.city") final String city) {
span.setAttribute("weather.source", "AccuWeather");
return "Sunny in " + city;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.tomee.microprofile.telemetry;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("weather")
@RequestScoped
public class WeatherResource {

@Inject
private WeatherGateway gateway;

@GET
@Path("/forecast/{city}")
@Produces(MediaType.TEXT_PLAIN)
public String forecast(@PathParam("city") final String city) {
return gateway.forecast(city);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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.tomee.microprofile.telemetry;

import jakarta.ws.rs.core.Response;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.tomee.server.composer.Archive;
import org.apache.tomee.server.composer.TomEE;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.tomitribe.util.IO;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(Parameterized.class)
public class TelemetryConfigFileTest {

private static final String OTEL_CONFIG_YAML = String.join("\n",
"file_format: \"1.0\"",
"disabled: false",
"");

@Parameterized.Parameters(name = "{0}")
public static Object[][] distributions() {
return new Object[][]{
{"microprofile"},
{"plus"},
{"plume"},
};
}

private final String classifier;

public TelemetryConfigFileTest(final String classifier) {
this.classifier = classifier;
}

private TomEE.Builder distribution() throws Exception {
switch (classifier) {
case "microprofile":
return TomEE.microprofile();
case "plus":
return TomEE.plus();
case "plume":
// server-composer has no plume() shortcut; resolve it explicitly.
// "version" is exported as a system property by surefire (pom.xml).
return TomEE.of("org.apache.tomee:apache-tomee:tar.gz:plume:" + System.getProperty("version"));
default:
throw new IllegalArgumentException("Unknown classifier: " + classifier);
}
}

@Test
public void telemetryAppDeploysWithConfigFileSet() throws Exception {
final File appJar = Archive.archive()
.add(TelemetryApp.class)
.add(WeatherResource.class)
.add(WeatherGateway.class)
.asJar();

final List<String> declarativeConfigErrors = new ArrayList<>();

final TomEE.Builder builder = distribution()
.add("conf/otel-config.yaml", OTEL_CONFIG_YAML)
.add("webapps/test/WEB-INF/beans.xml", "")
.add("webapps/test/WEB-INF/lib/app.jar", appJar)
.watch("declarative-config", "\n", declarativeConfigErrors::add);

builder.home(home -> builder.env("CATALINA_OPTS",
"-Dtomee.mp.scan=all"
+ " -Dotel.config.file=" + new File(home, "conf/otel-config.yaml").getAbsolutePath()));

final TomEE tomee = builder.build();
try {
final Response response = WebClient.create(tomee.toURI().toString())
.path("/test/api/weather/forecast/London")
.get();

assertEquals(classifier + ": telemetry app did not deploy with otel.config.file set"
+ " (missing opentelemetry-sdk-extension-declarative-config?) " + declarativeConfigErrors,
200, response.getStatus());
assertEquals("Sunny in London", IO.slurp(response.readEntity(java.io.InputStream.class)));
assertTrue(classifier + ": OpenTelemetry declarative-config failure in server log " + declarativeConfigErrors,
declarativeConfigErrors.isEmpty());
} finally {
tomee.shutdown();
}
}
}
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
<version.microprofile.impl.health>4.0.4</version.microprofile.impl.health>
<version.microprofile.impl.openapi>4.2.4</version.microprofile.impl.openapi>
<version.microprofile.impl.opentelemetry>2.15.1</version.microprofile.impl.opentelemetry>
<version.opentelemetry>1.62.0</version.opentelemetry>
<version.opentelemetry.instrumentation>2.27.0</version.opentelemetry.instrumentation>
<version.opentelemetry.declarative-config>1.62.0-alpha</version.opentelemetry.declarative-config>

<!-- Jackson and snakeyaml required by OpenAPI Impl -->
<version.jackson>2.22.1</version.jackson>
Expand Down Expand Up @@ -1916,6 +1919,22 @@
<artifactId>snakeyaml</artifactId>
<version>${version.snakeyaml}</version>
</dependency>
<!-- OpenTelemetry libraries used directly by TomEE modules -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${version.opentelemetry}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-declarative-config</artifactId>
<version>${version.opentelemetry.declarative-config}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>${version.opentelemetry.instrumentation}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 5 additions & 0 deletions tomee/tomee-microprofile/mp-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@
</exclusions>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-declarative-config</artifactId>
</dependency>

<!-- Jackson and snakeyaml required by OpenAPI Impl -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
Loading