Add OSGi support for library instrumentation, API, and SDK extension artifacts#18995
Open
royteeuwen wants to merge 5 commits into
Open
Add OSGi support for library instrumentation, API, and SDK extension artifacts#18995royteeuwen wants to merge 5 commits into
royteeuwen wants to merge 5 commits into
Conversation
Generate OSGi bundle metadata (via the bnd gradle plugin) for every published io.opentelemetry.instrumentation library: the instrumentation-api/annotations modules, all library instrumentations, and SDK extensions. This lets them be consumed directly in OSGi runtimes, replacing external wrapper bundles. - conventions: add bnd dependency, osgiEnabled/osgiOptionalPackages on OtelJavaExtension, and a new otel.osgi-conventions plugin applied via otel.library-instrumentation, otel.sdk-extension and the four API modules. Javaagent/shadowed artifacts are intentionally left untouched. - SPI capabilities are auto-generated from META-INF/services (-metainf-services: auto). - osgi-test: new module that boots Apache Felix + Aries SPI Fly and runs JUnit 5 tests inside the container (api, logbackAppender, resources suites).
…che OSGi bundles The apache-httpclient-4.3 suite now boots Felix and runs ApacheHttpClientTelemetry against the stock org.apache.httpcomponents.httpclient/httpcore OSGi bundles - the same bundles AEM/Sling provide. They are pulled non-transitively because their POMs also drag in the plain (non-OSGi) httpclient/httpcore jars, which otherwise shadow the bundles in the resolver and leave org.apache.http unexported. All four suites (api, apacheHttpClient, logbackAppender, resources) now pass fully in-container.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds OSGi bundle metadata generation for published library artifacts and introduces a dedicated :osgi-test module to verify that the produced bundles resolve and run in an Apache Felix OSGi container (including SPI Fly ServiceLoader mediation).
Changes:
- Introduce
otel.osgi-conventions+ newotelJavaextension knobs (osgiEnabled,osgiOptionalPackages) to generate OSGi manifest metadata via Bnd. - Add
:osgi-testintegration test module with multiple OSGi suites (api, apacheHttpClient, logbackAppender, resources). - Adjust specific instrumentation metadata (e.g., logback appender optional imports) and centralize OSGi test dependency versions.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| settings.gradle.kts | Registers the new :osgi-test module in the build. |
| osgi-test/build.gradle.kts | Adds Gradle+Bnd wiring to generate/resolve/run OSGi test suites under Felix/SPI Fly. |
| osgi-test/src/testApi/.../ApiOsgiTest.java | Verifies core API/annotations are usable inside OSGi. |
| osgi-test/src/testApacheHttpClient/.../ApacheHttpClientOsgiTest.java | Verifies Apache HttpClient telemetry bundle works in OSGi. |
| osgi-test/src/testLogbackAppender/.../LogbackAppenderOsgiTest.java | Verifies logback appender resolves without optional Logstash packages. |
| osgi-test/src/testResources/.../ResourcesOsgiTest.java | Verifies AutoService/SPI metadata is bridged to OSGi services via SPI Fly. |
| conventions/src/main/kotlin/otel.osgi-conventions.gradle.kts | New convention plugin applying Bnd bundle generation to published libraries. |
| conventions/src/main/kotlin/io/.../OtelJavaExtension.kt | Adds OSGi-related extension properties. |
| conventions/build.gradle.kts | Adds the Bnd Gradle plugin dependency used by the new convention. |
| dependencyManagement/build.gradle.kts | Pins versions for OSGi test runtime + JUnit/Bnd tester. |
| conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts | Applies otel.osgi-conventions to library instrumentation modules. |
| conventions/src/main/kotlin/otel.sdk-extension.gradle.kts | Applies otel.osgi-conventions to SDK extension modules. |
| instrumentation-api/build.gradle.kts | Applies otel.osgi-conventions to instrumentation API. |
| instrumentation-api-incubator/build.gradle.kts | Applies otel.osgi-conventions to incubator API. |
| instrumentation-annotations/build.gradle.kts | Applies otel.osgi-conventions to annotations module. |
| instrumentation-annotations-support/build.gradle.kts | Applies otel.osgi-conventions to annotations support module. |
| instrumentation/logback/.../library/build.gradle.kts | Marks Logstash packages as optional OSGi imports. |
…assert concrete class resource in logback test
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #18884.
With open-telemetry/opentelemetry-java#8417 the core modules gained OSGi support. This adds the same for the artifacts published by this repo.
What this does
Generates OSGi bundle metadata (via the bnd Gradle plugin) for every published
io.opentelemetry.instrumentationlibrary, so they can be consumed directly in OSGi runtimes (e.g. Apache Felix / Eclipse Equinox, AEM/Sling) without external wrapper bundles:instrumentation-api,instrumentation-api-incubator,instrumentation-annotations,instrumentation-annotations-supportinstrumentation/**/library, viaotel.library-instrumentation)resources,runtime-telemetry, viaotel.sdk-extension)Javaagent and shadowed artifacts are intentionally left untouched.
How
biz.aQute.bnd:biz.aQute.bnd.gradle:7.3.0) to the convention build, mirroringopentelemetry-java.otel.osgi-conventionsconvention plugin configures thejartask's bndbundleblock:-exportcontents: io.opentelemetry.*, anImport-Packagethat makesjavax.annotation(and per-moduleosgiOptionalPackages) optional, and-metainf-services: autoso SPI providers inMETA-INF/services(including AutoService-generated ones like theresourcesResourceProviders) become OSGiProvide-Capabilityheaders.OtelJavaExtensiongainsosgiEnabled(default true, per-module opt-out) andosgiOptionalPackages.otel.library-instrumentation+otel.sdk-extensionand the four standalone API/annotation modules.Tests
New
osgi-testmodule that boots a real OSGi container (Apache Felix + Aries SPI Fly) and runs JUnit 5 tests inside it, via bnd'sBundle→Resolve→TestOSGitasks (modeled onopentelemetry-java'sintegration-tests/osgi). Suites:instrumentation-api+-api-incubator+-annotations: context propagation, builds anInstrumenter, references@WithSpan.ApacheHttpClientTelemetryresolved against the stock Apachehttpclient-osgi/httpcore-osgibundles.osgiOptionalPackagestuning).ResourceProviders are mediated by SPI Fly (validating-metainf-services: auto).All four suites pass in-container. Additionally, all ~89 OSGi-capable modules were built and verified to produce valid bundles (
Bundle-SymbolicName+Export-Package).Notes / open questions for reviewers
osgiOptionalPackagescurrently tunes the logback appender's optional Logstash import; other modules may need similar per-module tuning, which surfaces as a clear OSGi resolution error (never silent).osgi-testapacheHttpClient suite pullshttpclient-osgi/httpcore-osginon-transitively because their POMs also drag in the plain (non-OSGi)httpclient/httpcorejars, which otherwise shadow the bundles in the resolver.