Skip to content

Commit b4bf6fd

Browse files
authored
How to make SkyWalking agent works in OSGI environment? (#450)
1 parent 8dde931 commit b4bf6fd

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Release Notes.
1616
#### Documentation
1717
* Update docs of Tracing APIs, reorganize the API docs into six parts.
1818
* Correct missing package name in native manual API docs.
19-
19+
* Add a FAQ doc about "How to make SkyWalking agent works in `OSGI` environment?"
2020

2121
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/168?closed=1)
2222

docs/en/faq/osgi.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## How to make SkyWalking agent works in `OSGI` environment?
2+
3+
`OSGI` implements its own set of [modularity](https://www.osgi.org/resources/modularity/), which means that each `Bundle` has its own unique class loader for isolating different versions of classes.
4+
By default, OSGI runtime uses the boot classloader for the bundle codes, which makes the `java.lang.NoClassDefFoundError` exception in the booting stage.
5+
```
6+
java.lang.NoClassDefFoundError: org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/EnhancedInstance
7+
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:419)
8+
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:383)
9+
at ch.qos.logback.classic.Logger.log(Logger.java:765)
10+
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:216)
11+
at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:771)
12+
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:748)
13+
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
14+
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
15+
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
16+
at by.kolodyuk.osgi.springboot.SpringBootBundleActivator.start(SpringBootBundleActivator.java:21)
17+
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:849)
18+
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2429)
19+
at org.apache.felix.framework.Felix.startBundle(Felix.java:2335)
20+
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1566)
21+
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:297)
22+
at java.base/java.lang.Thread.run(Thread.java:829)
23+
```
24+
25+
### How to resolve this issue?
26+
1. we need to set the parent classloader in `OSGI` to `AppClassLoader`, through the specific parameter `org.osgi.framework.bundle.parent=app`.
27+
The list of parameters can be found in the [OSGI API](https://docs.osgi.org/specification/osgi.core/7.0.0/framework.api.html)
28+
2. Load the `SkyWalking` related classes to the bundle parent class loader, `AppClassLoader`, with the parameter `org.osgi.framework.bootdelegation=org.apache.skywalking.apm.*`
29+
or `org.osgi.framework.bootdelegation=*`. This step is optional. Some OSGi implementations (i.e. Equinox) enable them by default
30+

docs/menu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ catalog:
9696
catalog:
9797
- name: "Why is java.ext.dirs not supported?"
9898
path: "/en/faq/ext-dirs"
99+
- name: "How to make SkyWalking agent works in `OSGI` environment?"
100+
path: "/en/faq/osgi"
99101
- name: "Contribution"
100102
catalog:
101103
- name: "Compiling Guidance"

0 commit comments

Comments
 (0)