Skip to content
Merged
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 @@ -33,6 +33,7 @@
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.resources.Resource;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.logging.Logger;
Expand Down Expand Up @@ -60,28 +61,39 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetr
OP_AMP_POLLING_INTERVAL, DEFAULT_DELAY_BETWEEN_REQUESTS.getNextDelay().toMillis());

String endpoint = config.getString(OP_AMP_ENDPOINT);
startOpampClient(
endpoint,
resource,
pollingDuration,
new OpampClient.Callbacks() {
@Override
public void onConnect(OpampClient opampClient) {}
OpampClient client =
startOpampClient(
endpoint,
resource,
pollingDuration,
new OpampClient.Callbacks() {
@Override
public void onConnect(OpampClient opampClient) {}

@Override
public void onConnectFailed(OpampClient opampClient, @Nullable Throwable throwable) {
logger.log(WARNING, "Connection to OpAMP server failed", throwable);
}
@Override
public void onConnectFailed(OpampClient opampClient, @Nullable Throwable throwable) {
logger.log(WARNING, "Connection to OpAMP server failed", throwable);
}

@Override
public void onErrorResponse(
OpampClient opampClient, ServerErrorResponse serverErrorResponse) {
logger.log(WARNING, "OpAMP server returned error " + serverErrorResponse);
}
@Override
public void onErrorResponse(
OpampClient opampClient, ServerErrorResponse serverErrorResponse) {
logger.log(WARNING, "OpAMP server returned error " + serverErrorResponse);
}

@Override
public void onMessage(OpampClient opampClient, MessageData messageData) {}
});
@Override
public void onMessage(OpampClient opampClient, MessageData messageData) {}
});
Runtime.getRuntime()
.addShutdownHook(
new Thread(
() -> {
try {
client.close();
} catch (IOException e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider catching Exception here. If something else that IOException is thrown here, and stderr is not redirected to log then we may see nothing in logs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it is not important. Often the exceptions that happen during shutdown are just noise anyway.

logger.log(WARNING, "Error shutting down OpAMP client", e);
}
}));
}

static OpampClient startOpampClient(
Expand Down
Loading