diff --git a/modules/nextflow/src/main/groovy/nextflow/util/SimpleHttpClient.groovy b/modules/nextflow/src/main/groovy/nextflow/util/SimpleHttpClient.groovy index 07ac305fa6..00124f1392 100644 --- a/modules/nextflow/src/main/groovy/nextflow/util/SimpleHttpClient.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/util/SimpleHttpClient.groovy @@ -122,6 +122,7 @@ class SimpleHttpClient { con.setRequestMethod(method) con.setRequestProperty("Content-Type", contentType) con.setRequestProperty("User-Agent", userAgent) + con.setRequestProperty("Traceparent", TraceUtils.nextTrace()) // set charset if( charset ) con.setRequestProperty("charset", "utf-8") diff --git a/modules/nf-commons/src/main/nextflow/util/TraceUtils.groovy b/modules/nf-commons/src/main/nextflow/util/TraceUtils.groovy new file mode 100644 index 0000000000..000a2ac1f9 --- /dev/null +++ b/modules/nf-commons/src/main/nextflow/util/TraceUtils.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2024, Seqera Labs + * + * 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 nextflow.util + +import groovy.transform.CompileStatic + +/** + * + * @author Paolo Di Tommaso + */ +@CompileStatic +class TraceUtils { + + static String nextTrace() { + final traceId = UUID.randomUUID().toString().replace("-", "").substring(0, 32) + final spanId = UUID.randomUUID().toString().replace("-", "").substring(0, 16) + return String.format("00-%s-%s-01", traceId, spanId) + } + +} diff --git a/modules/nf-commons/src/test/nextflow/util/TraceUtilsTest.groovy b/modules/nf-commons/src/test/nextflow/util/TraceUtilsTest.groovy new file mode 100644 index 0000000000..6614d2c992 --- /dev/null +++ b/modules/nf-commons/src/test/nextflow/util/TraceUtilsTest.groovy @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2024, Seqera Labs + * + * 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 nextflow.util + +import spock.lang.Specification + +/** + * + * @author Paolo Di Tommaso + */ +class TraceUtilsTest extends Specification { + + def 'should create a traceparent string' () { + when: + def trace = TraceUtils.nextTrace() + then: + trace =~ /00-[a-f0-9]{32}-[a-f0-9]{16}-01/ + } + +} diff --git a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy index 89cbb3fe4d..5295a54b9e 100644 --- a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy +++ b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy @@ -68,6 +68,7 @@ import nextflow.processor.TaskRun import nextflow.script.bundle.ResourcesBundle import nextflow.util.SysHelper import nextflow.util.Threads +import nextflow.util.TraceUtils import org.slf4j.Logger import org.slf4j.LoggerFactory /** @@ -290,12 +291,13 @@ class WaveClient { request.towerAccessToken = accessToken request.towerRefreshToken = refreshToken + final trace = TraceUtils.nextTrace() final body = JsonOutput.toJson(request) final uri = URI.create("${endpoint}/v1alpha2/container") log.debug "Wave request: $uri; attempt=$attempt - request: $request" final req = HttpRequest.newBuilder() .uri(uri) - .headers('Content-Type','application/json') + .headers('Content-Type','application/json', 'Traceparent', trace) .POST(HttpRequest.BodyPublishers.ofString(body)) .build()