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

WIP:Add OSGi support to OpenTelemetry project #4627

Closed
wants to merge 10 commits into from

Conversation

LWogan
Copy link

@LWogan LWogan commented Jul 20, 2022

Use bnd plugin to add OSGi metdata to manifest files to allow them to be used within an OSGi framework

@LWogan LWogan requested a review from a user July 20, 2022 18:08
@LWogan LWogan requested a review from Oberon00 as a code owner July 20, 2022 18:08
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 20, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@jkwatson
Copy link
Contributor

@LWogan before we can look at this or accept it, we need you to sign the CLA. Thanks!

@codecov
Copy link

codecov bot commented Jul 20, 2022

Codecov Report

Merging #4627 (baf0eb4) into main (d84a111) will decrease coverage by 0.00%.
The diff coverage is n/a.

❗ Current head baf0eb4 differs from pull request most recent head a5110ce. Consider uploading reports for the commit a5110ce to get more accurate results

@@             Coverage Diff              @@
##               main    #4627      +/-   ##
============================================
- Coverage     90.04%   90.03%   -0.01%     
+ Complexity     5058     5057       -1     
============================================
  Files           581      581              
  Lines         15591    15591              
  Branches       1491     1491              
============================================
- Hits          14039    14038       -1     
  Misses         1100     1100              
- Partials        452      453       +1     
Impacted Files Coverage Δ
...ava/io/opentelemetry/sdk/internal/RateLimiter.java 94.11% <0.00%> (-5.89%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d84a111...a5110ce. Read the comment docs.

@jkwatson
Copy link
Contributor

I know virtually nothing about OSGi, but this looks ok to me on its surface. @jack-berg do you have any experience with OSGi, or know anyone we can rope in to help?

@LWogan
Copy link
Author

LWogan commented Jul 21, 2022

To add a little explanation of what did does. The bnd instruction will generate OSGi metadata and add it to the manifest files of each jar. OSGi is a framework which relies on this metadata to functionally operate. The OpenTelemetry artifacts cannot be used by anyone running in an OSGi framework without this.

There was some logic already present in the project to set specific manifest attributes, I have preserved these by instructing the bnd operation to add them while adding its automatically generated OSGi metadata.

@LWogan LWogan changed the title Add OSGi support to OpenTelemetry project WIP:Add OSGi support to OpenTelemetry project Jul 21, 2022
@LWogan LWogan marked this pull request as draft July 21, 2022 14:00
Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

I'm not familiar with OSGi but I asked around New Relic and a couple peek took a glance and said it looks innocent.

For reference, here's what the :api jar manifest looks like before:

Manifest-Version: 1.0
Automatic-Module-Name: io.opentelemetry.api
Built-By: jberg
Built-JDK: 11.0.15
Implementation-Title: all
Implementation-Version: 1.17.0-SNAPSHOT

and after:

Manifest-Version: 1.0
Automatic-Module-Name: io.opentelemetry.api
Bnd-LastModified: 1658958870198
Built-By: jberg
Built-JDK: 11.0.15
Bundle-ManifestVersion: 2
Bundle-Name: opentelemetry-api
Bundle-SymbolicName: opentelemetry-api
Bundle-Version: 1.17.0.SNAPSHOT
Created-By: 11.0.15 (Eclipse Adoptium)
Implementation-Title: all
Implementation-Version: 1.17.0-SNAPSHOT
Import-Package: io.opentelemetry.context,io.opentelemetry.context.prop
 agation,io.opentelemetry.sdk.autoconfigure,javax.annotation;version="
 [3.0,4)"
Private-Package: io.opentelemetry.api,io.opentelemetry.api.baggage,io.
 opentelemetry.api.baggage.propagation,io.opentelemetry.api.common,io.
 opentelemetry.api.internal,io.opentelemetry.api.metrics,io.openteleme
 try.api.trace,io.opentelemetry.api.trace.propagation,io.opentelemetry
 .api.trace.propagation.internal
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-6.3.1.202206071316

Comment on lines 15 to 17
// When updating, update above in plugins too
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:6.3.1")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.4.2")
Copy link
Member

Choose a reason for hiding this comment

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

The comment applies to the spotless plugin. Should change the order to restore it.

Suggested change
// When updating, update above in plugins too
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:6.3.1")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.4.2")
// When updating, update above in plugins too
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.4.2")
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:6.3.1")

@@ -126,6 +124,15 @@ tasks {
}
}

named("jar", Jar::class.java) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment indicating that this adds required OSGi metadata to the jar manifest?

…portable from other modules. Various modules within this repo have packages with the namespace internal which are exposed via the apis of non internal classes and therefore had to be exposed
@LWogan
Copy link
Author

LWogan commented Jul 28, 2022

@jack-berg Ive made some additional changes. I needed to add annotations to numerous package-info files. This informs the OSGi framework that these packages are available for use by other jars. Worth noting some packages marked with the namespace internal have been included as some of their classes are on the APIs of classes in other packages.

Another point to add is this PR will add support to this project for OSGi. However there are numerous dependencies such as io.grpc (and its transitive dependencies) which also do not have OSGi support. There are workarounds to this but I thought I should point that out.

Leaving as a draft for now as I am still integrating OpenTelemetry into an OSGi project so I might not have worked out all the issues yet.

@jack-berg jack-berg self-requested a review July 28, 2022 15:20
@splatch
Copy link

splatch commented Aug 8, 2022

I was able to test it and I believe it needs a second touch. Import of javax.annotation package should be marked as optional. Otherwise runtime environment is forced to host findbugs which is strictly speaking build time dependency/tool which does not serve any purpose for execution of byte code.

@splatch
Copy link

splatch commented Aug 9, 2022

@jack-berg Looking at this again (on top of 0.16) I think there are more things to tackle within library design itself.

The SpanExporterConfiguration introduces a lookup of a specific implementations from a dependency consumed in opentelemetry-api module:

Its not quite clear to me why such design exists. With such way in place you tie autconfigure module with all listed spi providers. Effectively it is not possible to separate api from specific implementations as bndtools which generates OSGi metadata is able to spot somehow Class.forName and refered class names. Effectively it causes direct listing of such packages as import statements for for sdk-extensions-autoconfigure, which is used by api. Wouldn't it be better to have some kind of ExporterFactory looked up through ServiceLoader first and then let it configure specific exporter through passed properties?

Any use of Class.forName(String) without a ClassLoader is a trouble marker under OSGi cause it will fail in most of the cases:

Such patterns work fine with single classloader which is used with flat classpath, but will certainly fail with hierarchical classloaders and osgi which has multiple classloaders. For simplicity of understanding - under OSGi each bundle (deployed jar) have its own classloader exposing only declared import statements.

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Aug 23, 2022
@jack-berg
Copy link
Member

Its not quite clear to me why such design exists.

Hi @splatch - sorry for the delayed reply. Not sure what the best answer is here, but I can provide some context. The autoconfigure is responsible for configuring an OpenTelemetrySdk instance based on system properties and env vars. The components it configures includes exporters for specific protocols, such as zipkin, jaeger, prometheus, otlp, etc. Autoconfigure doesn't want to impose transitive dependencies on those exporters, since users will likely only need one or two and the others would just result in unnecessary bulk. So instead it places compileOnly dependencies on these components, and executes the configuration logic for each conditionally based on its presence on the classpath.

The advantage of this is that configuration lives in one place, instead of being scattered around each of the components. Not sure how you could accomplish this with the ExporterFactory pattern you describe, but admittedly I may not be fully grasping your suggestion.

@github-actions github-actions bot removed the Stale label Aug 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2022

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 6, 2022
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Sep 20, 2022
@PascalDutch
Copy link

Hi, why is this never merged? We are also looking for functionality like this, since we want to use OpenTelemetry in an OSGi context.

@LWogan
Copy link
Author

LWogan commented Oct 25, 2022

Hi, why is this never merged? We are also looking for functionality like this, since we want to use OpenTelemetry in an OSGi context.

From my perspective the pr is incomplete. Needs more testing and probably more changes.

The package structures of this Otel project means if you want to pull in a single lib then you pretty much have to pull in every other subproject due to the internal dependency tree with each subproject having some package import from another. This is a frustration when you only wish to use a subset of bundles.

Also, unfortunately, many of OpenTelems dependencies and also transient dependencies are not OSGi bundles which makes it very difficult to use this library within an OSGi context even with this PR applied.

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.

5 participants