Skip to content
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 21 commits into from
Jun 21, 2024

Conversation

cyrille-leclerc
Copy link
Contributor

@cyrille-leclerc cyrille-leclerc commented Sep 15, 2023

Refactor the OTelSdkProvider to make it an implementation of OpenTelemetry that is intended to live on a Jenkins Controller.

Testing done

Submitter checklist

Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
# Conflicts:
#	src/main/java/io/jenkins/plugins/opentelemetry/OpenTelemetrySdkProvider.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/log/OtelLogStorage.java
#	src/main/java/io/jenkins/plugins/opentelemetry/job/log/OtelLogStorageFactory.java
Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
Signed-off-by: Cyrille Le Clerc <[email protected]>
@cyrille-leclerc cyrille-leclerc marked this pull request as ready for review January 2, 2024 12:12
@cyrille-leclerc cyrille-leclerc changed the title Cleanup OTelSdkProvider Refactor the OTelSdkProvider into an implementation of openTelemetry Jan 2, 2024
kuisathaverat
kuisathaverat previously approved these changes Jan 2, 2024
@cyrille-leclerc cyrille-leclerc marked this pull request as draft June 5, 2024 09:02
# Conflicts:
#	src/main/java/io/jenkins/plugins/opentelemetry/JenkinsOpenTelemetryPluginConfiguration.java
#	src/main/java/io/jenkins/plugins/opentelemetry/OpenTelemetrySdkProvider.java
@cyrille-leclerc cyrille-leclerc marked this pull request as ready for review June 17, 2024 11:11
@cyrille-leclerc cyrille-leclerc changed the title Refactor the OTelSdkProvider into an implementation of openTelemetry Refactor the OTelSdkProvider into an implementation of OpenTelemetry Jun 17, 2024
kuisathaverat
kuisathaverat previously approved these changes Jun 20, 2024
@cyrille-leclerc
Copy link
Contributor Author

Sorry @kuisathaverat I made some changes to better support OTel instrumentation in other plugins. Could you please review again the PR 👼
Note that I have added many unit tests with the last commit

Comment on lines +12 to +18
public class InstrumentationScope {
@Nonnull
final String instrumentationScopeName;
@Nullable
final String schemaUrl;
@Nullable
final String instrumentationScopeVersion;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding a JavaDoc description of the fields and the class

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ReconfigurableEventLoggerProvider implements EventLoggerProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding a JavaDoc description to the class

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ReconfigurableLoggerProvider implements LoggerProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding a JavaDoc description to the class

/**
* Reconfigurable {@link OpenTelemetry}
*/
public class ReconfigurableOpenTelemetry implements OpenTelemetry, Closeable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding a JavaDoc description to the class

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ReconfigurableTracerProvider implements TracerProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding a JavaDoc description to the class

Copy link
Contributor

@kuisathaverat kuisathaverat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments LGTM

@cyrille-leclerc
Copy link
Contributor Author

Thanks, I'll javadoc in a subsequent PR

@cyrille-leclerc cyrille-leclerc merged commit d997f5f into main Jun 21, 2024
14 checks passed
@cyrille-leclerc cyrille-leclerc deleted the cleanup-otel-provider branch June 21, 2024 09:32
* as early as possible in Jenkins lifecycle so any plugin invoking those Global setters will have the
* reconfigurable instance .
*/
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED, before = InitMilestone.SYSTEM_CONFIG_LOADED)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct: There reasons is:

  1. we want to be sure that any plugin that is using OTel will use our implementation of OpenTelemetry, even when getting this OpenTelemetry instance through GlobalOpenTelemetry.get()
  2. we don't know how to ensure the OpenTelemetry plugin gets configured & initialized before all other plugins (e.g. the initialization code DatabaseSchemaLoader#migrateSchema() of the JUnit SQL Storage Plugin is invoked by Jenkins before the Jenkins OTel Plugin initialization code JenkinsOpenTelemetryPluginConfiguration#initializeOpenTelemetry() despite the dependency.

The solution we identified is to:

  1. Register a Reconfigurable OpenTelemetry instance in GlobalOpenTelemetry as early as possible in Jenkin's lifecycle with a NoOp implementation (see initializeOpenTelemetryAfterExtensionsAugmented()).
  2. When the Jenkins Otel Plugin config is ready, we reconfigure the OpenTelmetry instance (see 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

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants