-
Notifications
You must be signed in to change notification settings - Fork 141
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 #93 from newrelic/spring-webflux
Spring webflux
- Loading branch information
Showing
31 changed files
with
572 additions
and
219 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
This product contains a modified part of OpenTelemetry: | ||
|
||
* License: | ||
|
||
Copyright 2019 The OpenTelemetry Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
in compliance with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
* Homepage: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/LICENSE |
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,31 @@ | ||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("io.projectreactor.ipc:reactor-netty:0.7.0.RELEASE") | ||
} | ||
|
||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
compileTestJava { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
compileJava.options.bootstrapClasspath = null | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.netty-reactor-0.7.0' } | ||
} | ||
|
||
verifyInstrumentation { | ||
// Capped for the compatibility docs plugin | ||
passesOnly 'io.projectreactor.ipc:reactor-netty:[0.7.0.RELEASE,0.7.15.RELEASE]' | ||
|
||
// New Versions 0.8.0+ moved here | ||
fails 'io.projectreactor.netty:reactor-netty:[0.8.0.RELEASE,)' | ||
} | ||
|
||
site { | ||
title 'Netty Reactor' | ||
type 'Appserver' | ||
} |
98 changes: 98 additions & 0 deletions
98
instrumentation/netty-reactor-0.7.0/src/main/java/io/netty/TokenLinkingSubscriber.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,98 @@ | ||
package io.netty; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
import reactor.core.CoreSubscriber; | ||
import reactor.core.Fuseable; | ||
import reactor.core.Scannable; | ||
import reactor.core.publisher.Operators; | ||
import reactor.util.context.Context; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
// Based on OpenTelemetry code | ||
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/instrumentation-core/reactor-3.1/src/main/java/io/opentelemetry/instrumentation/reactor/TracingSubscriber.java | ||
public class TokenLinkingSubscriber<T> implements CoreSubscriber<T> { | ||
private final Token token; | ||
private final Subscriber<? super T> subscriber; | ||
private Context context; | ||
|
||
public TokenLinkingSubscriber(Subscriber<? super T> subscriber, Context ctx) { | ||
this.subscriber = subscriber; | ||
this.context = ctx; | ||
// newrelic-token is added by spring-webflux-5.1 instrumentation | ||
this.token = ctx.getOrDefault("newrelic-token", null); | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Subscription subscription) { | ||
subscriber.onSubscribe(subscription); | ||
} | ||
|
||
@Override | ||
public void onNext(T o) { | ||
withNRToken(() -> subscriber.onNext(o)); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
withNRError(() -> subscriber.onError(throwable), throwable); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
subscriber.onComplete(); | ||
} | ||
|
||
@Override | ||
public Context currentContext() { | ||
return context; | ||
} | ||
|
||
@Trace(async = true, excludeFromTransactionTrace = true) | ||
private void withNRToken(Runnable runnable) { | ||
if (token != null && AgentBridge.getAgent().getTransaction(false) == null) { | ||
token.link(); | ||
} | ||
runnable.run(); | ||
} | ||
|
||
@Trace(async = true, excludeFromTransactionTrace = true) | ||
private void withNRError(Runnable runnable, Throwable throwable) { | ||
if (token != null && token.isActive()) { | ||
token.linkAndExpire(); | ||
NewRelic.noticeError(throwable); | ||
} | ||
runnable.run(); | ||
} | ||
|
||
public static <T> Function<? super Publisher<T>, ? extends Publisher<T>> tokenLift() { | ||
return Operators.lift(new TokenLifter<>()); | ||
} | ||
|
||
private static class TokenLifter<T> | ||
implements BiFunction<Scannable, CoreSubscriber<? super T>, CoreSubscriber<? super T>> { | ||
|
||
public TokenLifter() { | ||
} | ||
|
||
@Override | ||
public CoreSubscriber<? super T> apply(Scannable publisher, CoreSubscriber<? super T> sub) { | ||
// if Flux/Mono #just, #empty, #error | ||
if (publisher instanceof Fuseable.ScalarCallable) { | ||
return sub; | ||
} | ||
Token token = sub.currentContext().getOrDefault("newrelic-token", null); | ||
if (token != null ) { | ||
return new TokenLinkingSubscriber<>(sub, sub.currentContext()); | ||
} | ||
return sub; | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
...ation/netty-reactor-0.7.0/src/main/java/reactor/core/publisher/Hooks_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,12 @@ | ||
package reactor.core.publisher; | ||
|
||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Weave(originalName = "reactor.core.publisher.Hooks") | ||
public abstract class Hooks_Instrumentation { | ||
@NewField | ||
public static AtomicBoolean instrumented = new AtomicBoolean(false); | ||
} |
File renamed without changes.
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,17 @@ | ||
This product contains a modified part of OpenTelemetry: | ||
|
||
* License: | ||
|
||
Copyright 2019 The OpenTelemetry Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
in compliance with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
* Homepage: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/LICENSE |
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
98 changes: 98 additions & 0 deletions
98
...ctor-0.8.0/src/main/java/com/nr/instrumentation/reactor/netty/TokenLinkingSubscriber.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,98 @@ | ||
package com.nr.instrumentation.reactor.netty; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Token; | ||
import com.newrelic.api.agent.Trace; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
import reactor.core.CoreSubscriber; | ||
import reactor.core.Fuseable; | ||
import reactor.core.Scannable; | ||
import reactor.core.publisher.Operators; | ||
import reactor.util.context.Context; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
// Based on OpenTelemetry code | ||
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/instrumentation-core/reactor-3.1/src/main/java/io/opentelemetry/instrumentation/reactor/TracingSubscriber.java | ||
public class TokenLinkingSubscriber<T> implements CoreSubscriber<T> { | ||
private final Token token; | ||
private final Subscriber<? super T> subscriber; | ||
private Context context; | ||
|
||
public TokenLinkingSubscriber(Subscriber<? super T> subscriber, Context ctx) { | ||
this.subscriber = subscriber; | ||
this.context = ctx; | ||
// newrelic-token is added by spring-webflux-5.1 instrumentation | ||
this.token = ctx.getOrDefault("newrelic-token", null); | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Subscription subscription) { | ||
subscriber.onSubscribe(subscription); | ||
} | ||
|
||
@Override | ||
public void onNext(T o) { | ||
withNRToken(() -> subscriber.onNext(o)); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
withNRError(() -> subscriber.onError(throwable), throwable); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
subscriber.onComplete(); | ||
} | ||
|
||
@Override | ||
public Context currentContext() { | ||
return context; | ||
} | ||
|
||
@Trace(async = true, excludeFromTransactionTrace = true) | ||
private void withNRToken(Runnable runnable) { | ||
if (token != null && AgentBridge.getAgent().getTransaction(false) == null) { | ||
token.link(); | ||
} | ||
runnable.run(); | ||
} | ||
|
||
@Trace(async = true, excludeFromTransactionTrace = true) | ||
private void withNRError(Runnable runnable, Throwable throwable) { | ||
if (token != null && token.isActive()) { | ||
token.linkAndExpire(); | ||
NewRelic.noticeError(throwable); | ||
} | ||
runnable.run(); | ||
} | ||
|
||
public static <T> Function<? super Publisher<T>, ? extends Publisher<T>> tokenLift() { | ||
return Operators.lift(new TokenLifter<>()); | ||
} | ||
|
||
private static class TokenLifter<T> | ||
implements BiFunction<Scannable, CoreSubscriber<? super T>, CoreSubscriber<? super T>> { | ||
|
||
public TokenLifter() { | ||
} | ||
|
||
@Override | ||
public CoreSubscriber<? super T> apply(Scannable publisher, CoreSubscriber<? super T> sub) { | ||
// if Flux/Mono #just, #empty, #error | ||
if (publisher instanceof Fuseable.ScalarCallable) { | ||
return sub; | ||
} | ||
Token token = sub.currentContext().getOrDefault("newrelic-token", null); | ||
if (token != null ) { | ||
return new TokenLinkingSubscriber<>(sub, sub.currentContext()); | ||
} | ||
return sub; | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
...y-reactor-0.8.0/src/main/java/io/netty/channel/ChannelHandlerContext_Instrumentation.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
...n/netty-reactor-0.8.0/src/main/java/io/netty/channel/ChannelPipeline_Instrumentation.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.