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
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class CamelPropagationUtilTest {
class CamelPropagationUtilTest {

@BeforeAll
public static void setUp() {
static void setUp() {
GlobalOpenTelemetry.set(
OpenTelemetry.propagating(ContextPropagators.create(JaegerPropagator.getInstance())));
}

@Test
public void shouldExtractHttpParentForHttpEndpoint() throws Exception {

void shouldExtractHttpParentForHttpEndpoint() throws Exception {
// given
Endpoint endpoint = new HttpEndpoint("", new HttpComponent(), URI.create(""));
Map<String, Object> exchangeHeaders =
Expand All @@ -54,8 +53,7 @@ public void shouldExtractHttpParentForHttpEndpoint() throws Exception {
}

@Test
public void shouldNotFailExtractingNullHttpParentForHttpEndpoint() throws Exception {

void shouldNotFailExtractingNullHttpParentForHttpEndpoint() throws Exception {
// given
Endpoint endpoint = new HttpEndpoint("", new HttpComponent(), URI.create(""));
Map<String, Object> exchangeHeaders = Collections.singletonMap("uber-trace-id", null);
Expand All @@ -70,8 +68,7 @@ public void shouldNotFailExtractingNullHttpParentForHttpEndpoint() throws Except
}

@Test
public void shouldNotFailExtractingNullAwsParentForSqsEndpoint() {

void shouldNotFailExtractingNullAwsParentForSqsEndpoint() {
// given
Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration());
Map<String, Object> exchangeHeaders = Collections.singletonMap("AWSTraceHeader", null);
Expand All @@ -86,8 +83,7 @@ public void shouldNotFailExtractingNullAwsParentForSqsEndpoint() {
}

@Test
public void shouldExtractAwsParentForSqsEndpoint() {

void shouldExtractAwsParentForSqsEndpoint() {
// given
Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration());
Map<String, Object> exchangeHeaders =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -20,6 +20,18 @@

class SanitizationTest {

static class CqlArgs implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("FROM TABLE WHERE FIELD>=-1234", "FROM TABLE WHERE FIELD>=?"),
Arguments.of(
"SELECT Name, Phone.Number FROM Contact WHERE Address.State = 'NY'",
"SELECT Name, Phone.Number FROM Contact WHERE Address.State = ?"),
Arguments.of("FROM col WHERE @Tag='Something'", "FROM col WHERE @Tag=?"));
}
}

@ParameterizedTest
@ArgumentsSource(CqlArgs.class)
void sanitizeCql(String original, String expected) {
Expand All @@ -31,7 +43,22 @@ void sanitizeCql(String original, String expected) {
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(expected, actualSanitized);
assertThat(actualSanitized).isEqualTo(expected);
}

static class JdbcArgs implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("SELECT 3", "SELECT ?"),
Arguments.of(
"SELECT * FROM TABLE WHERE FIELD = 1234", "SELECT * FROM TABLE WHERE FIELD = ?"),
Arguments.of(
"SELECT * FROM TABLE WHERE FIELD<-1234", "SELECT * FROM TABLE WHERE FIELD<?"),
Arguments.of(
"SELECT col1 AS col2 FROM users WHERE field=1234",
"SELECT col1 AS col2 FROM users WHERE field=?"));
}
}

@ParameterizedTest
Expand All @@ -45,22 +72,7 @@ void sanitizeJdbc(String original, String expected) {
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(expected, actualSanitized);
}

@ParameterizedTest
@ArgumentsSource(SqlArgs.class)
void sanitizeSql(String original, String expected) {

DbSpanDecorator decorator = new DbSpanDecorator("sql", "");

Exchange exchange = mock(Exchange.class);
Message message = mock(Message.class);
when(message.getHeader("CamelSqlQuery")).thenReturn(original);
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(expected, actualSanitized);
assertThat(actualSanitized).isEqualTo(expected);
}

static class SqlArgs implements ArgumentsProvider {
Expand All @@ -75,30 +87,18 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
}
}

static class CqlArgs implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("FROM TABLE WHERE FIELD>=-1234", "FROM TABLE WHERE FIELD>=?"),
Arguments.of(
"SELECT Name, Phone.Number FROM Contact WHERE Address.State = 'NY'",
"SELECT Name, Phone.Number FROM Contact WHERE Address.State = ?"),
Arguments.of("FROM col WHERE @Tag='Something'", "FROM col WHERE @Tag=?"));
}
}
@ParameterizedTest
@ArgumentsSource(SqlArgs.class)
void sanitizeSql(String original, String expected) {

static class JdbcArgs implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("SELECT 3", "SELECT ?"),
Arguments.of(
"SELECT * FROM TABLE WHERE FIELD = 1234", "SELECT * FROM TABLE WHERE FIELD = ?"),
Arguments.of(
"SELECT * FROM TABLE WHERE FIELD<-1234", "SELECT * FROM TABLE WHERE FIELD<?"),
Arguments.of(
"SELECT col1 AS col2 FROM users WHERE field=1234",
"SELECT col1 AS col2 FROM users WHERE field=?"));
}
DbSpanDecorator decorator = new DbSpanDecorator("sql", "");

Exchange exchange = mock(Exchange.class);
Message message = mock(Message.class);
when(message.getHeader("CamelSqlQuery")).thenReturn(original);
when(exchange.getIn()).thenReturn(message);

String actualSanitized = decorator.getStatement(exchange, null);
assertThat(actualSanitized).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ private static Map<String, SpanDecorator> loadDecorators() {
result.put("direct-vm", new InternalSpanDecorator());
result.put("disruptor", new InternalSpanDecorator());
result.put("disruptor-vm", new InternalSpanDecorator());
result.put("elasticsearch", new DbSpanDecorator("elasticsearch", "elasticsearch"));
result.put("opensearch", new DbSpanDecorator("opensearch", "opensearch"));
result.put(
"elasticsearch",
new DbSpanDecorator(
"elasticsearch", DbIncubatingAttributes.DbSystemIncubatingValues.ELASTICSEARCH));
result.put(
"opensearch",
new DbSpanDecorator(
"opensearch", DbIncubatingAttributes.DbSystemIncubatingValues.OPENSEARCH));
result.put("http4", new Http4SpanDecorator());
result.put("https4", new Https4SpanDecorator());
result.put("http", new HttpSpanDecorator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
class DirectCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationContext> {

@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

private ConfigurableApplicationContext appContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
class MulticastDirectCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationContext> {

@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

private ConfigurableApplicationContext appContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
class RestCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationContext> {

@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

private ConfigurableApplicationContext appContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
class SingleServiceCamelTest extends AbstractHttpServerUsingTest<ConfigurableApplicationContext> {

@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

@Override
protected ConfigurableApplicationContext setupServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
class TwoServicesWithDirectClientCamelTest
extends AbstractHttpServerUsingTest<ConfigurableApplicationContext> {
@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

private static CamelContext clientContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SYSTEM;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class AwsSpanAssertions {
Expand Down Expand Up @@ -65,41 +65,41 @@ static SpanDataAssert sqs(
throw new IllegalStateException("can't get rpc method from span name " + spanName);
}

List<AttributeAssertion> attributeAssertions = new ArrayList<>();
attributeAssertions.addAll(
Arrays.asList(
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
satisfies(
stringKey("aws.queue.name"),
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo(queueName), v -> assertThat(v).isNull())),
satisfies(
stringKey("aws.queue.url"),
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo(queueUrl), v -> assertThat(v).isNull())),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(HTTP_REQUEST_METHOD, "POST"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200),
satisfies(URL_FULL, val -> val.isInstanceOf(String.class)),
satisfies(SERVER_ADDRESS, stringAssert -> stringAssert.isInstanceOf(String.class)),
satisfies(
SERVER_PORT,
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isNull(),
v -> assertThat(v).isInstanceOf(Number.class))),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(RPC_SYSTEM, "aws-api"),
satisfies(RPC_METHOD, stringAssert -> stringAssert.isEqualTo(rpcMethod)),
equalTo(RPC_SERVICE, "AmazonSQS")));
List<AttributeAssertion> attributeAssertions =
new ArrayList<>(
asList(
equalTo(stringKey("aws.agent"), "java-aws-sdk"),
satisfies(
stringKey("aws.queue.name"),
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo(queueName), v -> assertThat(v).isNull())),
satisfies(
stringKey("aws.queue.url"),
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isEqualTo(queueUrl), v -> assertThat(v).isNull())),
satisfies(AWS_REQUEST_ID, val -> val.isInstanceOf(String.class)),
equalTo(HTTP_REQUEST_METHOD, "POST"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200),
satisfies(URL_FULL, val -> val.isInstanceOf(String.class)),
satisfies(SERVER_ADDRESS, stringAssert -> stringAssert.isInstanceOf(String.class)),
satisfies(
SERVER_PORT,
val ->
val.satisfiesAnyOf(
v -> assertThat(v).isNull(),
v -> assertThat(v).isInstanceOf(Number.class))),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(RPC_SYSTEM, "aws-api"),
satisfies(RPC_METHOD, stringAssert -> stringAssert.isEqualTo(rpcMethod)),
equalTo(RPC_SERVICE, "AmazonSQS")));

if (spanName.endsWith("receive")
|| spanName.endsWith("process")
|| spanName.endsWith("publish")) {
attributeAssertions.addAll(
Arrays.asList(
asList(
equalTo(MESSAGING_DESTINATION_NAME, queueName), equalTo(MESSAGING_SYSTEM, AWS_SQS)));
if (spanName.endsWith("receive")) {
attributeAssertions.add(equalTo(MESSAGING_OPERATION, "receive"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void direct(SpanDataAssert span, String spanName) {
span.hasName(spanName)
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttribute(stringKey("camel.uri"), "direct://" + spanName);
.hasAttributesSatisfyingExactly(equalTo(stringKey("camel.uri"), "direct://" + spanName));
}

static SpanDataAssert sqsProduce(SpanDataAssert span, String queueName) {
Expand All @@ -42,7 +42,7 @@ static SpanDataAssert sqsConsume(SpanDataAssert span, String queueName) {
static SpanDataAssert sqsConsume(SpanDataAssert span, String queueName, int delay) {
return span.hasName(queueName)
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
.hasAttributesSatisfyingExactly(
equalTo(
stringKey("camel.uri"),
"aws-sqs://" + queueName + "?amazonSQSClient=%23sqsClient&delay=" + delay),
Expand All @@ -54,7 +54,7 @@ static SpanDataAssert sqsConsume(SpanDataAssert span, String queueName, int dela
static SpanDataAssert snsPublish(SpanDataAssert span, String topicName) {
return span.hasName(topicName)
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
.hasAttributesSatisfyingExactly(
equalTo(
stringKey("camel.uri"), "aws-sns://" + topicName + "?amazonSNSClient=%23snsClient"),
equalTo(MESSAGING_DESTINATION_NAME, topicName));
Expand All @@ -63,7 +63,7 @@ static SpanDataAssert snsPublish(SpanDataAssert span, String topicName) {
static SpanDataAssert s3(SpanDataAssert span, String bucketName) {
return span.hasName("aws-s3")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfying(
.hasAttributesSatisfyingExactly(
equalTo(
stringKey("camel.uri"), "aws-s3://" + bucketName + "?amazonS3Client=%23s3Client"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class S3CamelTest {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static final Logger logger = LoggerFactory.getLogger(S3CamelTest.class);

Expand All @@ -37,7 +37,7 @@ protected static void setUp() {
}

@Test
public void camelS3ProducerToCamelSqsConsumer() {
void camelS3ProducerToCamelSqsConsumer() {
String queueName = "s3SqsCamelTest";
String bucketName = "bucket-test-s3-sqs-camel";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SnsCamelTest {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static final Logger logger = LoggerFactory.getLogger(SnsCamelTest.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SqsCamelTest {

@RegisterExtension
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

private static final AwsConnector awsConnector = AwsConnector.elasticMq();

Expand Down
Loading
Loading