Repository: helidon-io/helidon (java)

Issue:
4.x webserver testing documentation issue
## Environment Details
* Helidon Version: 4.0.1
* Helidon SE
* OS: Windows
* Java
----------

## Problem Description
Documentation https://helidon.io/docs/v4/#/se/testing states the following:
> In addition, a static method annotated with @SetUpServer can be defined for @ServerTest, which has a single parameter of WebServer.Builder.

But `WebServer `doen't exist in `io.helidon.webserver.testing.junit5:helidon-webserver-testing-junit5:4.0.1`.

So it should be:
> In addition, a static method annotated with @SetUpServer can be defined for @ServerTest, which has a single parameter of WebServerConfig.Builder.

Pull request:
4.x: Docs: change WebServer.Builder to WebServerConfig.Builder.
### Description

Change occurrences of `WebServer.Builder ` to `WebServerConfig.Builder`

Fixes #8168

### Documentation

Fixes a doc bug

Patch:
diff --git a/.github/workflows/create-backport-issues.yml b/.github/workflows/create-backport-issues.yml
index c9c103efa4..5548be0748 100644
--- a/.github/workflows/create-backport-issues.yml
+++ b/.github/workflows/create-backport-issues.yml
@@ -9,7 +9,25 @@ on:
       version:
         description: 'Helidon version this issue was reported for'
         required: true
+        type: choice
+        options:
+          - 2.x
+          - 3.x
+          - 4.x
         default: '2.x'
+      target-2:
+        type: boolean
+        description: 'Port to 2.x?'
+        default:  false
+      target-3:
+        type: boolean
+        description: 'Port to 3.x?'
+        default: true
+      target-4:
+        type: boolean
+        description: 'Port to 4.x?'
+        default: true
+
 env:
   GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}
 
@@ -20,4 +38,4 @@ jobs:
     steps:
       - name: Check out repository code
         uses: actions/checkout@v2
-      - run: etc/scripts/actions/create-backport-issues.sh $GITHUB_REPOSITORY ${{ github.event.inputs.issue }} ${{ github.event.inputs.version }}
+      - run: etc/scripts/actions/create-backport-issues.sh $GITHUB_REPOSITORY ${{ github.event.inputs.issue }} ${{ github.event.inputs.version }} ${{ github.event.inputs.target-2 }} ${{ github.event.inputs.target-3 }} ${{ github.event.inputs.target-4 }}
diff --git a/docs/src/main/asciidoc/se/guides/health.adoc b/docs/src/main/asciidoc/se/guides/health.adoc
index 82df96fe9d..ad0bfe0297 100644
--- a/docs/src/main/asciidoc/se/guides/health.adoc
+++ b/docs/src/main/asciidoc/se/guides/health.adoc
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
-    Copyright (c) 2019, 2023 Oracle and/or its affiliates.
+    Copyright (c) 2019, 2024 Oracle and/or its affiliates.
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -176,7 +176,7 @@ You can add your own custom health checks. These typically assess the conditions
 The following trivial but illustrative example adds a custom start-up check that reports `DOWN` until the server has been running for eight seconds and reports `UP` thereafter. Note the two main steps in the example code:
 
 1. Create an explicit instance of `ObserveFeature` which contains a custom `HealthObserver` with the custom check.
-2. Add that `ObserveFeature` instance to the `WebServer.Builder` as a feature.
+2. Add that `ObserveFeature` instance to the `WebServerConfig.Builder` as a feature.
 
 
 [source,java]
diff --git a/etc/scripts/actions/create-backport-issues.sh b/etc/scripts/actions/create-backport-issues.sh
index 5925ff8c1b..12e1ae9cf1 100755
--- a/etc/scripts/actions/create-backport-issues.sh
+++ b/etc/scripts/actions/create-backport-issues.sh
@@ -1,6 +1,6 @@
 #!/bin/bash -l
 #
-# Copyright (c) 2022 Oracle and/or its affiliates.
+# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -38,8 +38,8 @@ readonly REPOSITORY_FULL_NAME="$1"
 readonly ISSUE_NUMBER="$2"
 readonly HELIDON_VERSION="$3"
 
-if [ -z "${REPOSITORY_FULL_NAME}" -o -z "${ISSUE_NUMBER}" -o -z "${HELIDON_VERSION}" ]; then
-  echo "usage: $0 <repository-name> <issue-number> <helidon-version>"
+if [ -z "${REPOSITORY_FULL_NAME}" -o -z "${ISSUE_NUMBER}" -o -z "${HELIDON_VERSION}" -o $# -le 3 ]; then
+  echo "usage: $0 <repository-name> <issue-number> <helidon-version> <helidon-versions-to-port-to...>"
   exit 1
 fi
 
@@ -112,11 +112,15 @@ fi
 issue_title=$(sed "s/\"/'/g" <<< "$issue_title")
 
 ############################################################
-# For each version that is not the issue's version, add backport
+# For each version the caller specified add a porting issue.
 ############################################################
-for version in ${VERSIONS[@]}; do
-  if [ "$version" != "$HELIDON_VERSION" ]; then
-    # Create issue for all other versions and add the same labels and assignee
+version_targets=()
+next_version_to_check=2
+for is_version_selected in "${@:4}"; do
+  version=${next_version_to_check}.x
+  next_version_to_check=$((next_version_to_check+1))
+  if [ "$version" != "$HELIDON_VERSION" -a "$is_version_selected" = "true" ]; then
+    # Create issue for other indicated versions and add the same labels and assignee
     new_issue_title="[$version] ${issue_title}"
     new_issue_text="Backport of #${ISSUE_NUMBER} for Helidon ${version}"
 
diff --git a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java
index a2907af39d..d5349accb5 100644
--- a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java
+++ b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, 2022 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2024 Oracle and/or its affiliates.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -58,18 +58,32 @@ final class TracerProviderHelper {
     }
 
     public static Optional<Span> currentSpan() {
-        return TRACER_PROVIDER.currentSpan();
+        /*
+        If a custom TracerProvider implementation indirectly tries to access the current span (for example, by triggering custom
+        logging that adds the current span to each message), then this method can be invoked before the static initializer has
+        completed and, therefore, before TRACER_PROVIDER is assigned.
+         */
+        return (TRACER_PROVIDER == null) ? Optional.empty() : TRACER_PROVIDER.currentSpan();
     }
 
     static Tracer global() {
+        if (TRACER_PROVIDER == null) {
+            throw new IllegalStateException("Use before initialization has completed");
+        }
         return TRACER_PROVIDER.global();
     }
 
     static void global(Tracer tracer) {
+        if (TRACER_PROVIDER == null) {
+            throw new IllegalStateException("Use before initialization has completed");
+        }
         TRACER_PROVIDER.global(tracer);
     }
 
     static TracerBuilder<?> findTracerBuilder() {
+        if (TRACER_PROVIDER == null) {
+            throw new IllegalStateException("Use before initialization has completed");
+        }
         return TRACER_PROVIDER.createBuilder();
     }
 }


Test patch:
diff --git a/docs/src/main/asciidoc/se/testing.adoc b/docs/src/main/asciidoc/se/testing.adoc
index db7f71379b..c1d89f807c 100644
--- a/docs/src/main/asciidoc/se/testing.adoc
+++ b/docs/src/main/asciidoc/se/testing.adoc
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 
-    Copyright (c) 2023 Oracle and/or its affiliates.
+    Copyright (c) 2023, 2024 Oracle and/or its affiliates.
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -24,6 +24,8 @@
 :feature-name: Helidon Testing Framework
 :rootdir: {docdir}/..
 
+include::{rootdir}/includes/se.adoc[]
+
 == Contents
 
 - <<Overview, Overview>>
@@ -98,7 +100,7 @@ and may have any name. The `@SetUpRoute` annotation has `value` with socket name
 
 |===
 
-In addition, a static method annotated with `@SetUpServer` can be defined for `@ServerTest`, which has a single parameter of `WebServer.Builder`.
+In addition, a static method annotated with `@SetUpServer` can be defined for `@ServerTest`, which has a single parameter of link:{javadoc-base-url}/io.helidon.webserver/io/helidon/webserver/WebServerConfig.Builder.html[`WebServerConfig.Builder`].
 
 The following table lists the injectable types (through constructor or method injection).
 
diff --git a/tracing/tracing/src/test/java/io/helidon/tracing/TestEarlyUseOfSpanCurrent.java b/tracing/tracing/src/test/java/io/helidon/tracing/TestEarlyUseOfSpanCurrent.java
new file mode 100644
index 0000000000..1150ade91d
--- /dev/null
+++ b/tracing/tracing/src/test/java/io/helidon/tracing/TestEarlyUseOfSpanCurrent.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024 Oracle and/or its affiliates.
+ *
+ * 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 io.helidon.tracing;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+class TestEarlyUseOfSpanCurrent {
+
+    @Test
+    void ensureCurrentSpanNonNull() {
+
+        Span.current(); // Trigger the service loading of the test provider which will itself invoke Span.current().
+        assertThat("Early current span", TestTracerProvider.earlyCurrentSpan(), notNullValue());
+    }
+}
diff --git a/tracing/tracing/src/test/java/io/helidon/tracing/TestTracerProvider.java b/tracing/tracing/src/test/java/io/helidon/tracing/TestTracerProvider.java
new file mode 100644
index 0000000000..66abd44691
--- /dev/null
+++ b/tracing/tracing/src/test/java/io/helidon/tracing/TestTracerProvider.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2024 Oracle and/or its affiliates.
+ *
+ * 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 io.helidon.tracing;
+
+import java.util.Optional;
+
+/**
+ * Approximates the behavior of a custom tracer provider with a constructor that invokes a logger which invokes Span.current().
+ */
+public class TestTracerProvider extends NoOpTracerProvider {
+
+    private static Optional<Span> earlyCurrentSpan;
+
+    public TestTracerProvider() {
+        Optional<Span> currentSpan;
+        try {
+            currentSpan = Span.current();
+        } catch (NullPointerException e) {
+            // silent
+            currentSpan = null;
+        }
+        earlyCurrentSpan = currentSpan;
+    }
+
+    static Optional<Span> earlyCurrentSpan() {
+        return earlyCurrentSpan;
+    }
+}
diff --git a/tracing/tracing/src/test/resources/META-INF/services/io.helidon.tracing.spi.TracerProvider b/tracing/tracing/src/test/resources/META-INF/services/io.helidon.tracing.spi.TracerProvider
new file mode 100644
index 0000000000..d11cd06103
--- /dev/null
+++ b/tracing/tracing/src/test/resources/META-INF/services/io.helidon.tracing.spi.TracerProvider
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2024 Oracle and/or its affiliates.
+#
+# 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.
+#
+io.helidon.tracing.TestTracerProvider
\ No newline at end of file