Skip to content

Commit

Permalink
[pinpoint-apm#11399] Add ktor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Aug 23, 2024
1 parent 9ddc23a commit a724544
Show file tree
Hide file tree
Showing 31 changed files with 1,642 additions and 0 deletions.
111 changes: 111 additions & 0 deletions agent-module/agent-testweb/ktor-plugin-testweb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-agent-testweb</artifactId>
<version>3.0.1-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-ktor-plugin-testweb</artifactId>

<packaging>jar</packaging>

<properties>
<pinpoint.agent.jvmargument>
${pinpoint.agent.default.jvmargument}
</pinpoint.agent.jvmargument>
<kotlin.version>2.0.0</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-status-pages</artifactId>
<version>2.3.12</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>2.3.12</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-config-yaml-jvm</artifactId>
<version>2.3.12</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-tests-jvm</artifactId>
<version>2.3.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-core-jvm -->
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-core-jvm</artifactId>
<version>2.3.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-cio-jvm -->
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-cio-jvm</artifactId>
<version>2.3.12</version>
</dependency>


<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 NAVER Corp.
*
* 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.
*/

package com.pinpoint.test.plugin

import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*

fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
.start(wait = true)
}

fun Application.module() {
configureRouting()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2024 NAVER Corp.
*
* 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.
*/

package com.pinpoint.test.plugin

import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.http.content.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Application.configureRouting() {
install(StatusPages) {
exception<IllegalStateException> { call, cause ->
call.respondText("App in illegal state as ${cause.message}")
}
}
routing {
staticResources("/content", "mycontent")

get("/") {
call.respondText("Hello World!")
}

get("/test1") {
val text = "<h1>Hello From Ktor</h1>"
val type = ContentType.parse("text/html")
call.respondText(text, type)
}
get("/client") {
val client = HttpClient(CIO)
val response: HttpResponse = client.get("https://ktor.io/")
println(response.status)
client.close()
call.respondText(response.toString())
}

get("/error-test") {
throw IllegalStateException("Too Busy")
}
}
}
1 change: 1 addition & 0 deletions agent-module/agent-testweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<module>okhttp-plugin-testweb</module>
<module>grpc-plugin-testweb</module>
<module>resilience4j-plugin-testweb</module>
<module>ktor-plugin-testweb</module>
<module>closed-module-testweb</module>
<module>closed-module-testlib</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,34 @@ profiler.reactor-netty.client.mark.error.transport.error=false
profiler.reactor-netty.client.trace.http.error=true
profiler.reactor-netty.client.mark.error.http.error=false

###########################################################
# Ktor
###########################################################
profiler.ktor.enable=true

# Server
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
profiler.ktor.server.bootstrap.main=
# trace param in request ,default value is true
profiler.ktor.server.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.ktor.server.excludeurl=
# profiler.ktor.server.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.ktor.server.excludemethod=

# original IP address header
# https://en.wikipedia.org/wiki/X-Forwarded-For
#profiler.ktor.server.realipheader=X-Forwarded-For
# nginx real ip header
#profiler.ktor.server.realipheader=X-Real-IP
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
#profiler.ktor.server.realipemptyvalue=unknown

# Retransform
profiler.ktor.http.server.retransform.configure-routing=true

###########################################################
# JSP #
###########################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,34 @@ profiler.reactor-netty.client.mark.error.transport.error=false
profiler.reactor-netty.client.trace.http.error=false
profiler.reactor-netty.client.mark.error.http.error=false

###########################################################
# Ktor
###########################################################
profiler.ktor.enable=false

# Server
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
profiler.ktor.server.bootstrap.main=
# trace param in request ,default value is true
profiler.ktor.server.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.ktor.server.excludeurl=
# profiler.ktor.server.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.ktor.server.excludemethod=

# original IP address header
# https://en.wikipedia.org/wiki/X-Forwarded-For
#profiler.ktor.server.realipheader=X-Forwarded-For
# nginx real ip header
#profiler.ktor.server.realipheader=X-Real-IP
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
#profiler.ktor.server.realipemptyvalue=unknown

# Retransform
profiler.ktor.http.server.retransform.configure-routing=true

###########################################################
# JSP #
###########################################################
Expand Down
5 changes: 5 additions & 0 deletions agent-module/plugins/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@
<artifactId>pinpoint-spring-cloud-sleuth-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-ktor-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.navercorp.pinpoint</groupId>-->
<!-- <artifactId>pinpoint-spring-stub</artifactId>-->
Expand Down
38 changes: 38 additions & 0 deletions agent-module/plugins/ktor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Ktor
* Since: Pinpoint 3.0.1
* See: https://ktor.io/

### Pinpoint Configuration
pinpoint.config

#### Set enable options.
~~~
###########################################################
# Ktor
###########################################################
profiler.ktor.enable=false
# Server
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
profiler.ktor.server.bootstrap.main=
# trace param in request ,default value is true
profiler.ktor.server.tracerequestparam=true
# URLs to exclude from tracing.
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
profiler.ktor.server.excludeurl=
# profiler.ktor.server.trace.excludemethod=
# HTTP Request methods to exclude from tracing
#profiler.ktor.server.excludemethod=
# original IP address header
# https://en.wikipedia.org/wiki/X-Forwarded-For
#profiler.ktor.server.realipheader=X-Forwarded-For
# nginx real ip header
#profiler.ktor.server.realipheader=X-Real-IP
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
#profiler.ktor.server.realipemptyvalue=unknown
# Retransform
profiler.ktor.http.server.retransform.configure-routing=true
~~~
59 changes: 59 additions & 0 deletions agent-module/plugins/ktor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-plugins</artifactId>
<version>3.0.1-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-ktor-plugin</artifactId>
<name>pinpoint-ktor-plugin</name>
<packaging>jar</packaging>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-common-servlet</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>2.3.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>2.3.12</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<includes>
<include>com/navercorp/**/*</include>
<include>META-INF/**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit a724544

Please sign in to comment.