-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the OTelSdkProvider
into an implementation of OpenTelemetry
#704
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b3556b2
Cleanup OTelSdkProvider
cyrille-leclerc 2394b80
merge master
cyrille-leclerc 55a78df
Cleanup OTelSdkProvider
cyrille-leclerc 5eb9f7e
Merge branch 'master' into cleanup-otel-provider
cyrille-leclerc c4e88e8
Cleanup OTelSdkProvider
cyrille-leclerc d350353
Merge branch 'master' into cleanup-otel-provider
cyrille-leclerc 16f15ad
Merge branch 'master' into cleanup-otel-provider
cyrille-leclerc db9f6b1
merge master branch
cyrille-leclerc 4563cb5
Merge branch 'master' into cleanup-otel-provider
cyrille-leclerc 5094187
Cleanup OTelSdkProvider
cyrille-leclerc 0fbe955
Cleanup OTelSdkProvider
cyrille-leclerc f80b493
Merge branch 'master' into cleanup-otel-provider
cyrille-leclerc 4001b38
Merge master
cyrille-leclerc d6ab809
Merge master
cyrille-leclerc a67e5cf
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc 03028bd
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc 1c8693d
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc 9def781
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc 34102f2
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc a702d36
Merge branch 'main' into cleanup-otel-provider
cyrille-leclerc d0c9ca4
Add reconfigurability of the TraceProvider, LoggerProvider, and Even…
cyrille-leclerc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
127 changes: 127 additions & 0 deletions
127
src/main/java/io/jenkins/plugins/opentelemetry/JenkinsControllerOpenTelemetry.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,127 @@ | ||
/* | ||
* Copyright The Original Author or Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.jenkins.plugins.opentelemetry; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Preconditions; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import io.jenkins.plugins.opentelemetry.opentelemetry.ReconfigurableOpenTelemetry; | ||
import io.jenkins.plugins.opentelemetry.semconv.JenkinsOtelSemanticAttributes; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.incubator.events.EventLogger; | ||
import io.opentelemetry.api.incubator.events.GlobalEventLoggerProvider; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.instrumentation.resources.ProcessResourceProvider; | ||
import io.opentelemetry.sdk.OpenTelemetrySdk; | ||
|
||
import javax.annotation.PreDestroy; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* {@link OpenTelemetry} instance intended to live on the Jenkins Controller. | ||
*/ | ||
@Extension | ||
public class JenkinsControllerOpenTelemetry extends ReconfigurableOpenTelemetry implements OpenTelemetry { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(JenkinsControllerOpenTelemetry.class.getName()); | ||
|
||
/** | ||
* See {@code OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS} | ||
*/ | ||
public static final String DEFAULT_OTEL_JAVA_DISABLED_RESOURCE_PROVIDERS = ProcessResourceProvider.class.getName(); | ||
|
||
public final static AtomicInteger INSTANCE_COUNTER = new AtomicInteger(0); | ||
|
||
@NonNull | ||
private final transient Tracer defaultTracer; | ||
protected transient Meter defaultMeter; | ||
protected final transient EventLogger defaultEventLogger; | ||
|
||
public JenkinsControllerOpenTelemetry() { | ||
super(); | ||
if (INSTANCE_COUNTER.get() > 0) { | ||
LOGGER.log(Level.WARNING, "More than one instance of JenkinsControllerOpenTelemetry created: " + INSTANCE_COUNTER.get()); | ||
} | ||
|
||
String opentelemetryPluginVersion = OtelUtils.getOpentelemetryPluginVersion(); | ||
|
||
this.defaultTracer = | ||
getTracerProvider() | ||
.tracerBuilder(JenkinsOtelSemanticAttributes.INSTRUMENTATION_NAME) | ||
.setInstrumentationVersion(opentelemetryPluginVersion) | ||
.build(); | ||
|
||
this.defaultEventLogger = getEventLoggerProvider() | ||
.eventLoggerBuilder(JenkinsOtelSemanticAttributes.INSTRUMENTATION_NAME) | ||
.setInstrumentationVersion(opentelemetryPluginVersion) | ||
.build(); | ||
} | ||
|
||
@NonNull | ||
public Tracer getDefaultTracer() { | ||
return defaultTracer; | ||
} | ||
|
||
public boolean isLogsEnabled() { | ||
String otelLogsExporter = config.getString("otel.logs.exporter"); | ||
return otelLogsExporter != null && !otelLogsExporter.equals("none"); | ||
} | ||
|
||
public boolean isOtelLogsMirrorToDisk() { | ||
String otelLogsExporter = config.getString("otel.logs.mirror_to_disk"); | ||
return otelLogsExporter != null && otelLogsExporter.equals("true"); | ||
} | ||
|
||
@VisibleForTesting | ||
@NonNull | ||
protected OpenTelemetrySdk getOpenTelemetrySdk() { | ||
Preconditions.checkNotNull(getOpenTelemetryDelegate()); | ||
if (getOpenTelemetryDelegate() instanceof OpenTelemetrySdk) { | ||
return (OpenTelemetrySdk) getOpenTelemetryDelegate(); | ||
} else { | ||
throw new IllegalStateException("OpenTelemetry initialized as NoOp"); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void shutdown() { | ||
super.close(); | ||
} | ||
|
||
public void initialize(@NonNull OpenTelemetryConfiguration configuration) { | ||
configure( | ||
configuration.toOpenTelemetryProperties(), | ||
configuration.toOpenTelemetryResource()); | ||
} | ||
|
||
@Override | ||
protected void postOpenTelemetrySdkConfiguration() { | ||
String opentelemetryPluginVersion = OtelUtils.getOpentelemetryPluginVersion(); | ||
|
||
this.defaultMeter = getMeterProvider() | ||
.meterBuilder(JenkinsOtelSemanticAttributes.INSTRUMENTATION_NAME) | ||
.setInstrumentationVersion(opentelemetryPluginVersion) | ||
.build(); | ||
|
||
LOGGER.log(Level.FINER, () -> "Configure OpenTelemetryLifecycleListeners: " + ExtensionList.lookup(OpenTelemetryLifecycleListener.class).stream().sorted().map(e -> e.getClass().getName()).collect(Collectors.joining(", "))); | ||
ExtensionList.lookup(OpenTelemetryLifecycleListener.class).stream() | ||
.sorted() | ||
.forEachOrdered(otelComponent -> { | ||
otelComponent.afterSdkInitialized(defaultMeter, getOpenTelemetryDelegate().getLogsBridge(), defaultEventLogger, defaultTracer, config); | ||
otelComponent.afterSdkInitialized(getOpenTelemetryDelegate(), config); | ||
}); | ||
} | ||
|
||
static public JenkinsControllerOpenTelemetry get() { | ||
return ExtensionList.lookupSingleton(JenkinsControllerOpenTelemetry.class); | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before system config loaded? how will the configuration be available for this plugin? and how will someone configure this plugin with JCasC if its so early?
jcasc is after system config loaded:
https://github.com/jenkinsci/configuration-as-code-plugin/blob/3b0e6de4ab83e8024e6cac635728c28b68ac663a/plugin/src/main/java/io/jenkins/plugins/casc/ConfigurationAsCode.java#L337
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct: There reasons is:
OpenTelemetry
, even when getting this OpenTelemetry instance throughGlobalOpenTelemetry.get()
DatabaseSchemaLoader#migrateSchema()
of the JUnit SQL Storage Plugin is invoked by Jenkins before the Jenkins OTel Plugin initialization codeJenkinsOpenTelemetryPluginConfiguration#initializeOpenTelemetry()
despite the dependency.The solution we identified is to:
GlobalOpenTelemetry
as early as possible in Jenkin's lifecycle with a NoOp implementation (seeinitializeOpenTelemetryAfterExtensionsAugmented()
).initializeOpenTelemetry()
)I think we can cleanup a bit this code but it works and it was quite time consuming to get there :-)
Dos it make sense?
https://github.com/jenkinsci/junit-sql-storage-plugin/blob/76cefd5f4cf6117553fa6f219442a9cbba64b458/src/main/java/io/jenkins/plugins/junit/storage/database/DatabaseSchemaLoader.java#L24-L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see bit confusing but it'll work I think