-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25409 from benjamin-confino/23458-tel-shim
23458 tel shim
- Loading branch information
Showing
13 changed files
with
245 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...nal_fat/fat/src/io/openliberty/microprofile/telemetry/internal_fat/TelemetryShimTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.microprofile.telemetry.internal_fat; | ||
|
||
import static com.ibm.websphere.simplicity.ShrinkHelper.DeployOptions.SERVER_ONLY; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.ibm.websphere.simplicity.PropertiesAsset; | ||
import com.ibm.websphere.simplicity.ShrinkHelper; | ||
|
||
import componenttest.annotation.Server; | ||
import componenttest.annotation.TestServlet; | ||
import componenttest.annotation.TestServlets; | ||
import componenttest.custom.junit.runner.FATRunner; | ||
import componenttest.topology.impl.LibertyServer; | ||
import componenttest.topology.utils.FATServletClient; | ||
import io.openliberty.microprofile.telemetry.internal_fat.apps.shim.OpenTracingShimServlet; | ||
import io.openliberty.microprofile.telemetry.internal_fat.apps.shim.TracedBean; | ||
|
||
/** | ||
* Test use of the Open Telemetry Autoconfigure Trace SPIs: https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-extension-autoconfigure-spi/latest/index.html | ||
*/ | ||
@RunWith(FATRunner.class) | ||
public class TelemetryShimTest extends FATServletClient { | ||
|
||
public static final String SHIM_APP_NAME = "shimTest"; | ||
|
||
@TestServlets({ | ||
@TestServlet(contextRoot = SHIM_APP_NAME, servlet = OpenTracingShimServlet.class), | ||
}) | ||
@Server("Telemetry10Shim") | ||
public static LibertyServer server; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
WebArchive exporterTestWar = ShrinkWrap.create(WebArchive.class, SHIM_APP_NAME + ".war") | ||
.addClass(OpenTracingShimServlet.class) | ||
.addClass(TracedBean.class) | ||
.addAsLibraries(new File("lib/shim").listFiles()); | ||
|
||
ShrinkHelper.exportAppToServer(server, exporterTestWar, SERVER_ONLY); | ||
|
||
server.startServer(); | ||
} | ||
|
||
@AfterClass | ||
public static void teardown() throws Exception { | ||
server.stopServer(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
.../io/openliberty/microprofile/telemetry/internal_fat/apps/shim/OpenTracingShimServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.microprofile.telemetry.internal_fat.apps.shim; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.servlet.annotation.WebServlet; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.opentracingshim.OpenTracingShim; | ||
|
||
import io.opentracing.Span; | ||
import io.opentracing.Tracer; | ||
|
||
import componenttest.app.FATServlet; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* JAXRS service. | ||
*/ | ||
@ApplicationScoped | ||
@WebServlet("/shim") | ||
public class OpenTracingShimServlet extends FATServlet { | ||
/** | ||
* <p>The open tracing tracer. Will bew injected as a shim from OpenTelemetry.</p> | ||
*/ | ||
private Tracer tracer; | ||
|
||
@Inject | ||
void createShim(OpenTelemetry ot) { | ||
tracer = OpenTracingShim.createTracerShim(ot); | ||
} | ||
|
||
/** | ||
* Injected class with Traced annotation on the class. | ||
*/ | ||
@Inject | ||
private TracedBean bean; | ||
|
||
@Test | ||
public void testOpenTracingShim() { | ||
bean.annotatedClassMethodImplicitlyTraced(tracer); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
..._fat/fat/src/io/openliberty/microprofile/telemetry/internal_fat/apps/shim/TracedBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package io.openliberty.microprofile.telemetry.internal_fat.apps.shim; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.opentelemetry.instrumentation.annotations.WithSpan; | ||
|
||
import io.opentracing.Span; | ||
import io.opentracing.Tracer; | ||
|
||
import org.junit.Assert; | ||
|
||
/** | ||
* POJO to test Traced annotation. | ||
*/ | ||
@ApplicationScoped | ||
public class TracedBean { | ||
/** | ||
* Method that we expect to be Traced implicitly. | ||
*/ | ||
@WithSpan | ||
public void annotatedClassMethodImplicitlyTraced(Tracer tracer) { | ||
System.out.println("Called annotatedClassMethodImplicitlyTraced"); | ||
Span span = tracer.activeSpan(); | ||
Assert.assertNotNull(span); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...roprofile.telemetry.1.0.internal_fat/publish/servers/Telemetry10Shim/bootstrap.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bootstrap.include=../testports.properties | ||
otel.sdk.disabled=false |
1 change: 1 addition & 0 deletions
1
...berty.microprofile.telemetry.1.0.internal_fat/publish/servers/Telemetry10Shim/jvm.options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Dio.opentelemetry.context.enableStrictContext=true |
15 changes: 15 additions & 0 deletions
15
...iberty.microprofile.telemetry.1.0.internal_fat/publish/servers/Telemetry10Shim/server.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<server description="Server for testing Telemetry10"> | ||
|
||
<include location="../fatTestPorts.xml" /> | ||
|
||
<featureManager> | ||
<feature>servlet-6.0</feature> | ||
<feature>mpTelemetry-1.0</feature> | ||
<feature>componentTest-2.0</feature> | ||
</featureManager> | ||
|
||
<application type="war" location="shimTest.war"> | ||
<classloader apiTypeVisibility="+third-party" /> | ||
</application> | ||
|
||
</server> |