Skip to content

Commit 0a7b046

Browse files
committed
[#12457] Backport: Add S3(Simple Storage Service) client plugin
1 parent 657a444 commit 0a7b046

File tree

28 files changed

+1100
-0
lines changed

28 files changed

+1100
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ profiler.mongo.tracebsonbindvalue=true
835835
# For example, the settings for profiler.jdbc.xxx=true/false and profiler.jdbc.xxx.tracesqlbindvalue=true/false are also used by R2DBC.
836836
profiler.spring.data.r2dbc.enable=true
837837

838+
###########################################################
839+
# S3(Simple Storage Service)
840+
###########################################################
841+
# Amazon SDK v2 S3
842+
profiler.aws.sdk.s3.enable=true
843+
# Allow profiling status code value.
844+
profiler.aws.sdk.s3.statuscode=true
845+
# Mark error
846+
profiler.aws.sdk.s3.mark.error=true
847+
# Cannot be used with the Apache HttpClient 4.x or JDK HttpURLConnection.
848+
# Use the -Dprofiler.apache.httpclient4.enable=false or -Dprofiler.jdk.http=false setting.
849+
838850
###########################################################
839851
# Apache HTTP Client 3.x #
840852
###########################################################

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,18 @@ profiler.mongo.tracebsonbindvalue=true
832832
# For example, the settings for profiler.jdbc.xxx=true/false and profiler.jdbc.xxx.tracesqlbindvalue=true/false are also used by R2DBC.
833833
profiler.spring.data.r2dbc.enable=true
834834

835+
###########################################################
836+
# S3(Simple Storage Service)
837+
###########################################################
838+
# Amazon SDK v2 S3
839+
profiler.aws.sdk.s3.enable=true
840+
# Allow profiling status code value.
841+
profiler.aws.sdk.s3.statuscode=true
842+
# Mark error
843+
profiler.aws.sdk.s3.mark.error=true
844+
# Cannot be used with the Apache HttpClient 4.x or JDK HttpURLConnection.
845+
# Use the -Dprofiler.apache.httpclient4.enable=false or -Dprofiler.jdk.http=false setting.
846+
835847
###########################################################
836848
# Apache HTTP Client 3.x #
837849
###########################################################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2018 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.navercorp.pinpoint.bootstrap.plugin.request;
18+
19+
public interface ClientDatabaseRequestAdaptor<T> {
20+
21+
/**
22+
* The DestinationId is logical name of the destination.
23+
* <p>
24+
*
25+
* @return If the value does not exist, it should return "UNKNOWN".
26+
*/
27+
String getDestinationId(T request);
28+
29+
/**
30+
* URL
31+
*
32+
* @return If the value does not exist, it should return null.
33+
*/
34+
String getEndPoint(T request);
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2018 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.navercorp.pinpoint.bootstrap.plugin.request;
18+
19+
import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder;
20+
import com.navercorp.pinpoint.bootstrap.logging.PluginLogManager;
21+
import com.navercorp.pinpoint.bootstrap.logging.PluginLogger;
22+
23+
import java.util.Objects;
24+
25+
public class ClientDatabaseRequestRecorder<T> {
26+
private static final String DEFAULT = "UNKNOWN";
27+
28+
private final PluginLogger logger = PluginLogManager.getLogger(this.getClass());
29+
private final boolean isDebug = logger.isDebugEnabled();
30+
31+
private final ClientDatabaseRequestAdaptor<T> requestAdaptor;
32+
33+
public ClientDatabaseRequestRecorder(ClientDatabaseRequestAdaptor<T> requestAdaptor) {
34+
this.requestAdaptor = Objects.requireNonNull(requestAdaptor, "clientRequestAdaptor");
35+
}
36+
37+
// Records the client's request information.
38+
public void record(final SpanEventRecorder recorder, final T clientRequest) {
39+
if (recorder == null || clientRequest == null) {
40+
return;
41+
}
42+
43+
final String destinationId = requestAdaptor.getDestinationId(clientRequest);
44+
if (destinationId != null) {
45+
recorder.recordDestinationId(destinationId);
46+
if (isDebug) {
47+
logger.debug("Record destinationId={}", destinationId);
48+
}
49+
} else {
50+
// Set default value
51+
recorder.recordDestinationId(DEFAULT);
52+
if (isDebug) {
53+
logger.debug("Record destinationId={}", DEFAULT);
54+
}
55+
}
56+
57+
final String endPoint = requestAdaptor.getEndPoint(clientRequest);
58+
if (endPoint != null) {
59+
recorder.recordEndPoint(endPoint);
60+
if (isDebug) {
61+
logger.debug("Record endPoint={}", endPoint);
62+
}
63+
} else {
64+
// Set default value
65+
recorder.recordEndPoint(DEFAULT);
66+
if (isDebug) {
67+
logger.debug("Record endPoint={}", DEFAULT);
68+
}
69+
}
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2018 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.navercorp.pinpoint.bootstrap.plugin.request;
18+
19+
public interface ClientDatabaseRequestWrapper {
20+
21+
/**
22+
* The DestinationId is logical name of the destination.
23+
* <p>
24+
*
25+
* @return If the value does not exist, it should return "UNKNOWN".
26+
*/
27+
String getDestinationId();
28+
29+
/**
30+
* EndPoint
31+
*
32+
* @return If the value does not exist, it should return null.
33+
*/
34+
String getEndPoint();
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2018 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.navercorp.pinpoint.bootstrap.plugin.request;
18+
19+
public class ClientDatabaseRequestWrapperAdaptor implements ClientDatabaseRequestAdaptor<ClientDatabaseRequestWrapper> {
20+
21+
public static final ClientDatabaseRequestAdaptor<ClientDatabaseRequestWrapper> INSTANCE = new ClientDatabaseRequestWrapperAdaptor();
22+
23+
@Override
24+
public String getDestinationId(ClientDatabaseRequestWrapper request) {
25+
return request.getDestinationId();
26+
}
27+
28+
@Override
29+
public String getEndPoint(ClientDatabaseRequestWrapper request) {
30+
return request.getEndPoint();
31+
}
32+
}

agent-module/plugins/assembly/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@
437437
<artifactId>pinpoint-ktor-plugin</artifactId>
438438
<version>${project.version}</version>
439439
</dependency>
440+
<dependency>
441+
<groupId>com.navercorp.pinpoint</groupId>
442+
<artifactId>pinpoint-aws-sdk-s3-plugin</artifactId>
443+
<version>${project.version}</version>
444+
</dependency>
440445
<!-- <dependency>-->
441446
<!-- <groupId>com.navercorp.pinpoint</groupId>-->
442447
<!-- <artifactId>pinpoint-spring-stub</artifactId>-->
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## AWS SDK S3
2+
* Since: Pinpoint 3.1.0
3+
* See: https://github.com/aws/aws-sdk-java-v2/
4+
5+
### Pinpoint Configuration
6+
pinpoint.config
7+
8+
#### Set enable options.
9+
~~~
10+
# Amazon SDK v2 S3
11+
profiler.aws.sdk.s3.enable=true
12+
# Allow profiling status code value.
13+
profiler.aws.sdk.s3.statuscode=true
14+
# Mark error
15+
profiler.aws.sdk.s3.mark.error=true
16+
# Cannot be used with the Apache HttpClient 4.x library.
17+
# Use the -Dprofiler.apache.httpclient4.enable=false setting.
18+
~~~
19+
20+
### Trace
21+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.3-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>pinpoint-aws-sdk-s3-plugin</artifactId>
12+
<name>pinpoint-aws-sdk-s3-plugin</name>
13+
<packaging>jar</packaging>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.navercorp.pinpoint</groupId>
18+
<artifactId>pinpoint-bootstrap-core</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>software.amazon.awssdk</groupId>
24+
<artifactId>s3</artifactId>
25+
<version>2.31.31</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
</dependencies>
29+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.navercorp.pinpoint.plugin.aws.sdk.s3;
18+
19+
import com.navercorp.pinpoint.common.trace.ServiceType;
20+
import com.navercorp.pinpoint.common.trace.ServiceTypeProvider;
21+
22+
public class AwsSdkS3Constants {
23+
public static final ServiceType AWS_SDK_S3 = ServiceTypeProvider.getByName("AWS_SDK_S3");
24+
public static final ServiceType AWS_SDK_S3_INTERNAL = ServiceTypeProvider.getByName("AWS_SDK_S3_INTERNAL");
25+
}

0 commit comments

Comments
 (0)