Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1163c97
commit d8c0fcd
Showing
4 changed files
with
379 additions
and
7 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
119 changes: 119 additions & 0 deletions
119
...main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/B3MultiPropagationTest.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,119 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed 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.eclipse.microprofile.telemetry.tracing.tck.rest; | ||
|
||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_KEY; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_METADATA; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_METADATA_ATTR; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_VALUE; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_VALUE_ATTR; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.PROPAGATION_HEADERS_ATTR; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.SpanResourceClient; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.RestClientDefinitionException; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.TestLibraries; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.exporter.InMemorySpanExporter; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.exporter.InMemorySpanExporterProvider; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.api.baggage.BaggageEntryMetadata; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import jakarta.inject.Inject; | ||
|
||
public class B3MultiPropagationTest extends Arquillian { | ||
|
||
@Deployment | ||
public static WebArchive createDeployment() { | ||
|
||
return ShrinkWrap.create(WebArchive.class) | ||
.addClasses(InMemorySpanExporter.class, InMemorySpanExporterProvider.class, PropagationHelper.class, | ||
SpanResourceClient.class) | ||
.addAsLibrary(TestLibraries.AWAITILITY_LIB) | ||
.addAsServiceProvider(ConfigurableSpanExporterProvider.class, InMemorySpanExporterProvider.class) | ||
.addAsResource( | ||
new StringAsset( | ||
"otel.sdk.disabled=false\notel.traces.exporter=in-memory\notel.propagators=b3multi"), | ||
"META-INF/microprofile-config.properties") | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
} | ||
|
||
@ArquillianResource | ||
URL url; | ||
@Inject | ||
InMemorySpanExporter spanExporter; | ||
|
||
SpanResourceClient client; | ||
|
||
@BeforeMethod | ||
void setUp() { | ||
// Only want to run on server | ||
if (spanExporter != null) { | ||
spanExporter.reset(); | ||
|
||
try { | ||
// Create client manually so we can pass in URL from arquillian | ||
client = RestClientBuilder.newBuilder().baseUri(url.toURI()).build(SpanResourceClient.class); | ||
} catch (IllegalStateException | RestClientDefinitionException | URISyntaxException e) { | ||
Assert.fail("Failed to create rest client", e); | ||
} | ||
} | ||
} | ||
|
||
@Test(groups = "optional-tests") | ||
void B3MultiPropagation() { | ||
|
||
Baggage baggage = Baggage.builder() | ||
.put(BAGGAGE_KEY, BAGGAGE_VALUE, BaggageEntryMetadata.create(BAGGAGE_METADATA)).build(); | ||
try (Scope s = baggage.makeCurrent()) { | ||
client.span(); | ||
} | ||
// assertResponseStatus(response, OK); | ||
|
||
spanExporter.assertSpanCount(2); | ||
|
||
SpanData server = spanExporter.getFirst(SpanKind.SERVER); | ||
|
||
// B3 does not support baggage, so baggage should not be propagated | ||
Assert.assertNull(server.getAttributes().get(BAGGAGE_VALUE_ATTR)); | ||
Assert.assertNull(server.getAttributes().get(BAGGAGE_METADATA_ATTR)); | ||
|
||
// Assert that the expected headers were used | ||
Assert.assertTrue(server.getAttributes().get(PROPAGATION_HEADERS_ATTR).contains("X-B3-TraceId")); | ||
Assert.assertTrue(server.getAttributes().get(PROPAGATION_HEADERS_ATTR).contains("X-B3-SpanId")); | ||
Assert.assertTrue(server.getAttributes().get(PROPAGATION_HEADERS_ATTR).contains("X-B3-Sampled")); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
.../src/main/java/org/eclipse/microprofile/telemetry/tracing/tck/rest/B3PropagationTest.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,117 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed 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.eclipse.microprofile.telemetry.tracing.tck.rest; | ||
|
||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_KEY; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_METADATA; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_METADATA_ATTR; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_VALUE; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.BAGGAGE_VALUE_ATTR; | ||
import static org.eclipse.microprofile.telemetry.tracing.tck.rest.PropagationHelper.SpanResourceClient; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.RestClientDefinitionException; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.TestLibraries; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.exporter.InMemorySpanExporter; | ||
import org.eclipse.microprofile.telemetry.tracing.tck.exporter.InMemorySpanExporterProvider; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.api.baggage.BaggageEntryMetadata; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import jakarta.inject.Inject; | ||
|
||
public class B3PropagationTest extends Arquillian { | ||
|
||
@Deployment | ||
public static WebArchive createDeployment() { | ||
|
||
return ShrinkWrap.create(WebArchive.class) | ||
.addClasses(InMemorySpanExporter.class, InMemorySpanExporterProvider.class, PropagationHelper.class, | ||
SpanResourceClient.class) | ||
.addAsLibrary(TestLibraries.AWAITILITY_LIB) | ||
.addAsServiceProvider(ConfigurableSpanExporterProvider.class, InMemorySpanExporterProvider.class) | ||
.addAsResource( | ||
new StringAsset( | ||
"otel.sdk.disabled=false\notel.traces.exporter=in-memory\notel.propagators=b3"), | ||
"META-INF/microprofile-config.properties") | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
} | ||
|
||
@ArquillianResource | ||
URL url; | ||
@Inject | ||
InMemorySpanExporter spanExporter; | ||
|
||
SpanResourceClient client; | ||
|
||
@BeforeMethod | ||
void setUp() { | ||
// Only want to run on server | ||
if (spanExporter != null) { | ||
spanExporter.reset(); | ||
|
||
try { | ||
// Create client manually so we can pass in URL from arquillian | ||
client = RestClientBuilder.newBuilder().baseUri(url.toURI()).build(SpanResourceClient.class); | ||
} catch (IllegalStateException | RestClientDefinitionException | URISyntaxException e) { | ||
Assert.fail("Failed to create rest client", e); | ||
} | ||
} | ||
} | ||
|
||
@Test(groups = "optional-tests") | ||
void B3Propagation() { | ||
|
||
Baggage baggage = Baggage.builder() | ||
.put(BAGGAGE_KEY, BAGGAGE_VALUE, BaggageEntryMetadata.create(BAGGAGE_METADATA)).build(); | ||
try (Scope s = baggage.makeCurrent()) { | ||
client.span(); | ||
} | ||
spanExporter.assertSpanCount(2); | ||
|
||
SpanData server = spanExporter.getFirst(SpanKind.SERVER); | ||
|
||
// B3 does not support baggage, so baggage should not be propagated | ||
Assert.assertNull(server.getAttributes().get(BAGGAGE_VALUE_ATTR)); | ||
Assert.assertNull(server.getAttributes().get(BAGGAGE_METADATA_ATTR)); | ||
|
||
// Assert that the expected headers were used | ||
Assert.assertTrue( | ||
server.getAttributes().get(AttributeKey.stringArrayKey("test.propagation.headers")).contains("b3")); | ||
|
||
} | ||
} |
Oops, something went wrong.