Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23458 tel shim #25409

Merged
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
5 changes: 5 additions & 0 deletions dev/cnf/dependabot/check_this_in_if_it_changes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@
<artifactId>opentelemetry-extension-trace-propagators</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-opentracing-shim</artifactId>
<version>1.19.0-alpha</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
Expand Down
1 change: 1 addition & 0 deletions dev/cnf/oss_dependencies.maven
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ io.opentelemetry:opentelemetry-exporter-otlp-common:1.19.0
io.opentelemetry:opentelemetry-exporter-otlp:1.19.0
io.opentelemetry:opentelemetry-exporter-zipkin:1.19.0
io.opentelemetry:opentelemetry-extension-trace-propagators:1.19.0
io.opentelemetry:opentelemetry-opentracing-shim:1.19.0-alpha
io.opentelemetry:opentelemetry-sdk-common:1.19.0
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:1.19.0
io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.19.0-alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import com.ibm.websphere.ras.Tr;
import com.ibm.websphere.ras.TraceComponent;

import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.MeterBuilder;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerBuilder;
import io.opentelemetry.api.trace.TracerProvider;
Expand Down Expand Up @@ -61,4 +65,22 @@ public static Tracer getTracer(String instrumentationScopeName) {
public static TracerBuilder tracerBuilder(String instrumentationScopeName) {
return get().tracerBuilder(instrumentationScopeName);
}

public static MeterProvider getMeterProvider() {
return OpenTelemetry.noop().getMeterProvider();
}

public static Meter getMeter(String instrumentationScopeName) {
return OpenTelemetry.noop().getMeter(instrumentationScopeName);
}

public static MeterBuilder meterBuilder(String instrumentationScopeName) {
return OpenTelemetry.noop().meterBuilder(instrumentationScopeName);
}

public static void resetForTest() { } //no op

public static ContextPropagators getPropagators() {
return OpenTelemetry.noop().getPropagators();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 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
Expand Down Expand Up @@ -82,18 +82,24 @@ public Object span(final InvocationContext invocationContext) throws Exception {
Scope scope = null;
boolean shouldStart = instrumenter.shouldStart(parentContext, methodRequest);
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "Should start: " + shouldStart);
Tr.debug(this, tc, "Method " + invocationContext.getMethod().toString() + " Should start: " + shouldStart);
}

if (shouldStart) {
spanContext = instrumenter.start(parentContext, methodRequest);
scope = spanContext.makeCurrent();
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "spanContext " + spanContext.toString() + " has started and is now the current context");
}
}

try {
Object result = invocationContext.proceed();
if (shouldStart) {
instrumenter.end(spanContext, methodRequest, null, null);
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(this, tc, "spanContext " + spanContext.toString() + " has ended");
}
}
return result;
} finally {
Expand Down Expand Up @@ -142,4 +148,4 @@ public String[] extract(final Method method, final Parameter[] parameters) {
return attributeNames;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ tested.features:\
io.openliberty.org.eclipse.microprofile.rest.client.3.0;version=latest,\
io.openliberty.jakarta.annotation.2.1;version=latest,\
io.openliberty.jakarta.concurrency.3.0;version=latest,\
io.openliberty.mpTelemetry.1.0.thirdparty;version=latest
io.openliberty.mpTelemetry.1.0.thirdparty;version=latest,\
io.opentelemetry:opentelemetry-opentracing-shim;version=1.19.0.alpha,\
io.opentracing:opentracing-api;version=0.33.0


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 IBM Corporation and others.
* Copyright (c) 2022, 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
Expand All @@ -10,7 +10,22 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
apply from: '../wlp-gradle/subprojects/maven-central-mirror.gradle'

configurations {
shimLibs
}
Azquelt marked this conversation as resolved.
Show resolved Hide resolved

dependencies {
requiredLibs project(':io.openliberty.mpTelemetry.1.0.thirdparty')
}
shimLibs 'io.opentelemetry:opentelemetry-opentracing-shim:1.19.0-alpha'
}

task addShimLibs(type: Copy) {
from configurations.shimLibs
into new File(autoFvtDir, 'lib/shim')
}

addRequiredLibraries {
dependsOn addShimLibs
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TelemetryConfigEnvOnlyTest.class,
TelemetryConfigNullTest.class,
TelemetryServiceNameTest.class,
TelemetryShimTest.class,
TelemetryLoggingExporterTest.class,
TelemetryAPITest.class,
MultiThreadedContextTest.class,
Expand Down
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();
}
}
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);
}

}
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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bootstrap.include=../testports.properties
otel.sdk.disabled=false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dio.opentelemetry.context.enableStrictContext=true
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>