Skip to content

Commit

Permalink
[pinpoint-apm#8472] Support Kotlin Coroutines Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
koo-taejin authored and intr3p1d committed Dec 10, 2021
1 parent 178c7b5 commit 0824ab4
Show file tree
Hide file tree
Showing 14 changed files with 713 additions and 2 deletions.
12 changes: 11 additions & 1 deletion agent/src/main/resources/profiles/local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1247,4 +1247,14 @@ profiler.rocketmq.consumer.enable=false
# Comma separated list of package names
# eg) profiler.rocketmq.basePackage=com.company
# eg) profiler.rocketmq.basePackage=com.company.shopping.cart, com.company.payment
profiler.rocketmq.basePackage=
profiler.rocketmq.basePackage=

###########################################################
# Kotlin Corutines
# v1.0.1 ~
###########################################################
profiler.kotlin.coroutines.enable=false
# Only perfect string matching is supported. (If you do not include any value, it will not be tracked.)
# Comma separated list of coroutines name
# eg) profiler.kotlin.coroutines.name.include=CoroutineMyJob1,CoroutineMyJob2
profiler.kotlin.coroutines.name.include=
12 changes: 11 additions & 1 deletion agent/src/main/resources/profiles/release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1270,4 +1270,14 @@ profiler.rocketmq.consumer.enable=false
# Comma separated list of package names
# eg) profiler.rocketmq.basePackage=com.company
# eg) profiler.rocketmq.basePackage=com.company.shopping.cart, com.company.payment
profiler.rocketmq.basePackage=
profiler.rocketmq.basePackage=

###########################################################
# Kotlin Corutines
# v1.0.1 ~
###########################################################
profiler.kotlin.coroutines.enable=false
# Only perfect string matching is supported. (If you do not include any value, it will not be tracked.)
# Comma separated list of coroutines name
# eg) profiler.kotlin.coroutines.name.include=CoroutineMyJob1,CoroutineMyJob2
profiler.kotlin.coroutines.name.include=
8 changes: 8 additions & 0 deletions plugins/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@
<artifactId>pinpoint-rocketmq-plugin</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-kotlin-coroutines-plugin</artifactId>
<version>${project.version}</version>
</dependency>


</dependencies>

</project>
42 changes: 42 additions & 0 deletions plugins/kotlin-coroutines/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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>2.4.0-SNAPSHOT</version>
</parent>

<artifactId>pinpoint-kotlin-coroutines-plugin</artifactId>
<name>pinpoint-kotlin-coroutines-plugin</name>
<packaging>jar</packaging>

<properties>
<jdk.version>1.8</jdk.version>
<jdk.home>${env.JAVA_8_HOME}</jdk.home>
<sniffer.artifactid>java18</sniffer.artifactid>
</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-annotations</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.5.2</version>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2021 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.navercorp.pinpoint.plugin.kotlinx.coroutines;

import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Taejin Koo
*/
public class CoroutinesConfig {

private final boolean traceCoroutines;
private final List<String> nameIncludeList;

public CoroutinesConfig(ProfilerConfig config) {
this.traceCoroutines = config.readBoolean("profiler.kotlin.coroutines.enable", false);
String nameIncludes = config.readString("profiler.kotlin.coroutines.name.include", "");

if (StringUtils.hasLength(nameIncludes)) {
String[] nameIncludeArray = nameIncludes.split(",");
List<String> result = new ArrayList<>(nameIncludeArray.length);
for (String nameInclude : nameIncludeArray) {
if (StringUtils.hasLength(nameInclude)) {
result.add(nameInclude);
}
}
nameIncludeList = Collections.unmodifiableList(result);
} else {
nameIncludeList = Collections.emptyList();
}
}

public boolean isTraceCoroutines() {
return traceCoroutines;
}

public List<String> getIncludedNameList() {
return nameIncludeList;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CoroutinesConfig{");
sb.append("traceCoroutines=").append(traceCoroutines);
sb.append(", nameIncludeList=").append(nameIncludeList);
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2021 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.navercorp.pinpoint.plugin.kotlinx.coroutines;

import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.common.trace.ServiceTypeFactory;

/**
* @author Taejin Koo
*/
public final class CoroutinesConstants {

private CoroutinesConstants() {
}

public static final ServiceType SERVICE_TYPE = ServiceTypeFactory.of(8901, "KT_COROUTINES");

public static final String SCOPE = "KT_COROUTINES_SCOPE";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 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.navercorp.pinpoint.plugin.kotlinx.coroutines;

import com.navercorp.pinpoint.common.trace.TraceMetadataProvider;
import com.navercorp.pinpoint.common.trace.TraceMetadataSetupContext;

/**
* @author Taejin Koo
*/
public class CoroutinesMetadataProvider implements TraceMetadataProvider {

@Override
public void setup(TraceMetadataSetupContext context) {
context.addServiceType(CoroutinesConstants.SERVICE_TYPE);
}

}
Loading

0 comments on commit 0824ab4

Please sign in to comment.