use of com.megaease.easeagent.plugin.api.Cleaner in project easeagent by megaease.
the class AsyncContextImplTest method importToCurrent.
@Test
public void importToCurrent() {
String name = "test_name";
String value = "test_value";
SessionContext sessionContext = new SessionContext();
AsyncContextImpl asyncContext = AsyncContextImpl.build(NoOpTracer.NO_OP_SPAN_CONTEXT, () -> sessionContext, null);
asyncContext.put(name, value);
assertNull(sessionContext.get(name));
try (Cleaner cleaner = asyncContext.importToCurrent()) {
assertEquals(value, sessionContext.get(name));
}
assertNull(sessionContext.get(name));
AsyncContextImpl asyncContext2 = AsyncContextImpl.build(NoOpTracer.NO_OP_SPAN_CONTEXT, () -> sessionContext, Collections.singletonMap(name, value));
assertNull(sessionContext.get(name));
try (Cleaner cleaner = asyncContext2.importToCurrent()) {
assertEquals(value, sessionContext.get(name));
}
assertNull(sessionContext.get(name));
}
use of com.megaease.easeagent.plugin.api.Cleaner in project easeagent by megaease.
the class DoFilterForwardedInterceptor method doBefore.
@Override
public void doBefore(MethodInfo methodInfo, Context context) {
HttpServletRequest httpServletRequest = (HttpServletRequest) methodInfo.getArgs()[0];
HttpRequest httpRequest = new HttpServerRequest(httpServletRequest);
Cleaner cleaner = context.importForwardedHeaders(httpRequest);
context.put(FORWARDED_KEY, cleaner);
}
use of com.megaease.easeagent.plugin.api.Cleaner in project easeagent by megaease.
the class AsyncResponse4MetricsListener method process.
private void process(Response response, Exception exception) {
try (Cleaner ignored = asyncContext.importToCurrent()) {
Context context = EaseAgent.getContext();
Request request = context.get(REQUEST);
long duration = ContextUtils.getDuration(context);
boolean success = ElasticsearchCtxUtils.checkSuccess(response, exception);
this.elasticsearchMetric.collectMetric(ElasticsearchCtxUtils.getIndex(request.getEndpoint()), duration, success);
}
}
use of com.megaease.easeagent.plugin.api.Cleaner in project easeagent by megaease.
the class AgentMonoTest method testImportToCurrent.
@Test
public void testImportToCurrent() throws InterruptedException {
Context context = EaseAgent.getContext();
Span span = context.nextSpan();
Thread thread;
try (Scope ignored4 = span.maybeScope()) {
AsyncContext asyncContext1 = context.exportAsync();
AsyncContext asyncContext2 = context.exportAsync();
AsyncContext asyncContext3 = context.exportAsync();
thread = new Thread(() -> {
Context asyncContext = EaseAgent.getContext();
assertFalse(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored = asyncContext1.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored1 = asyncContext2.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
try (Cleaner ignored2 = asyncContext3.importToCurrent()) {
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertTrue(asyncContext.currentTracing().hasCurrentSpan());
}
assertFalse(asyncContext.currentTracing().hasCurrentSpan());
});
}
thread.start();
thread.join();
}
use of com.megaease.easeagent.plugin.api.Cleaner in project easeagent by megaease.
the class GatewayServerForwardedInterceptor method doBefore.
@Override
public void doBefore(MethodInfo methodInfo, Context context) {
ServerWebExchange exchange = (ServerWebExchange) methodInfo.getArgs()[0];
FluxHttpServerRequest httpServerRequest = new FluxHttpServerRequest(exchange.getRequest());
Cleaner cleaner = context.importForwardedHeaders(httpServerRequest);
context.put(FORWARDED_KEY, cleaner);
}
Aggregations