Skip to content

Commit 453eeef

Browse files
committed
[#11399] Add ktor plugin
1 parent 1925030 commit 453eeef

31 files changed

+1642
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<groupId>com.navercorp.pinpoint</groupId>
9+
<artifactId>pinpoint-agent-testweb</artifactId>
10+
<version>3.0.1-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>pinpoint-ktor-plugin-testweb</artifactId>
14+
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<pinpoint.agent.jvmargument>
19+
${pinpoint.agent.default.jvmargument}
20+
</pinpoint.agent.jvmargument>
21+
<kotlin.version>2.0.0</kotlin.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>io.ktor</groupId>
27+
<artifactId>ktor-server-status-pages</artifactId>
28+
<version>2.3.12</version>
29+
<scope>runtime</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.ktor</groupId>
33+
<artifactId>ktor-server-core-jvm</artifactId>
34+
<version>2.3.12</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.ktor</groupId>
38+
<artifactId>ktor-server-netty-jvm</artifactId>
39+
<version>2.3.12</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.ktor</groupId>
43+
<artifactId>ktor-server-config-yaml-jvm</artifactId>
44+
<version>2.3.12</version>
45+
<scope>runtime</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.ktor</groupId>
49+
<artifactId>ktor-server-tests-jvm</artifactId>
50+
<version>2.3.12</version>
51+
</dependency>
52+
<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-core-jvm -->
53+
<dependency>
54+
<groupId>io.ktor</groupId>
55+
<artifactId>ktor-client-core-jvm</artifactId>
56+
<version>2.3.12</version>
57+
</dependency>
58+
<!-- https://mvnrepository.com/artifact/io.ktor/ktor-client-cio-jvm -->
59+
<dependency>
60+
<groupId>io.ktor</groupId>
61+
<artifactId>ktor-client-cio-jvm</artifactId>
62+
<version>2.3.12</version>
63+
</dependency>
64+
65+
66+
<dependency>
67+
<groupId>org.jetbrains.kotlin</groupId>
68+
<artifactId>kotlin-stdlib-jdk8</artifactId>
69+
<version>${kotlin.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.jetbrains.kotlin</groupId>
73+
<artifactId>kotlin-test</artifactId>
74+
<version>${kotlin.version}</version>
75+
<scope>test</scope>
76+
</dependency>
77+
</dependencies>
78+
79+
<build>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.springframework.boot</groupId>
83+
<artifactId>spring-boot-maven-plugin</artifactId>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.jetbrains.kotlin</groupId>
87+
<artifactId>kotlin-maven-plugin</artifactId>
88+
<version>${kotlin.version}</version>
89+
<executions>
90+
<execution>
91+
<id>compile</id>
92+
<phase>compile</phase>
93+
<goals>
94+
<goal>compile</goal>
95+
</goals>
96+
</execution>
97+
<execution>
98+
<id>test-compile</id>
99+
<phase>test-compile</phase>
100+
<goals>
101+
<goal>test-compile</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
<configuration>
106+
<jvmTarget>1.8</jvmTarget>
107+
</configuration>
108+
</plugin>
109+
</plugins>
110+
</build>
111+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.pinpoint.test.plugin
18+
19+
import io.ktor.server.application.*
20+
import io.ktor.server.engine.*
21+
import io.ktor.server.netty.*
22+
23+
fun main() {
24+
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module)
25+
.start(wait = true)
26+
}
27+
28+
fun Application.module() {
29+
configureRouting()
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.pinpoint.test.plugin
18+
19+
import io.ktor.client.*
20+
import io.ktor.client.engine.cio.*
21+
import io.ktor.client.request.*
22+
import io.ktor.client.statement.*
23+
import io.ktor.http.*
24+
import io.ktor.server.application.*
25+
import io.ktor.server.http.content.*
26+
import io.ktor.server.plugins.statuspages.*
27+
import io.ktor.server.response.*
28+
import io.ktor.server.routing.*
29+
30+
fun Application.configureRouting() {
31+
install(StatusPages) {
32+
exception<IllegalStateException> { call, cause ->
33+
call.respondText("App in illegal state as ${cause.message}")
34+
}
35+
}
36+
routing {
37+
staticResources("/content", "mycontent")
38+
39+
get("/") {
40+
call.respondText("Hello World!")
41+
}
42+
43+
get("/test1") {
44+
val text = "<h1>Hello From Ktor</h1>"
45+
val type = ContentType.parse("text/html")
46+
call.respondText(text, type)
47+
}
48+
get("/client") {
49+
val client = HttpClient(CIO)
50+
val response: HttpResponse = client.get("https://ktor.io/")
51+
println(response.status)
52+
client.close()
53+
call.respondText(response.toString())
54+
}
55+
56+
get("/error-test") {
57+
throw IllegalStateException("Too Busy")
58+
}
59+
}
60+
}

agent-module/agent-testweb/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<module>okhttp-plugin-testweb</module>
8989
<module>grpc-plugin-testweb</module>
9090
<module>resilience4j-plugin-testweb</module>
91+
<module>ktor-plugin-testweb</module>
9192
<module>closed-module-testweb</module>
9293
<module>closed-module-testlib</module>
9394
</modules>

agent-module/agent/src/main/resources/profiles/local/pinpoint.config

+28
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,34 @@ profiler.reactor-netty.client.mark.error.transport.error=false
623623
profiler.reactor-netty.client.trace.http.error=true
624624
profiler.reactor-netty.client.mark.error.http.error=false
625625

626+
###########################################################
627+
# Ktor
628+
###########################################################
629+
profiler.ktor.enable=true
630+
631+
# Server
632+
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
633+
profiler.ktor.server.bootstrap.main=
634+
# trace param in request ,default value is true
635+
profiler.ktor.server.tracerequestparam=true
636+
# URLs to exclude from tracing.
637+
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
638+
profiler.ktor.server.excludeurl=
639+
# profiler.ktor.server.trace.excludemethod=
640+
# HTTP Request methods to exclude from tracing
641+
#profiler.ktor.server.excludemethod=
642+
643+
# original IP address header
644+
# https://en.wikipedia.org/wiki/X-Forwarded-For
645+
#profiler.ktor.server.realipheader=X-Forwarded-For
646+
# nginx real ip header
647+
#profiler.ktor.server.realipheader=X-Real-IP
648+
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
649+
#profiler.ktor.server.realipemptyvalue=unknown
650+
651+
# Retransform
652+
profiler.ktor.http.server.retransform.configure-routing=true
653+
626654
###########################################################
627655
# JSP #
628656
###########################################################

agent-module/agent/src/main/resources/profiles/release/pinpoint.config

+28
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,34 @@ profiler.reactor-netty.client.mark.error.transport.error=false
620620
profiler.reactor-netty.client.trace.http.error=false
621621
profiler.reactor-netty.client.mark.error.http.error=false
622622

623+
###########################################################
624+
# Ktor
625+
###########################################################
626+
profiler.ktor.enable=false
627+
628+
# Server
629+
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
630+
profiler.ktor.server.bootstrap.main=
631+
# trace param in request ,default value is true
632+
profiler.ktor.server.tracerequestparam=true
633+
# URLs to exclude from tracing.
634+
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
635+
profiler.ktor.server.excludeurl=
636+
# profiler.ktor.server.trace.excludemethod=
637+
# HTTP Request methods to exclude from tracing
638+
#profiler.ktor.server.excludemethod=
639+
640+
# original IP address header
641+
# https://en.wikipedia.org/wiki/X-Forwarded-For
642+
#profiler.ktor.server.realipheader=X-Forwarded-For
643+
# nginx real ip header
644+
#profiler.ktor.server.realipheader=X-Real-IP
645+
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
646+
#profiler.ktor.server.realipemptyvalue=unknown
647+
648+
# Retransform
649+
profiler.ktor.http.server.retransform.configure-routing=true
650+
623651
###########################################################
624652
# JSP #
625653
###########################################################

agent-module/plugins/assembly/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@
432432
<artifactId>pinpoint-spring-cloud-sleuth-plugin</artifactId>
433433
<version>${project.version}</version>
434434
</dependency>
435+
<dependency>
436+
<groupId>com.navercorp.pinpoint</groupId>
437+
<artifactId>pinpoint-ktor-plugin</artifactId>
438+
<version>${project.version}</version>
439+
</dependency>
435440
<!-- <dependency>-->
436441
<!-- <groupId>com.navercorp.pinpoint</groupId>-->
437442
<!-- <artifactId>pinpoint-spring-stub</artifactId>-->

agent-module/plugins/ktor/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Ktor
2+
* Since: Pinpoint 3.0.1
3+
* See: https://ktor.io/
4+
5+
### Pinpoint Configuration
6+
pinpoint.config
7+
8+
#### Set enable options.
9+
~~~
10+
###########################################################
11+
# Ktor
12+
###########################################################
13+
profiler.ktor.enable=false
14+
15+
# Server
16+
# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported.
17+
profiler.ktor.server.bootstrap.main=
18+
# trace param in request ,default value is true
19+
profiler.ktor.server.tracerequestparam=true
20+
# URLs to exclude from tracing.
21+
# Support ant style pattern. e.g. /aa/*.html, /??/exclude.html
22+
profiler.ktor.server.excludeurl=
23+
# profiler.ktor.server.trace.excludemethod=
24+
# HTTP Request methods to exclude from tracing
25+
#profiler.ktor.server.excludemethod=
26+
27+
# original IP address header
28+
# https://en.wikipedia.org/wiki/X-Forwarded-For
29+
#profiler.ktor.server.realipheader=X-Forwarded-For
30+
# nginx real ip header
31+
#profiler.ktor.server.realipheader=X-Real-IP
32+
# optional parameter, If the header value is ${profiler.ktor.realipemptyvalue}, Ignore header value.
33+
#profiler.ktor.server.realipemptyvalue=unknown
34+
35+
# Retransform
36+
profiler.ktor.http.server.retransform.configure-routing=true
37+
38+
~~~

agent-module/plugins/ktor/pom.xml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>com.navercorp.pinpoint</groupId>
7+
<artifactId>pinpoint-plugins</artifactId>
8+
<version>3.0.1-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>pinpoint-ktor-plugin</artifactId>
12+
<name>pinpoint-ktor-plugin</name>
13+
<packaging>jar</packaging>
14+
15+
<properties>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.navercorp.pinpoint</groupId>
21+
<artifactId>pinpoint-bootstrap-core</artifactId>
22+
<scope>provided</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.navercorp.pinpoint</groupId>
26+
<artifactId>pinpoint-common-servlet</artifactId>
27+
<version>${project.version}</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>io.ktor</groupId>
33+
<artifactId>ktor-server-core-jvm</artifactId>
34+
<version>2.3.12</version>
35+
<scope>provided</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.ktor</groupId>
39+
<artifactId>ktor-server-netty-jvm</artifactId>
40+
<version>2.3.12</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-jar-plugin</artifactId>
50+
<configuration>
51+
<includes>
52+
<include>com/navercorp/**/*</include>
53+
<include>META-INF/**/*</include>
54+
</includes>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
</project>

0 commit comments

Comments
 (0)