All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.javaagent.instrumentation.undertow.HttpServerConnectionInstrumentation Maven / Gradle / Ivy

There is a newer version: 2.8.0-alpha
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.javaagent.instrumentation.undertow;

import static io.opentelemetry.javaagent.instrumentation.undertow.UndertowSingletons.helper;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.undertow.server.HttpServerExchange;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class HttpServerConnectionInstrumentation implements TypeInstrumentation {
  @Override
  public ElementMatcher typeMatcher() {
    return namedOneOf(
        "io.undertow.server.protocol.http.HttpServerConnection",
        "io.undertow.server.protocol.http2.Http2ServerConnection");
  }

  @Override
  public void transform(TypeTransformer transformer) {
    transformer.applyAdviceToMethod(
        named("getSinkConduit")
            .and(takesArgument(0, named("io.undertow.server.HttpServerExchange"))),
        this.getClass().getName() + "$ResponseAdvice");
  }

  @SuppressWarnings("unused")
  public static class ResponseAdvice {

    @Advice.OnMethodEnter(suppress = Throwable.class)
    public static void onEnter(@Advice.Argument(0) HttpServerExchange exchange) {
      Context context = helper().getServerContext(exchange);
      HttpServerResponseCustomizerHolder.getCustomizer()
          .customize(context, exchange, UndertowHttpResponseMutator.INSTANCE);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy