Skip to content

Add OSGi support for library instrumentation, API, and SDK extension artifacts#18995

Open
royteeuwen wants to merge 5 commits into
open-telemetry:mainfrom
royteeuwen:osgi-support
Open

Add OSGi support for library instrumentation, API, and SDK extension artifacts#18995
royteeuwen wants to merge 5 commits into
open-telemetry:mainfrom
royteeuwen:osgi-support

Conversation

@royteeuwen

@royteeuwen royteeuwen commented Jun 14, 2026

Copy link
Copy Markdown

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.instrumentation library, 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-support
  • all library instrumentations (instrumentation/**/library, via otel.library-instrumentation)
  • SDK extensions (resources, runtime-telemetry, via otel.sdk-extension)

Javaagent and shadowed artifacts are intentionally left untouched.

How

  • Added the bnd Gradle plugin (biz.aQute.bnd:biz.aQute.bnd.gradle:7.3.0) to the convention build, mirroring opentelemetry-java.
  • New otel.osgi-conventions convention plugin configures the jar task's bnd bundle block: -exportcontents: io.opentelemetry.*, an Import-Package that makes javax.annotation (and per-module osgiOptionalPackages) optional, and -metainf-services: auto so SPI providers in META-INF/services (including AutoService-generated ones like the resources ResourceProviders) become OSGi Provide-Capability headers.
  • OtelJavaExtension gains osgiEnabled (default true, per-module opt-out) and osgiOptionalPackages.
  • The plugin is applied via otel.library-instrumentation + otel.sdk-extension and the four standalone API/annotation modules.

Tests

New osgi-test module that boots a real OSGi container (Apache Felix + Aries SPI Fly) and runs JUnit 5 tests inside it, via bnd's BundleResolveTestOSGi tasks (modeled on opentelemetry-java's integration-tests/osgi). Suites:

  • apiinstrumentation-api + -api-incubator + -annotations: context propagation, builds an Instrumenter, references @WithSpan.
  • apacheHttpClientApacheHttpClientTelemetry resolved against the stock Apache httpclient-osgi/httpcore-osgi bundles.
  • logbackAppender — the appender resolves without the optional Logstash encoder present (validating the osgiOptionalPackages tuning).
  • resources — asserts the AutoService 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

  • osgiOptionalPackages currently 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).
  • The osgi-test apacheHttpClient suite pulls httpclient-osgi/httpcore-osgi non-transitively because their POMs also drag in the plain (non-OSGi) httpclient/httpcore jars, which otherwise shadow the bundles in the resolver.

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.
Copilot AI review requested due to automatic review settings June 14, 2026 17:49
@royteeuwen royteeuwen requested a review from a team as a code owner June 14, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 + new otelJava extension knobs (osgiEnabled, osgiOptionalPackages) to generate OSGi manifest metadata via Bnd.
  • Add :osgi-test integration 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.

Comment thread conventions/src/main/kotlin/otel.osgi-conventions.gradle.kts Outdated
…assert concrete class resource in logback test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSGi support

2 participants