Skip to content

Commit e316074

Browse files
authored
Service name warning message customized for declarative config (#2500)
1 parent cf43944 commit e316074

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

custom/src/main/java/com/splunk/opentelemetry/servicename/ServiceNameChecker.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static io.opentelemetry.sdk.autoconfigure.AutoConfigureUtil.getResource;
2121

2222
import com.google.auto.service.AutoService;
23+
import io.opentelemetry.api.incubator.config.ConfigProvider;
24+
import io.opentelemetry.api.incubator.config.GlobalConfigProvider;
2325
import io.opentelemetry.javaagent.tooling.BeforeAgentListener;
2426
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
2527
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
@@ -50,10 +52,16 @@ public void beforeAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemet
5052
ConfigProperties config = getConfig(autoConfiguredOpenTelemetrySdk);
5153
Resource resource = getResource(autoConfiguredOpenTelemetrySdk);
5254
if (serviceNameNotConfigured(config, resource)) {
53-
logWarn.accept(
54-
"The service.name resource attribute is not set. Your service is unnamed and will be difficult to identify.\n"
55-
+ " Set your service name using the OTEL_SERVICE_NAME or OTEL_RESOURCE_ATTRIBUTES environment variable.\n"
56-
+ " E.g. `OTEL_SERVICE_NAME=\"<YOUR_SERVICE_NAME_HERE>\"`");
55+
if (isDeclarativeConfigInUse()) {
56+
logWarn.accept(
57+
"The service.name resource attribute is not set. Your service is unnamed and will be difficult to identify.\n"
58+
+ " Set your service name in '.resource.attributes' node, or specify appropriate resource detector in the configuration YAML file.");
59+
} else {
60+
logWarn.accept(
61+
"The service.name resource attribute is not set. Your service is unnamed and will be difficult to identify.\n"
62+
+ " Set your service name using the OTEL_SERVICE_NAME or OTEL_RESOURCE_ATTRIBUTES environment variable.\n"
63+
+ " E.g. `OTEL_SERVICE_NAME=\"<YOUR_SERVICE_NAME_HERE>\"`");
64+
}
5765
}
5866
}
5967

@@ -70,4 +78,8 @@ static boolean serviceNameNotConfigured(ConfigProperties config, Resource resour
7078
&& !resourceAttributes.containsKey(ServiceAttributes.SERVICE_NAME.getKey())
7179
&& "unknown_service:java".equals(resource.getAttribute(ServiceAttributes.SERVICE_NAME));
7280
}
81+
82+
private static boolean isDeclarativeConfigInUse() {
83+
return !GlobalConfigProvider.get().equals(ConfigProvider.noop());
84+
}
7385
}

0 commit comments

Comments
 (0)