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

Fix and enhance resource detection logging. #711

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -49,11 +49,11 @@ public String detect() throws Exception {
}

if (!dirTool.isDirectory(deploymentDir)) {
logger.log(FINE, "Deployment dir '{0}' doesn't exist.", deploymentDir);
logger.log(FINE, "Deployment dir {0} doesn't exist.", deploymentDir);
return null;
}

logger.log(FINE, "Looking for deployments in '{0}'.", deploymentDir);
logger.log(FINE, "Looking for deployments in {0}.", deploymentDir);
try (Stream<Path> stream = dirTool.list(deploymentDir)) {
return stream.map(this::detectName).filter(Objects::nonNull).findFirst().orElse(null);
}
Expand All @@ -62,11 +62,11 @@ public String detect() throws Exception {
@Nullable
private String detectName(Path path) {
if (!appServer.isValidAppName(path)) {
logger.log(FINE, "Skipping '{0}'.", path);
logger.log(FINE, "Skipping {0}.", path);
return null;
}

logger.log(FINE, "Attempting service name detection in '{0}'.", path);
logger.log(FINE, "Attempting service name detection in {0}.", path);
String name = path.getFileName().toString();
if (dirTool.isDirectory(path)) {
return parseBuddy.handleExplodedApp(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;

import com.google.auto.service.AutoService;
import io.opentelemetry.api.common.Attributes;
Expand Down Expand Up @@ -37,11 +38,14 @@ public AppServerServiceNameProvider() {
@Override
public Resource createResource(ConfigProperties config) {
String serviceName = detectServiceName();
if (serviceName != null) {
logger.log(INFO, "Auto-detected service name '{0}'.", serviceName);
return Resource.create(Attributes.of(SERVICE_NAME, serviceName));
if (serviceName == null) {
logger.log(
WARNING,
breedx-splk marked this conversation as resolved.
Show resolved Hide resolved
"Service name could not be detected using common application server strategies.");
return Resource.empty();
}
return Resource.empty();
logger.log(INFO, "Auto-detected service name {0}.", serviceName);
breedx-splk marked this conversation as resolved.
Show resolved Hide resolved
return Resource.create(Attributes.of(SERVICE_NAME, serviceName));
}

@Nullable
Expand All @@ -58,10 +62,30 @@ private String detectServiceName() {
@Override
public boolean shouldApply(ConfigProperties config, Resource existing) {
String serviceName = config.getString("otel.service.name");
if (serviceName != null) {
logger.log(
INFO,
"Skipping AppServerServiceName detection, otel.service.name is already set to {0}",
serviceName);
return false;
}
Map<String, String> resourceAttributes = config.getMap("otel.resource.attributes");
return serviceName == null
&& !resourceAttributes.containsKey(SERVICE_NAME.getKey())
&& "unknown_service:java".equals(existing.getAttribute(SERVICE_NAME));
if (resourceAttributes.containsKey(SERVICE_NAME.getKey())) {
logger.log(
INFO,
"Skipping AppServerServiceName detection, otel.resource.attributes already contains {0}",
resourceAttributes.get(SERVICE_NAME.getKey()));
return false;
}
String existingName = existing.getAttribute(SERVICE_NAME);
if (!"unknown_service:java".equals(existingName)) {
logger.log(
INFO,
"Skipping AppServerServiceName detection, resource already contains {0}",
existingName);
return false;
}
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public Path getDeploymentDir() {
// would be located in /dir/webapps.

String programArguments = System.getProperty("sun.java.command");
logger.log(FINE, "Started with arguments '{0}'.", programArguments);
logger.log(FINE, "Started with arguments {0}.", programArguments);
if (programArguments != null) {
Path jettyBase = parseJettyBase(programArguments);
if (jettyBase != null) {
logger.log(FINE, "Using jetty.base '{0}'.", jettyBase);
logger.log(FINE, "Using jetty.base {0}.", jettyBase);
return jettyBase.resolve("webapps");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Path getDeploymentDir() {
if (logger.isLoggable(FINE)) {
logger.log(
FINE,
"Using WLP_USER_DIR '{0}', WLP_OUTPUT_DIR '{1}'.",
"Using WLP_USER_DIR {0}, WLP_OUTPUT_DIR {1}.",
new Object[] {wlpUserDir, wlpOutputDir});
}
if (wlpUserDir != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String detect() throws Exception {
}

String programArguments = System.getProperty("sun.java.command");
logger.log(FINE, "Started with arguments '{0}'.", programArguments);
logger.log(FINE, "Started with arguments {0}.", programArguments);
if (programArguments == null) {
return null;
}
Expand All @@ -53,7 +53,7 @@ public String detect() throws Exception {
// in docker image it is /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/config
Path configDirectory = Paths.get(matcher.group(2));
if (!Files.isDirectory(configDirectory)) {
logger.log(FINE, "Missing configuration directory '{0}'.", configDirectory);
logger.log(FINE, "Missing configuration directory {0}.", configDirectory);
return null;
}

Expand All @@ -64,7 +64,7 @@ public String detect() throws Exception {
if (logger.isLoggable(FINE)) {
logger.log(
FINE,
"Parsed arguments: cell '{0}', node '{1}', server '{2}', configuration directory '{3}'.",
"Parsed arguments: cell {0}, node {1}, server {2}, configuration directory {3}.",
new Object[] {cell, node, server, configDirectory});
}

Expand All @@ -78,17 +78,17 @@ public String detect() throws Exception {
}
Path cellApplications = parent.resolve("installedApps").resolve(cell);
if (Files.isDirectory(cellApplications)) {
logger.log(FINE, "Looking for deployments in '{0}'.", cellApplications);
logger.log(FINE, "Looking for deployments in {0}.", cellApplications);

try (Stream<Path> stream = Files.list(cellApplications)) {
for (Path path : stream.collect(Collectors.toList())) {
String fullName = path.getFileName().toString();
// websphere deploys all applications as ear
if (!fullName.endsWith(".ear") || !appServer.isValidAppName(path)) {
logger.log(FINE, "Skipping '{0}'.", path);
logger.log(FINE, "Skipping {0}.", path);
continue;
}
logger.log(FINE, "Attempting service name detection in '{0}'.", path);
logger.log(FINE, "Attempting service name detection in {0}.", path);

// strip ear suffix
String name = fullName.substring(0, fullName.length() - 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WildflyAppServer implements AppServer {
@Override
public Path getDeploymentDir() throws URISyntaxException {
String programArguments = System.getProperty("sun.java.command");
logger.log(FINE, "Started with arguments '{0}'.", programArguments);
logger.log(FINE, "Started with arguments {0}.", programArguments);
if (programArguments == null) {
return null;
}
Expand All @@ -42,7 +42,7 @@ public Path getDeploymentDir() throws URISyntaxException {
// environment variable JBOSS_BASE_DIR to avoid parsing program arguments
String jbossBaseDir = System.getenv("JBOSS_BASE_DIR");
if (jbossBaseDir != null) {
logger.log(FINE, "Using JBOSS_BASE_DIR '{0}'.", jbossBaseDir);
logger.log(FINE, "Using JBOSS_BASE_DIR {0}.", jbossBaseDir);
return Paths.get(jbossBaseDir, "deployments");
}

Expand Down