forked from newrelic/newrelic-java-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request newrelic#538 from newrelic/spring-security
Spring security
- Loading branch information
Showing
19 changed files
with
222 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Reactor Netty Instrumentation | ||
|
||
Instrumentation for Reactor Netty server and also some widely used Reactor Core library code. | ||
|
||
This module is largely responsible for instrumenting the Reactor Core library to facilitate the passing, retrieval, | ||
and linking of `Tokens` across contexts to tie asynchronous threads together for individual `Transactions`. | ||
|
||
This instrumentation is dependent on other instrumentation modules to start a `Transaction`. | ||
Typically, the `netty-n.n` modules work with this instrumentation and will start a `Transaction` (see `NettyDispatcher#channelRead`). | ||
|
||
Most commonly this instrumentation comes into play with SpringBoot usage, in which case the `spring` and `spring-webflux` | ||
instrumentation modules also apply and should result in `Transactions` being renamed after the Spring controller. | ||
|
||
## Key Components | ||
|
||
* `TokenLinkingSubscriber` | ||
Implementation of a `reactor.core.CoreSubscriber` (a `Context` aware subscriber) that can be added as | ||
a lifecycle hook on `Flux`/`Mono` operators to propagate, retrieve, and link `Tokens` across async contexts. This is done in various places as follows: | ||
|
||
```java | ||
if (!Hooks_Instrumentation.instrumented.getAndSet(true)) { | ||
Hooks.onEachOperator(TokenLinkingSubscriber.class.getName(), tokenLift()); | ||
} | ||
``` | ||
|
||
* `Schedulers_Instrumentation` and `HttpTrafficHandler_Instrumentation` | ||
Both of these classes serve as entry points to add the `TokenLinkingSubscriber` sub-hook. | ||
|
||
* Scheduler `Task`s | ||
Reactor Core Scheduler tasks that execute on asynchronous threads. These are instrumented as points to link `Tokens`. | ||
|
||
## Troubleshooting | ||
|
||
In cases where a `Transaction` gets named `/NettyDispatcher` (or named after a security `Filter`) it usually indicates that context was lost somewhere in | ||
reactor code and that activity on threads where other instrumentation would typically apply could not be linked to the originating `Transaction` thread. | ||
Figuring out how to propagate and link a `Token` across the threads should resolve the issue. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
.../netty-reactor-0.8.0/src/main/java/reactor/core/scheduler/Schedulers_Instrumentation.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package reactor.core.scheduler; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber; | ||
import reactor.core.publisher.Hooks; | ||
import reactor.core.publisher.Hooks_Instrumentation; | ||
|
||
import static com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift; | ||
|
||
@Weave(type = MatchType.BaseClass, originalName = "reactor.core.scheduler.Schedulers") | ||
public abstract class Schedulers_Instrumentation { | ||
|
||
@Weave(type = MatchType.ExactClass, originalName = "reactor.core.scheduler.Schedulers$CachedScheduler") | ||
static class CachedScheduler { | ||
final Scheduler cached; | ||
final String key; | ||
|
||
CachedScheduler(String key, Scheduler cached) { | ||
/* | ||
* Add tokenLift hook if it hasn't already been added. This allows for tokens to be retrieved from | ||
* the current context and linked across threads at various points of the Flux/Mono lifecycle. | ||
* | ||
* When using Netty Reactor with SpringBoot this hook will be added by the HttpTrafficHandler_Instrumentation | ||
* but when using other embedded web servers (e.g. Tomcat, Jetty, Undertow) the HttpTrafficHandler class | ||
* doesn't get loaded and thus the hook isn't added. This ensures that the hook is added in a common code | ||
* path before any Scheduler Tasks are spun off on new threads. | ||
*/ | ||
if (!Hooks_Instrumentation.instrumented.getAndSet(true)) { | ||
Hooks.onEachOperator(TokenLinkingSubscriber.class.getName(), tokenLift()); | ||
} | ||
|
||
this.cached = Weaver.callOriginal(); | ||
this.key = Weaver.callOriginal(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Reactor Netty Instrumentation | ||
|
||
Instrumentation for Reactor Netty server and also some widely used Reactor Core library code. | ||
|
||
This module is largely responsible for instrumenting the Reactor Core library to facilitate the passing, retrieval, | ||
and linking of `Tokens` across contexts to tie asynchronous threads together for individual `Transactions`. | ||
|
||
This instrumentation is dependent on other instrumentation modules to start a `Transaction`. | ||
Typically, the `netty-n.n` modules work with this instrumentation and will start a `Transaction` (see `NettyDispatcher#channelRead`). | ||
|
||
Most commonly this instrumentation comes into play with SpringBoot usage, in which case the `spring` and `spring-webflux` | ||
instrumentation modules also apply and should result in `Transactions` being renamed after the Spring controller. | ||
|
||
## Key Components | ||
|
||
* `TokenLinkingSubscriber` | ||
Implementation of a `reactor.core.CoreSubscriber` (a `Context` aware subscriber) that can be added as | ||
a lifecycle hook on `Flux`/`Mono` operators to propagate, retrieve, and link `Tokens` across async contexts. This is done in various places as follows: | ||
|
||
```java | ||
if (!Hooks_Instrumentation.instrumented.getAndSet(true)) { | ||
Hooks.onEachOperator(TokenLinkingSubscriber.class.getName(), tokenLift()); | ||
} | ||
``` | ||
|
||
* `Schedulers_Instrumentation` and `HttpTrafficHandler_Instrumentation` | ||
Both of these classes serve as entry points to add the `TokenLinkingSubscriber` sub-hook. | ||
|
||
* Scheduler `Task`s | ||
Reactor Core Scheduler tasks that execute on asynchronous threads. These are instrumented as points to link `Tokens`. | ||
|
||
## Troubleshooting | ||
|
||
In cases where a `Transaction` gets named `/NettyDispatcher` (or named after a security `Filter`) it usually indicates that context was lost somewhere in | ||
reactor code and that activity on threads where other instrumentation would typically apply could not be linked to the originating `Transaction` thread. | ||
Figuring out how to propagate and link a `Token` across the threads should resolve the issue. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
.../netty-reactor-0.9.0/src/main/java/reactor/core/scheduler/Schedulers_Instrumentation.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2021 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package reactor.core.scheduler; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber; | ||
import reactor.core.publisher.Hooks; | ||
import reactor.core.publisher.Hooks_Instrumentation; | ||
|
||
import static com.nr.instrumentation.reactor.netty.TokenLinkingSubscriber.tokenLift; | ||
|
||
@Weave(type = MatchType.BaseClass, originalName = "reactor.core.scheduler.Schedulers") | ||
public abstract class Schedulers_Instrumentation { | ||
|
||
@Weave(type = MatchType.ExactClass, originalName = "reactor.core.scheduler.Schedulers$CachedScheduler") | ||
static class CachedScheduler { | ||
final Scheduler cached; | ||
final String stringRepresentation; | ||
|
||
CachedScheduler(String key, Scheduler cached) { | ||
/* | ||
* Add tokenLift hook if it hasn't already been added. This allows for tokens to be retrieved from | ||
* the current context and linked across threads at various points of the Flux/Mono lifecycle. | ||
* | ||
* When using Netty Reactor with SpringBoot this hook will be added by the HttpTrafficHandler_Instrumentation | ||
* but when using other embedded web servers (e.g. Tomcat, Jetty, Undertow) the HttpTrafficHandler class | ||
* doesn't get loaded and thus the hook isn't added. This ensures that the hook is added in a common code | ||
* path before any Scheduler Tasks are spun off on new threads. | ||
*/ | ||
if (!Hooks_Instrumentation.instrumented.getAndSet(true)) { | ||
Hooks.onEachOperator(TokenLinkingSubscriber.class.getName(), tokenLift()); | ||
} | ||
|
||
this.cached = Weaver.callOriginal(); | ||
this.stringRepresentation = Weaver.callOriginal(); | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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