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 @@ -98,8 +98,8 @@ public AwsSdkTelemetryBuilder setRecordIndividualHttpError(boolean recordIndivid
* #setUseConfiguredPropagatorForMessaging(boolean)}
*/
@CanIgnoreReturnValue
AwsSdkTelemetryBuilder setUseXrayPropagator(boolean useMessagingPropagator) {
this.useXrayPropagator = useMessagingPropagator;
AwsSdkTelemetryBuilder setUseXrayPropagator(boolean useXrayPropagator) {
this.useXrayPropagator = useXrayPropagator;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -403,8 +402,7 @@ void testConverseToolCallNoMessageContent() {
}

@Test
void testConverseToolCallStreamNoMessageContent()
throws InterruptedException, ExecutionException {
void testConverseToolCallStreamNoMessageContent() {
BedrockRuntimeAsyncClientBuilder builder = BedrockRuntimeAsyncClient.builder();
AwsSdkTelemetry telemetry =
AwsSdkTelemetry.builder(testing.getOpenTelemetry())
Expand Down Expand Up @@ -472,7 +470,7 @@ void testConverseToolCallStreamNoMessageContent()
.toolConfig(currentWeatherToolConfig())
.build(),
responseHandler)
.get();
.join();

if (currentToolArgs.length() > 0 && !responseChunksTools.isEmpty()) {
JsonNode node = JsonNode.parser().parse(currentToolArgs.toString());
Expand Down Expand Up @@ -650,7 +648,7 @@ void testConverseToolCallStreamNoMessageContent()
.toolConfig(currentWeatherToolConfig())
.build(),
responseHandler1)
.get();
.join();

assertThat(String.join("", responseChunks))
.contains(
Expand Down Expand Up @@ -1191,8 +1189,7 @@ void testInvokeModelToolCallAmazonNovaNoMessageContent() {
}

@Test
void testInvokeModelWithResponseStreamToolCallAmazonNovaNoMessageContent()
throws InterruptedException, ExecutionException {
void testInvokeModelWithResponseStreamToolCallAmazonNovaNoMessageContent() {
BedrockRuntimeAsyncClientBuilder builder = BedrockRuntimeAsyncClient.builder();
AwsSdkTelemetry telemetry =
AwsSdkTelemetry.builder(testing.getOpenTelemetry())
Expand Down Expand Up @@ -1337,7 +1334,7 @@ public void accept(PayloadPart chunk) {
.build())
.build();

client.invokeModelWithResponseStream(request0, responseHandler0).get();
client.invokeModelWithResponseStream(request0, responseHandler0).join();

String seattleToolUseId0 = "";
String sanFranciscoToolUseId0 = "";
Expand Down Expand Up @@ -1557,7 +1554,7 @@ public void accept(PayloadPart chunk) {
.build())
.build();

client.invokeModelWithResponseStream(request1, responseHandler1).get();
client.invokeModelWithResponseStream(request1, responseHandler1).join();

assertThat(text.toString())
.contains(
Expand Down Expand Up @@ -2027,8 +2024,7 @@ void testInvokeModelToolCallAnthropicClaudeNoMessageContent() {
}

@Test
void testInvokeModelWithResponseStreamToolCallAnthropicClaudeNoMessageContent()
throws InterruptedException, ExecutionException {
void testInvokeModelWithResponseStreamToolCallAnthropicClaudeNoMessageContent() {
BedrockRuntimeAsyncClientBuilder builder = BedrockRuntimeAsyncClient.builder();
AwsSdkTelemetry telemetry =
AwsSdkTelemetry.builder(testing.getOpenTelemetry())
Expand Down Expand Up @@ -2176,7 +2172,7 @@ public void accept(PayloadPart chunk) {
.build())
.build();

client.invokeModelWithResponseStream(request0, responseHandler0).get();
client.invokeModelWithResponseStream(request0, responseHandler0).join();

String seattleToolUseId0 = "";
String sanFranciscoToolUseId0 = "";
Expand Down Expand Up @@ -2370,7 +2366,7 @@ public void accept(PayloadPart chunk) {
.build())
.build();

client.invokeModelWithResponseStream(request1, responseHandler1).get();
client.invokeModelWithResponseStream(request1, responseHandler1).join();

assertThat(text.toString())
.contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
import static org.assertj.core.api.Assertions.assertThat;

import com.azure.core.annotation.ExpectedResponses;
Expand Down Expand Up @@ -105,7 +109,12 @@ void testPipelineAndSuppression() {
span.hasKind(SpanKind.CLIENT)
.hasName("GET")
.hasStatus(StatusData.unset())
.hasAttribute(HTTP_RESPONSE_STATUS_CODE, 200L)));
.hasAttributesSatisfyingExactly(
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
equalTo(SERVER_ADDRESS, "azure.com"),
equalTo(SERVER_PORT, 443),
equalTo(URL_FULL, "https://azure.com/path"))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ private static class ContextWithScope {
private final CamelRequest request;
@Nullable private final Scope scope;

ContextWithScope(ContextWithScope parent, Context context, CamelRequest request, Scope scope) {
ContextWithScope(
@Nullable ContextWithScope parent,
@Nullable Context context,
CamelRequest request,
@Nullable Scope scope) {
this.parent = parent;
this.context = context;
this.request = request;
Expand All @@ -97,11 +101,12 @@ static ContextWithScope activate(
return new ContextWithScope(parent, context, request, scope);
}

@Nullable
ContextWithScope getParent() {
return parent;
}

void deactivate(Exception exception) {
void deactivate(@Nullable Exception exception) {
if (scope == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class DecoratorRegistry {

private static final SpanDecorator DEFAULT = new BaseSpanDecorator();
private static final Map<String, SpanDecorator> DECORATORS = loadDecorators();
private static final SpanDecorator defaultDecorator = new BaseSpanDecorator();
private static final Map<String, SpanDecorator> decorators = loadDecorators();

private static Map<String, SpanDecorator> loadDecorators() {
Map<String, SpanDecorator> result = new HashMap<>();
Expand Down Expand Up @@ -64,6 +64,6 @@ private static Map<String, SpanDecorator> loadDecorators() {

public SpanDecorator forComponent(String component) {

return DECORATORS.getOrDefault(component, DEFAULT);
return decorators.getOrDefault(component, defaultDecorator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;

class RestSpanDecorator extends HttpSpanDecorator {

private static final Logger logger = Logger.getLogger(RestSpanDecorator.class.getName());

@Nullable
@Override
protected String getPath(Exchange exchange, Endpoint endpoint) {
String endpointUri = endpoint.getEndpointUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -45,6 +45,8 @@ class TwoServicesWithDirectClientCamelTest
@RegisterExtension
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();

private static CamelContext clientContext;

private static Integer portOne;
Expand Down Expand Up @@ -74,11 +76,7 @@ protected String getContextPath() {
@BeforeAll
protected void setUp() {
startServer();
}

@AfterAll
protected void cleanUp() {
cleanupServer();
cleanup.deferAfterAll(this::cleanupServer);
}

void createAndStartClient() throws Exception {
Expand All @@ -94,6 +92,7 @@ public void configure() {
}
});
clientContext.start();
cleanup.deferAfterAll(clientContext::stop);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ muzzle {
group.set("com.datastax.cassandra")
module.set("cassandra-driver-core")
versions.set("[3.0,4.0)")
assertInverse.set(true)
// While com.datastax.cassandra uses old versions of Guava, users may depends themselves on newer versions of Guava
extraDependency("com.google.guava:guava:27.0-jre")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public ResultSetFuture executeAsync(String query) {
ResultSetFuture future = session.executeAsync(query);
addCallbackToEndSpan(future, context, request);
return future;
} catch (Throwable t) {
instrumenter().end(context, request, null, t);
throw t;
}
}

Expand All @@ -127,6 +130,9 @@ public ResultSetFuture executeAsync(String query, Object... values) {
ResultSetFuture future = session.executeAsync(query, values);
addCallbackToEndSpan(future, context, request);
return future;
} catch (Throwable t) {
instrumenter().end(context, request, null, t);
throw t;
}
}

Expand All @@ -138,6 +144,9 @@ public ResultSetFuture executeAsync(String query, Map<String, Object> values) {
ResultSetFuture future = session.executeAsync(query, values);
addCallbackToEndSpan(future, context, request);
return future;
} catch (Throwable t) {
instrumenter().end(context, request, null, t);
throw t;
}
}

Expand All @@ -151,6 +160,9 @@ public ResultSetFuture executeAsync(Statement statement) {
ResultSetFuture future = session.executeAsync(statement);
addCallbackToEndSpan(future, context, request);
return future;
} catch (Throwable t) {
instrumenter().end(context, request, null, t);
throw t;
}
}

Expand Down
Loading