-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trace context propagation in atomic steps
- Loading branch information
Showing
12 changed files
with
400 additions
and
42 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...n/java/io/jenkins/plugins/opentelemetry/init/StepExecutionInstrumentationInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The Original Author or Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.jenkins.plugins.opentelemetry.init; | ||
|
||
import hudson.Extension; | ||
import hudson.util.ClassLoaderSanityThreadFactory; | ||
import hudson.util.DaemonThreadFactory; | ||
import hudson.util.NamingThreadFactory; | ||
import io.jenkins.plugins.opentelemetry.api.OpenTelemetryLifecycleListener; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
@Extension | ||
public class StepExecutionInstrumentationInitializer implements OpenTelemetryLifecycleListener { | ||
|
||
final static Logger logger = Logger.getLogger(StepExecutionInstrumentationInitializer.class.getName()); | ||
|
||
@Override | ||
public void afterConfiguration(@Nonnull ConfigProperties configProperties) { | ||
try { | ||
logger.log(Level.FINE, () -> "Instrumenting " + SynchronousNonBlockingStepExecution.class.getName() + "..."); | ||
Class<SynchronousNonBlockingStepExecution> synchronousNonBlockingStepExecutionClass = SynchronousNonBlockingStepExecution.class; | ||
Arrays.stream(synchronousNonBlockingStepExecutionClass.getDeclaredFields()).forEach(field -> logger.log(Level.FINE, () -> "Field: " + field.getName())); | ||
Field executorServiceField = synchronousNonBlockingStepExecutionClass.getDeclaredField("executorService"); | ||
executorServiceField.setAccessible(true); | ||
ExecutorService executorService = (ExecutorService) Optional.ofNullable(executorServiceField.get(null)).orElseGet(() -> Executors.newCachedThreadPool(new NamingThreadFactory(new ClassLoaderSanityThreadFactory(new DaemonThreadFactory()), "org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution"))); | ||
ExecutorService instrumentedExecutorService = Context.taskWrapping(executorService); | ||
executorServiceField.set(null, instrumentedExecutorService); | ||
|
||
// org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.runner | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.