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

Resolves various thread hop problems with Spring Reactor call chaining. #1883

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package reactor.core.publisher;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.MonoSubscribeOn")
abstract class MonoSubscribeOn_Instrumentation {

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber")
static final class SubscribeOnSubscriber_Instrumentation {
@NewField
private Token token;

@WeaveAllConstructors
SubscribeOnSubscriber_Instrumentation() {
if (NewRelic.getAgent().getTransaction() != null && token == null) {
token = NewRelic.getAgent().getTransaction().getToken();
}
}

public void run () {
if (token != null) {
Boolean result = token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}

public void cancel () {
if (token != null) {
token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package reactor.core.publisher;

import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.FluxMapFuseable")
abstract class FluxMapFuseable_Instrumentation {

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber")
static final class MapFuseableSubscriber_Instrumentation<T, R> {
@NewField
private Token token;

@WeaveAllConstructors
MapFuseableSubscriber_Instrumentation() {
if (AgentBridge.getAgent().getTransaction(false) != null && token == null) {
token = NewRelic.getAgent().getTransaction().getToken();
}
}

public void onComplete() {
if (token != null) {
token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}

public void onNext(T t) {
if (token != null) {
token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}

public void onError(Throwable t) {
if (token != null) {
token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package reactor.core.publisher;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.MonoSubscribeOn")
abstract class MonoSubscribeOn_Instrumentation {

@Weave(type = MatchType.ExactClass, originalName = "reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber")
static final class SubscribeOnSubscriber_Instrumentation {
@NewField
private Token token;

@WeaveAllConstructors
SubscribeOnSubscriber_Instrumentation() {
if (NewRelic.getAgent().getTransaction() != null && token == null) {
token = NewRelic.getAgent().getTransaction().getToken();
}
}

public void run () {
if (token != null) {
Boolean result = token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}

public void cancel () {
if (token != null) {
token.linkAndExpire();
token = null;
}
Weaver.callOriginal();
}
}
}
Loading