### Question:
ServletTransactionHelper { public static void determineServiceName(@Nullable String servletContextName, @Nullable ClassLoader servletContextClassLoader, @Nullable String contextPath) { if (servletContextClassLoader == null || nameInitialized.putIfAbsent(servletContextClassLoader, Boolean.TRUE) != null) { return; } @Nullable String serviceName = servletContextName; if ("application".equals(serviceName) || "".equals(serviceName) || "/".equals(serviceName)) { serviceName = null; } if (serviceName == null && contextPath != null && !contextPath.isEmpty()) { serviceName = contextPath.substring(1); } if (serviceName != null) { GlobalTracer.get().overrideServiceNameForClassLoader(servletContextClassLoader, serviceName); } } ServletTransactionHelper(ElasticApmTracer tracer); static void determineServiceName(@Nullable String servletContextName, @Nullable ClassLoader servletContextClassLoader, @Nullable String contextPath); void fillRequestContext(Transaction transaction, String protocol, String method, boolean secure,
                                   String scheme, String serverName, int serverPort, String requestURI, String queryString,
                                   String remoteAddr, @Nullable String contentTypeHeader); static void setUsernameIfUnset(@Nullable String userName, TransactionContext context); void onAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status,
                        boolean overrideStatusCodeOnThrowable, String method, @Nullable Map<String, String[]> parameterMap,
                        @Nullable String servletPath, @Nullable String pathInfo, @Nullable String contentTypeHeader, boolean deactivate); boolean captureParameters(String method, @Nullable String contentTypeHeader); static void setTransactionNameByServletClass(@Nullable String method, @Nullable Class<?> servletClass, Transaction transaction); boolean isCaptureHeaders(); static final String TRANSACTION_ATTRIBUTE; static final String ASYNC_ATTRIBUTE; }### Answer:
@Test void testServiceNameConsistencyAcrossDifferentClassLoaders() { final String testContext = "test-context"; final String testContextPath = "test-context-path"; URLClassLoader cl1 = new URLClassLoader(new URL[0]); ServletTransactionHelper.determineServiceName(testContext, cl1, testContextPath); tracer.startRootTransaction(cl1).end(); URLClassLoader cl2 = new URLClassLoader(new URL[0]); ServletTransactionHelper.determineServiceName(testContext, cl2, testContextPath); tracer.startRootTransaction(cl2).end(); assertThat(reporter.getTransactions().stream() .filter(transaction -> testContext.equals(transaction.getTraceContext().getServiceName())) .count() ).isEqualTo(2); }