From 50038723ea36d0e3037dec324a6a66ac12391239 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Mon, 23 Nov 2026 15:26:01 -0500 Subject: [PATCH 1/5] Internal - Bump otelAgentVersion from 2.33.1 to 2.34.0 and otelSdkVersion from 1.67.0 to 1.68.0 --- buildSrc/build.gradle.kts | 2 +- dependencyManagement/build.gradle.kts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3176246c..ad4dff68 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -42,7 +42,7 @@ dependencies { implementation("com.diffplug.spotless:spotless-plugin-gradle:8.10.4") implementation("io.freefair.gradle:lombok-plugin:9.5.0") - implementation("io.opentelemetry.instrumentation:gradle-plugins:2.33.1-alpha") + implementation("io.opentelemetry.instrumentation:gradle-plugins:2.34.0-alpha") implementation("com.gradleup.shadow:shadow-gradle-plugin:9.6.1") implementation("com.github.gmazzo.buildconfig:com.github.gmazzo.buildconfig.gradle.plugin:6.1.2") implementation("com.github.spotbugs:com.github.spotbugs.gradle.plugin:6.4.8") diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index d456c660..ab1eb30e 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -2,8 +2,8 @@ plugins { `java-platform` } -val otelAgentVersion = "2.33.1" -val otelSdkVersion = "1.67.0" +val otelAgentVersion = "2.34.0" +val otelSdkVersion = "1.68.0" val mockitoVersion = "5.2.0" val byteBuddyVersion = "1.18.17" From 3298c18d1cd8fec3d343865060f7dee75a94854f Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Mon, 23 Nov 2026 15:26:01 -0500 Subject: [PATCH 2/5] New - Stop requiring service name in service key --- .../extensions/SolarwindsAgentListener.java | 42 ++++++++- .../config/ConfigurationLoader.java | 1 + .../extensions/config/HttpSettingsReader.java | 21 +++-- .../config/SdkResourceServiceName.java | 81 +++++++++++++++++ .../HttpSamplerComponentProvider.java | 18 +++- ...ofilingSpanProcessorComponentProvider.java | 1 + .../SolarwindsAgentListenerTest.java | 87 +++++++++++++++++++ .../config/HttpSettingsReaderTest.java | 38 +++++++- .../config/SdkResourceServiceNameTest.java | 71 +++++++++++++++ .../HttpSamplerComponentProviderTest.java | 78 ++++++++++++++++- ...ingSpanProcessorComponentProviderTest.java | 7 ++ .../joboe/config/ServiceKeyUtils.java | 51 +++++++++-- .../joboe/config/ServiceKeyUtilsTest.java | 46 ++++++++++ .../joboe/core/rpc/RpcClientManager.java | 5 -- .../core/util/diagnostic/DiagnosticTools.java | 25 +----- .../extensions/LambdaConfigurationLoader.java | 1 + .../extensions/ResourceCustomizer.java | 23 ----- .../extensions/ResourceCustomizerTest.java | 34 +++----- sdk-config-kitchen-sink.yaml | 6 +- sdk-config.yaml | 2 +- 20 files changed, 540 insertions(+), 98 deletions(-) create mode 100644 custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java create mode 100644 custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceNameTest.java diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java index 64c2e480..ecf93b07 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListener.java @@ -22,6 +22,7 @@ import com.solarwinds.joboe.config.ConfigManager; import com.solarwinds.joboe.config.ConfigProperty; import com.solarwinds.joboe.config.JavaRuntimeVersionChecker; +import com.solarwinds.joboe.config.ServiceKeyUtils; import com.solarwinds.joboe.core.ReporterFactory; import com.solarwinds.joboe.core.profiler.Profiler; import com.solarwinds.joboe.core.profiler.ProfilerSetting; @@ -29,12 +30,17 @@ import com.solarwinds.joboe.core.rpc.RpcClientManager; import com.solarwinds.joboe.core.util.DaemonThreadFactory; import com.solarwinds.joboe.core.util.HostInfoUtils; +import com.solarwinds.joboe.logging.LogSanitizer; import com.solarwinds.joboe.logging.Logger; import com.solarwinds.joboe.logging.LoggerFactory; import com.solarwinds.joboe.sampling.SettingsManager; import com.solarwinds.opentelemetry.core.AgentState; +import com.solarwinds.opentelemetry.extensions.config.SdkResourceServiceName; import io.opentelemetry.javaagent.extension.AgentListener; +import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.sdk.trace.internal.SdkTracerProviderUtil; +import io.opentelemetry.semconv.ServiceAttributes; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -52,14 +58,43 @@ public class SolarwindsAgentListener implements AgentListener { @Override public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) { if (isAgentEnabled()) { - executeStartupTasks(); + String serviceName = resolveServiceName(autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk()); + logger.info("Resolved service name: " + LogSanitizer.sanitize(serviceName)); + SdkResourceServiceName.set(serviceName); + + executeStartupTasks(serviceName); registerShutdownTasks(); logger.info( "Successfully submitted SolarwindsAPM OpenTelemetry extensions initialization tasks"); } } - private void executeStartupTasks() { + /** + * Reads the final {@code service.name} from the built SDK's resource. Works for both declarative + * and system config since the tracer provider always carries the merged resource. + */ + static String resolveServiceName(OpenTelemetrySdk sdk) { + if (sdk == null) { + return null; + } + + try { + return SdkTracerProviderUtil.getSdkResourceProvider(sdk.getSdkTracerProvider()) + .getResource() + .getAttribute(ServiceAttributes.SERVICE_NAME); + } catch (RuntimeException e) { + logger.warn("Unable to read the service name from the SDK resource", e); + return null; + } + } + + /** The service key for the profiling client, carrying the final, normalized service name. */ + static String profilingServiceKey(String serviceName) { + return ServiceKeyUtils.withServiceName( + ConfigManager.getConfigOptional(ConfigProperty.AGENT_SERVICE_KEY, ""), serviceName); + } + + private void executeStartupTasks(String serviceName) { ExecutorService service = Executors.newSingleThreadExecutor(DaemonThreadFactory.newInstance("post-startup-tasks")); @@ -99,7 +134,8 @@ private void executeStartupTasks() { ReporterFactory.getInstance() .createQueuingEventReporter( RpcClientManager.getClient( - RpcClientManager.OperationType.PROFILING))); + RpcClientManager.OperationType.PROFILING, + profilingServiceKey(serviceName)))); } else { logger.info("Profiler is disabled, local settings : " + profilerSetting); } diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoader.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoader.java index 36c9aedf..6a62dfff 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoader.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoader.java @@ -410,6 +410,7 @@ public static void processConfigs(ConfigContainer configs) throws InvalidConfigE && !((String) configs.get(ConfigProperty.AGENT_SERVICE_KEY)).isEmpty()) { // Customer access key (UUID) String rawServiceKey = (String) configs.get(ConfigProperty.AGENT_SERVICE_KEY); + ServiceKeyUtils.warnIfServiceNameInServiceKey(rawServiceKey); String serviceKey = ServiceKeyUtils.transformServiceKey(rawServiceKey); if (!serviceKey.equalsIgnoreCase(rawServiceKey)) { diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReader.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReader.java index f46f87c1..56b3a232 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReader.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReader.java @@ -36,8 +36,6 @@ public class HttpSettingsReader implements SettingsReader { private static final String DEFAULT_COLLECTOR = "apm.collector.na-01.cloud.solarwinds.com"; - private static final String DEFAULT_SERVICE_KEY = ":unknown-java"; - private final HttpSettingsReaderDelegate delegate; private final Supplier collector; @@ -45,17 +43,29 @@ public class HttpSettingsReader implements SettingsReader { private final Supplier serviceKey; public static HttpSettingsReader forSystemConfig(HttpSettingsReaderDelegate delegate) { + return forSystemConfig(delegate, SdkResourceServiceName::get); + } + + static HttpSettingsReader forSystemConfig( + HttpSettingsReaderDelegate delegate, Supplier serviceName) { return new HttpSettingsReader( delegate, () -> ConfigManager.getConfigOptional(ConfigProperty.AGENT_COLLECTOR, DEFAULT_COLLECTOR), () -> - ConfigManager.getConfigOptional(ConfigProperty.AGENT_SERVICE_KEY, DEFAULT_SERVICE_KEY)); + ServiceKeyUtils.withServiceName( + ConfigManager.getConfigOptional(ConfigProperty.AGENT_SERVICE_KEY, ""), + serviceName.get())); } public static HttpSettingsReader forFileConfig( HttpSettingsReaderDelegate delegate, String collector, String serviceKey) { + return forFileConfig(delegate, collector, () -> serviceKey); + } + + public static HttpSettingsReader forFileConfig( + HttpSettingsReaderDelegate delegate, String collector, Supplier serviceKey) { return new HttpSettingsReader( - delegate, () -> collector != null ? collector : DEFAULT_COLLECTOR, () -> serviceKey); + delegate, () -> collector != null ? collector : DEFAULT_COLLECTOR, serviceKey); } private HttpSettingsReader( @@ -72,7 +82,8 @@ private HttpSettingsReader( public Settings getSettings() { String collectorUrl = constructSettingsEndpoint(collector.get()); String serviceKey = this.serviceKey.get(); - String serviceName = ServiceKeyUtils.getServiceName(serviceKey); + String serviceName = + ServiceKeyUtils.serviceNameOrDefault(ServiceKeyUtils.getServiceName(serviceKey)); String apiToken = ServiceKeyUtils.getApiKey(serviceKey); String settingsUrl = diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java new file mode 100644 index 00000000..a1f1ccd6 --- /dev/null +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java @@ -0,0 +1,81 @@ +/* + * © SolarWinds Worldwide, LLC. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.solarwinds.opentelemetry.extensions.config; + +import com.solarwinds.joboe.logging.LoggerFactory; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Holds the final {@code service.name} of the built SDK's resource, published by the agent listener + * once the SDK is built. The settings pollers are created while the SDK is being built, so they + * wait for the name to be published. + */ +public final class SdkResourceServiceName { + private static final long DEFAULT_WAIT_SECONDS = 10; + + private static volatile CompletableFuture serviceName = new CompletableFuture<>(); + + private static volatile boolean timedOut; + + private SdkResourceServiceName() {} + + public static void set(String name) { + serviceName.complete(name); + } + + /** Returns the published service name, waiting up to 10 seconds on the first call. */ + public static String get() { + return get(DEFAULT_WAIT_SECONDS, TimeUnit.SECONDS); + } + + /** + * Returns the published service name, waiting up to the timeout on the first call. Once a wait + * has timed out, later calls return immediately. + * + * @return the service name, or null if it's not available + */ + public static String get(long timeout, TimeUnit unit) { + CompletableFuture current = serviceName; + if (timedOut) { + return current.getNow(null); + } + + try { + return current.get(timeout, unit); + } catch (TimeoutException e) { + timedOut = true; + LoggerFactory.getLogger() + .warn( + "Timed out waiting for the SDK resource service name, falling back to the service" + + " key or default service name"); + return null; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return null; + } catch (Exception e) { + return null; + } + } + + /** For testing only. */ + public static void reset() { + serviceName = new CompletableFuture<>(); + timedOut = false; + } +} diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProvider.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProvider.java index ffa3490a..e2b3cc10 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProvider.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProvider.java @@ -28,9 +28,11 @@ import com.solarwinds.opentelemetry.extensions.config.HttpSettingsReader; import com.solarwinds.opentelemetry.extensions.config.HttpSettingsReaderDelegate; import com.solarwinds.opentelemetry.extensions.config.ProxyHelper; +import com.solarwinds.opentelemetry.extensions.config.SdkResourceServiceName; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import java.util.function.Function; +import java.util.function.Supplier; @AutoService(ComponentProvider.class) public class HttpSamplerComponentProvider extends AbstractSamplerComponentProvider { @@ -49,12 +51,17 @@ public class HttpSamplerComponentProvider extends AbstractSamplerComponentProvid private final Function delegateFactory; + private final Supplier serviceNameSupplier; + public HttpSamplerComponentProvider() { - this(HttpSettingsReaderDelegate::new); + this(HttpSettingsReaderDelegate::new, SdkResourceServiceName::get); } - HttpSamplerComponentProvider(Function delegateFactory) { + HttpSamplerComponentProvider( + Function delegateFactory, + Supplier serviceNameSupplier) { this.delegateFactory = delegateFactory; + this.serviceNameSupplier = serviceNameSupplier; } @Override @@ -94,10 +101,13 @@ protected SettingsFetcher createSettingsFetcher(DeclarativeConfigProperties prop throw new InvalidConfigException("Missing required sampler " + SERVICE_KEY + " config"); } - serviceKey = ServiceKeyUtils.transformServiceKey(serviceKey); + ServiceKeyUtils.warnIfServiceNameInServiceKey(serviceKey); + // Resolved on the polling thread: the SDK resource is only available after the SDK is built. return new HttpSettingsFetcher( HttpSettingsReader.forFileConfig( - delegateFactory.apply(ProxyHelper.toProxyConfig(properties)), collector, serviceKey), + delegateFactory.apply(ProxyHelper.toProxyConfig(properties)), + collector, + () -> ServiceKeyUtils.withServiceName(serviceKey, serviceNameSupplier.get())), POLLING_INTERVAL_SECONDS); } diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProvider.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProvider.java index 06d11c38..ad33fb1a 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProvider.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProvider.java @@ -107,6 +107,7 @@ ProfilerSetting convert(DeclarativeConfigProperties profilerProperties) "Invalid profiler " + SERVICE_KEY + " config, value cannot be empty"); } + ServiceKeyUtils.warnIfServiceNameInServiceKey(serviceKey); ConfigManager.setConfig( ConfigProperty.AGENT_SERVICE_KEY, ServiceKeyUtils.transformServiceKey(serviceKey)); diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListenerTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListenerTest.java index e3b1cf50..6396ecfa 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListenerTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/SolarwindsAgentListenerTest.java @@ -16,13 +16,28 @@ package com.solarwinds.opentelemetry.extensions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import com.solarwinds.joboe.config.ConfigManager; +import com.solarwinds.joboe.config.ConfigProperty; +import com.solarwinds.joboe.config.InvalidConfigException; +import com.solarwinds.opentelemetry.extensions.config.SdkResourceServiceName; import com.solarwinds.opentelemetry.extensions.config.provider.AutoConfigurationCustomizerProviderImpl; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.sdk.internal.ExtendedOpenTelemetrySdk; +import io.opentelemetry.sdk.internal.SdkConfigProvider; +import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.semconv.ServiceAttributes; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; @@ -55,6 +70,8 @@ class SolarwindsAgentListenerTest { void teardown() throws Throwable { // Reset the static agentEnabled field to true so it doesn't affect other tests AGENT_ENABLED_SETTER.invokeExact(true); + ConfigManager.reset(); + SdkResourceServiceName.reset(); } @Mock private AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdkMock; @@ -75,4 +92,74 @@ void verifySdkIsNotShutdownWhenBranchIsTaken() { verify(openTelemetrySdkMock, never()).shutdown(); } } + + @Test + void resolveServiceNameReadsDeclarativeSdkResource() { + try (OpenTelemetrySdk sdk = declarativeSdk("SDK Service")) { + assertEquals("SDK Service", SolarwindsAgentListener.resolveServiceName(sdk)); + } + } + + @Test + void resolveServiceNameReadsSystemConfigSdkResource() { + try (OpenTelemetrySdk sdk = sdk(resource("System Service"))) { + assertEquals("System Service", SolarwindsAgentListener.resolveServiceName(sdk)); + } + } + + @Test + void resolveServiceNameReturnsDefaultResourceServiceName() { + try (OpenTelemetrySdk sdk = declarativeSdk(null)) { + assertEquals("unknown_service:java", SolarwindsAgentListener.resolveServiceName(sdk)); + } + } + + @Test + void resolveServiceNameReturnsNullWithoutSdk() { + assertNull(SolarwindsAgentListener.resolveServiceName(null)); + } + + @Test + void profilingServiceKeyAttachesNormalizedServiceNameWithoutChangingConfig() + throws InvalidConfigException { + ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token"); + + assertEquals("token:sdk-service", SolarwindsAgentListener.profilingServiceKey("SDK Service")); + assertEquals("token", ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); + } + + @Test + void profilingServiceKeyReplacesServiceKeyName() throws InvalidConfigException { + ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token:key-service"); + + assertEquals("token:sdk-service", SolarwindsAgentListener.profilingServiceKey("sdk-service")); + } + + @Test + void profilingServiceKeyUsesDefaultServiceNameWhenNoneIsAvailable() + throws InvalidConfigException { + ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token"); + + assertEquals("token:unknown_service:java", SolarwindsAgentListener.profilingServiceKey(null)); + } + + private static OpenTelemetrySdk declarativeSdk(String serviceName) { + return ExtendedOpenTelemetrySdk.create( + sdk(resource(serviceName)), SdkConfigProvider.create(DeclarativeConfigProperties.empty())); + } + + private static OpenTelemetrySdk sdk(Resource resource) { + return OpenTelemetrySdk.builder() + .setTracerProvider(SdkTracerProvider.builder().setResource(resource).build()) + .setMeterProvider(SdkMeterProvider.builder().setResource(resource).build()) + .setLoggerProvider(SdkLoggerProvider.builder().setResource(resource).build()) + .build(); + } + + private static Resource resource(String serviceName) { + return serviceName == null + ? Resource.getDefault() + : Resource.getDefault() + .merge(Resource.create(Attributes.of(ServiceAttributes.SERVICE_NAME, serviceName))); + } } diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReaderTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReaderTest.java index 1b277686..7e4b2d06 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReaderTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/HttpSettingsReaderTest.java @@ -42,10 +42,13 @@ class HttpSettingsReaderTest { private HttpSettingsReader tested; + private String serviceName; + @BeforeEach void setUp() { ConfigManager.reset(); - tested = HttpSettingsReader.forSystemConfig(delegate); + serviceName = "test-service"; + tested = HttpSettingsReader.forSystemConfig(delegate, () -> serviceName); } @Test @@ -107,8 +110,9 @@ void testGetSettings_UrlWithHttp() throws InvalidConfigException { @Test void testGetSettings_WithDefaultValues() { + serviceName = null; String expectedUrl = - "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/unknown-java"; + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/unknown_service:java"; String expectedTokenHeader = "Bearer "; when(delegate.fetchSettings(expectedUrl, expectedTokenHeader)).thenReturn(mockSettings); @@ -122,7 +126,8 @@ void testGetSettings_WithDefaultValues() { @Test void testGetSettings_WithCustomServiceKey() throws InvalidConfigException { String collectorUrl = "custom.collector.com"; - String serviceKey = "my-api-key:my-service"; + String serviceKey = "my-api-key"; + serviceName = "my-service"; String expectedUrl = "https://custom.collector.com/v1/settings/my-service"; String expectedTokenHeader = "Bearer my-api-key"; @@ -158,7 +163,8 @@ void testGetSettings_DelegateThrowsException() throws InvalidConfigException { @Test void testGetSettings_UrlWithPortAndPath() throws InvalidConfigException { String collectorUrl = "https://custom.collector.com:8080/api"; - String serviceKey = "test-key:test-app"; + String serviceKey = "test-key"; + serviceName = "test-app"; String expectedUrl = "https://custom.collector.com:8080/api/v1/settings/test-app"; String expectedTokenHeader = "Bearer test-key"; @@ -211,4 +217,28 @@ void testGetSettingsSanitizesSettingsUrl() { assertEquals(mockSettings, fileConfigReader.getSettings()); verify(delegate).fetchSettings(expectedUrl, expectedTokenHeader); } + + @Test + void testGetSettings_WithTokenOnlyServiceKeyUsesDefaultServiceName() { + HttpSettingsReader reader = + HttpSettingsReader.forFileConfig(delegate, "apm.collector.com", "token-only"); + String expectedUrl = "https://apm.collector.com/v1/settings/unknown_service:java"; + + when(delegate.fetchSettings(expectedUrl, "Bearer token-only")).thenReturn(mockSettings); + + assertEquals(mockSettings, reader.getSettings()); + } + + @Test + void testGetSettings_SystemConfigUsesPublishedServiceNameOverServiceKeyName() + throws InvalidConfigException { + serviceName = "Published Service"; + ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "test-api-key:key-service"); + String expectedUrl = + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/published-service"; + + when(delegate.fetchSettings(expectedUrl, "Bearer test-api-key")).thenReturn(mockSettings); + + assertEquals(mockSettings, tested.getSettings()); + } } diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceNameTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceNameTest.java new file mode 100644 index 00000000..a0eea70f --- /dev/null +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceNameTest.java @@ -0,0 +1,71 @@ +/* + * © SolarWinds Worldwide, LLC. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.solarwinds.opentelemetry.extensions.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +class SdkResourceServiceNameTest { + + @AfterEach + void tearDown() { + SdkResourceServiceName.reset(); + } + + @Test + void returnsPublishedServiceName() { + SdkResourceServiceName.set("sdk-service"); + + assertEquals("sdk-service", SdkResourceServiceName.get(0, TimeUnit.SECONDS)); + } + + @Test + void returnsServiceNamePublishedWhileWaiting() { + new Thread(() -> SdkResourceServiceName.set("sdk-service")).start(); + + assertEquals("sdk-service", SdkResourceServiceName.get(5, TimeUnit.SECONDS)); + } + + @Test + void returnsNullWhenPublishedServiceNameIsNull() { + SdkResourceServiceName.set(null); + + assertNull(SdkResourceServiceName.get(5, TimeUnit.SECONDS)); + } + + @Test + void stopsWaitingAfterTimeout() { + assertNull(SdkResourceServiceName.get(10, TimeUnit.MILLISECONDS)); + + long start = System.nanoTime(); + assertNull(SdkResourceServiceName.get(5, TimeUnit.SECONDS)); + assertTrue(TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start) < 1); + } + + @Test + void returnsServiceNamePublishedAfterTimeout() { + assertNull(SdkResourceServiceName.get(10, TimeUnit.MILLISECONDS)); + SdkResourceServiceName.set("late-service"); + + assertEquals("late-service", SdkResourceServiceName.get(5, TimeUnit.SECONDS)); + } +} diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProviderTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProviderTest.java index bd65da6a..ed43d525 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProviderTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/HttpSamplerComponentProviderTest.java @@ -61,7 +61,8 @@ class HttpSamplerComponentProviderTest { proxy -> { proxyConfig.set(proxy); return delegate; - }); + }, + () -> "sampler-service"); @BeforeEach void setUp() { @@ -186,4 +187,79 @@ private DeclarativeConfigProperties fromYaml(String yaml) { new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))) .getStructured("swo_http"); } + + @Test + void testCreateUsesFinalServiceNameOverServiceKeyName() throws InterruptedException { + new HttpSamplerComponentProvider(proxy -> delegate, () -> "configured-service") + .create(fromYaml(SERVICE_KEY_ONLY)); + awaitFirstPoll(); + + verify(delegate) + .fetchSettings( + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/configured-service", + "Bearer sampler-key"); + } + + @Test + void testCreateUsesFinalServiceNameWithTokenOnlyServiceKey() throws InterruptedException { + new HttpSamplerComponentProvider(proxy -> delegate, () -> "configured-service") + .create(fromYaml("swo_http:\n service_key: sampler-key\n")); + awaitFirstPoll(); + + verify(delegate) + .fetchSettings( + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/configured-service", + "Bearer sampler-key"); + } + + @Test + void testCreateUsesDefaultServiceNameWhenNoneIsAvailable() throws InterruptedException { + new HttpSamplerComponentProvider(proxy -> delegate, () -> null) + .create(fromYaml(SERVICE_KEY_ONLY)); + awaitFirstPoll(); + + verify(delegate) + .fetchSettings( + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/unknown_service:java", + "Bearer sampler-key"); + } + + @Test + void testCreateResolvesServiceNameWhenPolling() throws InterruptedException { + CountDownLatch serviceNamePublished = new CountDownLatch(1); + AtomicReference serviceName = new AtomicReference<>(); + + new HttpSamplerComponentProvider( + proxy -> delegate, + () -> { + try { + serviceNamePublished.await(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + return serviceName.get(); + }) + .create(fromYaml("swo_http:\n service_key: sampler-key\n")); + + serviceName.set("sdk-service"); + serviceNamePublished.countDown(); + awaitFirstPoll(); + + verify(delegate) + .fetchSettings( + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/sdk-service", + "Bearer sampler-key"); + } + + @Test + void testCreateNormalizesFinalServiceName() throws InterruptedException { + new HttpSamplerComponentProvider(proxy -> delegate, () -> "My Service") + .create(fromYaml("swo_http:\n service_key: sampler-key\n")); + awaitFirstPoll(); + + verify(delegate) + .fetchSettings( + "https://apm.collector.na-01.cloud.solarwinds.com/v1/settings/my-service", + "Bearer sampler-key"); + } } diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProviderTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProviderTest.java index 4dce97de..bf10978a 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProviderTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/provider/ProfilingSpanProcessorComponentProviderTest.java @@ -226,4 +226,11 @@ private DeclarativeConfigProperties findProfilerConfig(InputStream in, String na .findFirst() .orElseThrow(() -> new IllegalStateException("swo_profiler not found in " + name)); } + + @Test + void testConvertAcceptsTokenOnlyServiceKey() throws InvalidConfigException { + tested.convert(fromYaml("swo_profiler:\n service_key: token\n")); + + assertEquals("token", ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); + } } diff --git a/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java b/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java index 0be3fa04..9d4c5b55 100644 --- a/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java +++ b/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java @@ -17,12 +17,15 @@ package com.solarwinds.joboe.config; import com.solarwinds.joboe.logging.LogSanitizer; +import com.solarwinds.joboe.logging.LoggerFactory; public class ServiceKeyUtils { public static final char SEPARATOR_CHARACTER = ':'; // char that separates customer key and service name within the service key public static final int SERVICE_NAME_MAX_LENGTH = 255; + public static final String DEFAULT_SERVICE_NAME = "unknown_service:java"; + public static String maskServiceKey(String serviceKey) { if (serviceKey == null) { return serviceKey; @@ -63,17 +66,55 @@ public static String getApiKey(String serviceKey) { return separatorIndex != -1 ? serviceKey.substring(0, separatorIndex) : serviceKey; } + /** + * Builds the {@code :} key expected by the collector from the final + * service name, normalized with {@link #transformServiceName}, falling back to {@link + * #DEFAULT_SERVICE_NAME} when there's none. + */ + public static String withServiceName(String serviceKey, String serviceName) { + return getApiKey(serviceKey) + + SEPARATOR_CHARACTER + + transformServiceName(serviceNameOrDefault(serviceName)); + } + + public static String serviceNameOrDefault(String serviceName) { + return isNotBlank(serviceName) ? serviceName : DEFAULT_SERVICE_NAME; + } + + public static void warnIfServiceNameInServiceKey(String serviceKey) { + if (serviceKey != null && isNotBlank(getServiceName(serviceKey))) { + LoggerFactory.getLogger() + .warn( + "Setting the service name in the service key is deprecated and will be removed in a" + + " future release. Set the service name with OTEL_SERVICE_NAME instead and" + + " provide only the API token as the service key."); + } + } + + private static boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + public static String transformServiceKey(String serviceKey) { String serviceName = getServiceName(serviceKey); if (serviceName != null) { - serviceName = serviceName.toLowerCase().replaceAll("\\s", "-").replaceAll("[^\\w.:_-]", ""); - if (serviceName.length() > SERVICE_NAME_MAX_LENGTH) { - serviceName = serviceName.substring(0, SERVICE_NAME_MAX_LENGTH); - } - return getApiKey(serviceKey) + SEPARATOR_CHARACTER + serviceName; + return getApiKey(serviceKey) + SEPARATOR_CHARACTER + transformServiceName(serviceName); } else { return serviceKey; } } + + /** + * Normalizes a service name: lower case, whitespace replaced with '-', characters other than word + * characters, '.', ':', '_' and '-' removed, and truncated to {@link #SERVICE_NAME_MAX_LENGTH}. + */ + public static String transformServiceName(String serviceName) { + String transformed = + serviceName.toLowerCase().replaceAll("\\s", "-").replaceAll("[^\\w.:_-]", ""); + if (transformed.length() > SERVICE_NAME_MAX_LENGTH) { + transformed = transformed.substring(0, SERVICE_NAME_MAX_LENGTH); + } + return transformed; + } } diff --git a/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java b/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java index e0f3851c..58b88fb6 100644 --- a/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java +++ b/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java @@ -46,4 +46,50 @@ void sanitizesLineBreaksInMaskedKey() { void returnsNullForNull() { assertNull(ServiceKeyUtils.maskServiceKey(null)); } + + @Test + void withServiceNameAppendsNameToTokenOnlyKey() { + assertEquals("token:my-service", ServiceKeyUtils.withServiceName("token", "My Service")); + } + + @Test + void withServiceNameReplacesServiceKeyName() { + assertEquals( + "token:final-name", ServiceKeyUtils.withServiceName("token:key-name", "final-name")); + } + + @Test + void withServiceNameUsesDefaultWhenNameIsMissing() { + assertEquals( + "token:unknown_service:java", ServiceKeyUtils.withServiceName("token:key-name", null)); + assertEquals("token:unknown_service:java", ServiceKeyUtils.withServiceName("token", " ")); + } + + @Test + void transformServiceNameNormalizesName() { + assertEquals( + "my-service.v1:prod_a", ServiceKeyUtils.transformServiceName("My Service.v1:prod_a!")); + } + + @Test + void transformServiceNameTruncatesLongName() { + StringBuilder name = new StringBuilder(); + for (int i = 0; i < ServiceKeyUtils.SERVICE_NAME_MAX_LENGTH + 10; i++) { + name.append('a'); + } + + assertEquals( + ServiceKeyUtils.SERVICE_NAME_MAX_LENGTH, + ServiceKeyUtils.transformServiceName(name.toString()).length()); + } + + @Test + void transformServiceKeyNormalizesServiceName() { + assertEquals("token:my-service", ServiceKeyUtils.transformServiceKey("token:My Service")); + } + + @Test + void transformServiceKeyKeepsTokenOnlyKey() { + assertEquals("token", ServiceKeyUtils.transformServiceKey("token")); + } } diff --git a/libs/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcClientManager.java b/libs/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcClientManager.java index 1ac5226e..0fc878a4 100644 --- a/libs/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcClientManager.java +++ b/libs/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcClientManager.java @@ -108,11 +108,6 @@ private static void setHostAndPortByVariable(String variable) { + "] for RPC client creation"); } - public static Client getClient(OperationType operationType) throws ClientException { - return getClient( - operationType, (String) ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); - } - public static Client getClient(OperationType operationType, String serviceKey) throws ClientException { return ClientManagerProvider.getClientManager(ClientType.GRPC) diff --git a/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java b/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java index 4c9311c1..304b6d1b 100644 --- a/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java +++ b/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java @@ -48,7 +48,7 @@ * *

java -Djava.security.debug=certpath,provider -Djavax.net.debug=ssl:session -cp * solarwinds-apm-agent.jar com.solarwinds.joboe.core.util.diagnostic.DiagnosticTools - * service_key=YourSolarWindsApiToken:YourServiceName [optional parameters] + * service_key=YourSolarWindsApiToken [optional parameters] * *

For example: java -Djava.security.debug=certpath,provider -Djavax.net.debug=ssl:session -cp * solarwinds-apm-agent.jar com.solarwinds.joboe.core.util.diagnostic.DiagnosticTools @@ -134,7 +134,7 @@ public static void main(String[] args) { private static void printUsage() { logger.info( - "Usage example : java -Djava.security.debug=certpath,provider -Djavax.net.debug=ssl:session -cp solarwinds-apm-agent.jar com.solarwinds.joboe.core.util.diagnostic.DiagnosticTools service_key=YourSolarWindsApiToken:YourServiceName"); + "Usage example : java -Djava.security.debug=certpath,provider -Djavax.net.debug=ssl:session -cp solarwinds-apm-agent.jar com.solarwinds.joboe.core.util.diagnostic.DiagnosticTools service_key=YourSolarWindsApiToken"); logger.info( "All other program parameters except for the service_key are optional and in format of [key]=[value], available parameters are:"); logger.info("service_key : Service key to be used for the diagnostics"); @@ -370,17 +370,8 @@ private static boolean isValidServiceKeyFormat(String serviceKey) { return false; } - String[] tokens = serviceKey.split(":", 2); - if (tokens.length != 2) { - logger.warn( - "Service Key [" - + ServiceKeyUtils.maskServiceKey(serviceKey) - + "] format is incorrect - not in :"); - return false; - } - - String apiToken = tokens[0]; - String serviceName = tokens[1]; + ServiceKeyUtils.warnIfServiceNameInServiceKey(serviceKey); + String apiToken = ServiceKeyUtils.getApiKey(serviceKey); if (apiToken.length() != APPOPTICS_API_TOKEN_LENGTH && apiToken.length() != SWOKEN_API_TOKEN_LENGTH) { @@ -397,14 +388,6 @@ private static boolean isValidServiceKeyFormat(String serviceKey) { return false; } - if (serviceName.trim().isEmpty()) { - logger.warn( - "Service Name should not be empty in Service Key [" - + ServiceKeyUtils.maskServiceKey(serviceKey) - + "]"); - return false; - } - return true; } diff --git a/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaConfigurationLoader.java b/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaConfigurationLoader.java index 2aeec2cd..05ebf21f 100644 --- a/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaConfigurationLoader.java +++ b/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/LambdaConfigurationLoader.java @@ -84,6 +84,7 @@ public static void load() throws InvalidConfigException { loadConfigurations(); String serviceKey = (String) ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY); + ServiceKeyUtils.warnIfServiceNameInServiceKey(serviceKey); logger.info( "Successfully loaded SolarwindsAPM OpenTelemetry extensions configurations. Service key: " + ServiceKeyUtils.maskServiceKey(serviceKey)); diff --git a/libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizer.java b/libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizer.java index 6957873b..922ba8a3 100644 --- a/libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizer.java +++ b/libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizer.java @@ -18,10 +18,7 @@ import com.solarwinds.joboe.config.ConfigManager; import com.solarwinds.joboe.config.ConfigProperty; -import com.solarwinds.joboe.config.InvalidConfigException; import com.solarwinds.joboe.config.ServiceKeyUtils; -import com.solarwinds.joboe.logging.LogSanitizer; -import com.solarwinds.joboe.logging.LoggerFactory; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.resources.ResourceBuilder; @@ -60,10 +57,8 @@ public Resource apply(Resource resource, ConfigProperties configProperties) { } String serviceName = getServiceName(resource, configProperties); - updateServiceKey(serviceName); resourceBuilder.put(ServiceAttributes.SERVICE_NAME, serviceName); - LoggerFactory.getLogger().info("Resolved service name: " + LogSanitizer.sanitize(serviceName)); ResourceCustomizer.resource = resourceBuilder.build(); return ResourceCustomizer.resource; } @@ -88,22 +83,4 @@ private String getServiceName(Resource resource, ConfigProperties configProperti return serviceName; } - - private void updateServiceKey(String serviceName) { - if (serviceName != null) { - String serviceKey = ConfigManager.getConfigOptional(ConfigProperty.AGENT_SERVICE_KEY, ":"); - String apiKey = ServiceKeyUtils.getApiKey(serviceKey); - - try { - ConfigManager.setConfig( - ConfigProperty.AGENT_SERVICE_KEY, String.format("%s:%s", apiKey, serviceName)); - } catch (InvalidConfigException ignore) { - LoggerFactory.getLogger() - .debug( - () -> - "Failed to update service key with name: " - + LogSanitizer.sanitize(serviceName)); - } - } - } } diff --git a/libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizerTest.java b/libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizerTest.java index 831aab38..cd5fa90b 100644 --- a/libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizerTest.java +++ b/libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/ResourceCustomizerTest.java @@ -197,32 +197,18 @@ void verifyThatServiceNameIsNullWhenNotInResourceAndNoServiceKeyConfigured() { } @Test - void verifyThatServiceKeyIsUpdatedWithConfiguredServiceNameWhenNotOnAppService() - throws InvalidConfigException { - ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token:old-name"); + void verifyThatServiceKeyIsNotModified() throws InvalidConfigException { + ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token"); Resource resource = Resource.create( - Attributes.builder().put(ServiceAttributes.SERVICE_NAME, "new-name").build()); - - tested.apply( - resource, - DefaultConfigProperties.createFromMap( - Collections.singletonMap("otel.service.name", "new-name"))); - assertEquals("token:new-name", ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); - } + Attributes.builder().put(ServiceAttributes.SERVICE_NAME, "otel-service").build()); - @Test - void verifyThatServiceKeyIsUpdatedWithServiceNameWhenOnAppService() - throws InvalidConfigException { - ConfigManager.setConfig(ConfigProperty.AGENT_SERVICE_KEY, "token:old-name"); - Resource resource = - Resource.create( - Attributes.builder() - .put(CloudIncubatingAttributes.CLOUD_PLATFORM, "azure.app_service") - .put(ServiceAttributes.SERVICE_NAME, "new-name") - .build()); - - tested.apply(resource, DefaultConfigProperties.createFromMap(Collections.emptyMap())); - assertEquals("token:new-name", ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); + Resource actual = + tested.apply( + resource, + DefaultConfigProperties.createFromMap( + Collections.singletonMap("otel.service.name", "otel-service"))); + assertEquals("otel-service", actual.getAttribute(ServiceAttributes.SERVICE_NAME)); + assertEquals("token", ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); } } diff --git a/sdk-config-kitchen-sink.yaml b/sdk-config-kitchen-sink.yaml index 3dd96c55..27255595 100644 --- a/sdk-config-kitchen-sink.yaml +++ b/sdk-config-kitchen-sink.yaml @@ -122,7 +122,8 @@ tracer_provider: - swo_profiler: # Optional. Defaults to false. enabled: true - # Required when enabled. Format: : + # Required when enabled. Format: . The service name comes from the service.name resource attribute; + # : is deprecated. service_key: ${SW_APM_SERVICE_KEY} # Optional. Set to your data center's collector. collector: apm.collector.na-01.cloud.solarwinds.com @@ -184,7 +185,8 @@ tracer_provider: sampler: # Required. Fetches sampling settings from the SolarWinds collector. swo_http: - # Required. Format: : + # Required. Format: . The service name comes from the service.name resource attribute; + # : is deprecated. service_key: ${SW_APM_SERVICE_KEY} # Required. Set to your data center's collector. Falls back to apm.collector.na-01.cloud.solarwinds.com. collector: apm.collector.na-01.cloud.solarwinds.com diff --git a/sdk-config.yaml b/sdk-config.yaml index 5ac00b96..c99bf3ee 100644 --- a/sdk-config.yaml +++ b/sdk-config.yaml @@ -7,7 +7,7 @@ # vars defined in https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/. # Required environment variables: -# SW_APM_SERVICE_KEY: : +# SW_APM_SERVICE_KEY: (the service name comes from the service.name resource attribute) # SW_APM_API_TOKEN: # Replace na-01 in the sampler collector and exporter endpoints with your SolarWinds Observability data center. From 43f0e9860635a8e61db6ec8eaea0a79987c36872 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Mon, 23 Nov 2026 16:21:06 -0500 Subject: [PATCH 3/5] Internal - Use token-only service key in smoke tests --- .github/workflows/push.yml | 6 ++++-- smoke-tests/netty-test/build.gradle.kts | 5 ++++- .../java/com/solarwinds/containers/ExtensionContainer.java | 3 ++- .../com/solarwinds/containers/PetClinicRestContainer.java | 5 +++-- .../solarwinds/containers/SpringBootWebMvcContainer.java | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 271d1a07..b886fc74 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -192,7 +192,8 @@ jobs: run: | ./gradlew :netty-test:run env: - SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }}:smoke-test-linux + SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }} + OTEL_SERVICE_NAME: smoke-test-linux smoke-test-no-agent: runs-on: ubuntu-latest @@ -249,7 +250,8 @@ jobs: run: | .\gradlew.bat :netty-test:run env: - SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }}:smoke-test-windows + SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }} + OTEL_SERVICE_NAME: smoke-test-windows release-test: runs-on: ubuntu-latest diff --git a/smoke-tests/netty-test/build.gradle.kts b/smoke-tests/netty-test/build.gradle.kts index 8b76fd5f..6b3637ba 100644 --- a/smoke-tests/netty-test/build.gradle.kts +++ b/smoke-tests/netty-test/build.gradle.kts @@ -65,6 +65,9 @@ tasks.register("downloadSwoAgent") } tasks.named("run", JavaExec::class) { - setEnvironment("SW_APM_SERVICE_KEY" to "${System.getenv("SW_APM_SERVICE_KEY")}:netty-pipeline-test-app") + setEnvironment( + "SW_APM_SERVICE_KEY" to System.getenv("SW_APM_SERVICE_KEY"), + "OTEL_SERVICE_NAME" to (System.getenv("OTEL_SERVICE_NAME") ?: "netty-pipeline-test-app") + ) dependsOn("downloadSwoAgent") } diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/ExtensionContainer.java b/smoke-tests/src/test/java/com/solarwinds/containers/ExtensionContainer.java index f7b40093..64c4352c 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/ExtensionContainer.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/ExtensionContainer.java @@ -58,7 +58,8 @@ public GenericContainer build() { .waitingFor(Wait.forHttp("/actuator/health").withReadTimeout(Duration.ofMinutes(5)).forPort(SERVER_PORT)) .withEnv("SERVER_PORT", String.format("%d", SERVER_PORT)) .withEnv("SW_APM_DEBUG_LEVEL", "trace") - .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY") + ":java-apm-smoke-test-webmvc-ext") + .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY")) + .withEnv("OTEL_SERVICE_NAME", "java-apm-smoke-test-webmvc-ext") .withStartupTimeout(Duration.ofMinutes(5)) .withCopyFileToContainer( MountableFile.forHostPath(agentPath), diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java b/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java index a73b47d7..fe33948d 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/PetClinicRestContainer.java @@ -109,7 +109,7 @@ public GenericContainer build() { .withEnv("spring_datasource_username", PostgresContainer.USERNAME) .withEnv("spring_datasource_password", PostgresContainer.PASSWORD) .withEnv("spring_jpa_hibernate_ddl-auto", "none") - .withEnv("SW_APM_SERVICE_KEY", String.format("%s:%s", System.getenv("SW_APM_SERVICE_KEY"), ServiceNames.SMOKE_TEST)) + .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY")) .withEnv("OTEL_EXPORTER_OTLP_HEADERS", String.format("authorization=Bearer %s", System.getenv("SW_APM_SERVICE_KEY"))) .withStartupTimeout(Duration.ofMinutes(5)) @@ -144,7 +144,8 @@ public GenericContainer build() { .withEnv("SW_APM_EXPORT_LOGS_ENABLED", "true") .withEnv("SW_APM_EXPORT_METRICS_ENABLED", "true") .withEnv("SW_APM_COLLECTOR", System.getenv("SW_APM_COLLECTOR")) - .withEnv("SW_APM_SERVICE_KEY", String.format("%s:%s", System.getenv("SW_APM_SERVICE_KEY"), ServiceNames.SMOKE_TEST)) + .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY")) + .withEnv("OTEL_SERVICE_NAME", ServiceNames.SMOKE_TEST) .withStartupTimeout(Duration.ofMinutes(5)) .withCopyFileToContainer( MountableFile.forHostPath(agentPath), diff --git a/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java b/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java index 3e785921..ee938fe7 100644 --- a/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java +++ b/smoke-tests/src/test/java/com/solarwinds/containers/SpringBootWebMvcContainer.java @@ -82,7 +82,8 @@ public GenericContainer build() { .withEnv("SW_APM_CONFIG_FILE", "/app/apm-config.json") .withEnv("SW_APM_DEBUG_LEVEL", "trace") .withEnv("SW_APM_COLLECTOR", System.getenv("SW_APM_COLLECTOR")) - .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY") + ":java-apm-smoke-test-webmvc") + .withEnv("SW_APM_SERVICE_KEY", System.getenv("SW_APM_SERVICE_KEY")) + .withEnv("OTEL_SERVICE_NAME", "java-apm-smoke-test-webmvc") .withStartupTimeout(Duration.ofMinutes(5)) .withCopyFileToContainer( MountableFile.forHostPath(agentPath), From 42b9b6534763d4dc101c7e5808e2c39d4c8544e9 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Mon, 23 Nov 2026 20:36:41 -0500 Subject: [PATCH 4/5] Internal - Reduce service name wait to 1s --- .../extensions/config/SdkResourceServiceName.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java index a1f1ccd6..2203a9b4 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/config/SdkResourceServiceName.java @@ -27,7 +27,7 @@ * wait for the name to be published. */ public final class SdkResourceServiceName { - private static final long DEFAULT_WAIT_SECONDS = 10; + private static final long DEFAULT_WAIT_SECONDS = 1; private static volatile CompletableFuture serviceName = new CompletableFuture<>(); @@ -39,7 +39,7 @@ public static void set(String name) { serviceName.complete(name); } - /** Returns the published service name, waiting up to 10 seconds on the first call. */ + /** Returns the published service name, waiting up to 1 second on the first call. */ public static String get() { return get(DEFAULT_WAIT_SECONDS, TimeUnit.SECONDS); } From 1241de00e608fc215716553bc08535fa1632eade Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Tue, 24 Nov 2026 10:17:19 -0500 Subject: [PATCH 5/5] Internal - Address review: default after normalization, token-only diagnostics --- .../solarwinds/joboe/config/ServiceKeyUtils.java | 6 +++--- .../joboe/config/ServiceKeyUtilsTest.java | 14 ++++++++++++++ .../core/util/diagnostic/DiagnosticTools.java | 6 +++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java b/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java index 9d4c5b55..b0fd1db8 100644 --- a/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java +++ b/libs/config/src/main/java/com/solarwinds/joboe/config/ServiceKeyUtils.java @@ -72,9 +72,9 @@ public static String getApiKey(String serviceKey) { * #DEFAULT_SERVICE_NAME} when there's none. */ public static String withServiceName(String serviceKey, String serviceName) { - return getApiKey(serviceKey) - + SEPARATOR_CHARACTER - + transformServiceName(serviceNameOrDefault(serviceName)); + // Normalization can empty a name (e.g. only unsupported characters), so default afterwards. + String normalized = isNotBlank(serviceName) ? transformServiceName(serviceName) : null; + return getApiKey(serviceKey) + SEPARATOR_CHARACTER + serviceNameOrDefault(normalized); } public static String serviceNameOrDefault(String serviceName) { diff --git a/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java b/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java index 58b88fb6..ed1bc550 100644 --- a/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java +++ b/libs/config/src/test/java/com/solarwinds/joboe/config/ServiceKeyUtilsTest.java @@ -92,4 +92,18 @@ void transformServiceKeyNormalizesServiceName() { void transformServiceKeyKeepsTokenOnlyKey() { assertEquals("token", ServiceKeyUtils.transformServiceKey("token")); } + + @Test + void withServiceNameUsesDefaultWhenNormalizedNameIsEmpty() { + assertEquals("token:unknown_service:java", ServiceKeyUtils.withServiceName("token", "!!!")); + assertEquals("token:unknown_service:java", ServiceKeyUtils.withServiceName("token", "中文")); + } + + @Test + void withServiceNameNormalizesLegacyServiceKeyName() { + assertEquals( + "token:legacy-name", + ServiceKeyUtils.withServiceName( + "token:Legacy Name", ServiceKeyUtils.getServiceName("token:Legacy Name"))); + } } diff --git a/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java b/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java index 304b6d1b..b6ff1e48 100644 --- a/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java +++ b/libs/core/src/main/java/com/solarwinds/joboe/core/util/diagnostic/DiagnosticTools.java @@ -328,7 +328,11 @@ private static Result testServiceKey(String serviceKey) { Client client = null; try { - client = RpcClientManager.getClient(OperationType.STATUS, serviceKey); + client = + RpcClientManager.getClient( + OperationType.STATUS, + ServiceKeyUtils.withServiceName( + serviceKey, ServiceKeyUtils.getServiceName(serviceKey))); com.solarwinds.joboe.core.rpc.Result rpcCallResult = client.postStatus(generateDiagnosticMessage(), null).get(timeout, TimeUnit.MILLISECONDS);