diff --git a/docs/integration-java.mdx b/docs/integration-java.mdx index 59cf7ee6..fd4b790c 100644 --- a/docs/integration-java.mdx +++ b/docs/integration-java.mdx @@ -10,6 +10,8 @@ keywords: [ pyroscope, java, javaspy, profiling, async-profiler ] import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; +import {exampleMaven, exampleGradle, examplePlainJava, exampleSpringFramework} from '../src/javaCodeBlocks'; +import CodeBlock from '@theme/CodeBlock'; Pyroscope uses [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) to collect profiling data from Java applications. @@ -40,22 +42,36 @@ You can start pyroscope either from your apps's java code or attach it as javaag #### Start pyroscope from app's java code Add pyroscope dependency: -```kotlin -implementation("io.pyroscope:agent:${pyroscope_version}") -``` + + + + {exampleMaven} + + + {exampleGradle} + + + Then add the following code to your application: -```java -PyroscopeAgent.start( - new Config.Builder() - .setApplicationName("ride-sharing-app-java") - .setProfilingEvent(EventType.ITIMER) - .setFormat(Format.JFR) - .setServerAddress("http://pyroscope-server:4040") - // Optionally, if authentication is enabled, specify the API key. - // .setAuthToken(System.getenv("PYROSCOPE_AUTH_TOKEN")) - .build() -); -``` + + + + {examplePlainJava} + + + {exampleSpringFramework} + + You can also optionally replace some pyroscope components diff --git a/src/javaCodeBlocks.js b/src/javaCodeBlocks.js new file mode 100644 index 00000000..e7ce0c6e --- /dev/null +++ b/src/javaCodeBlocks.js @@ -0,0 +1,40 @@ +export const exampleGradle = `implementation("io.pyroscope:agent:\${pyroscope_version}")` + +export const exampleMaven = ` + io.pyroscope + agent + pyroscope_version +` + +export const examplePlainJava = `PyroscopeAgent.start( + new Config.Builder() + .setApplicationName("ride-sharing-app-java") + .setProfilingEvent(EventType.ITIMER) + .setFormat(Format.JFR) + .setServerAddress("http://pyroscope-server:4040") + // Optionally, if authentication is enabled, specify the API key. + // .setAuthToken(System.getenv("PYROSCOPE_AUTH_TOKEN")) + .build() + );` + +export const exampleSpringFramework = `import io.pyroscope.javaagent.PyroscopeAgent; +import io.pyroscope.javaagent.config.Config; +import io.pyroscope.javaagent.EventType; +import io.pyroscope.http.Format; + +@PostConstruct +public void init() { + + PyroscopeAgent.start( + new Config.Builder() + .setApplicationName("ride-sharing-app-java") + .setProfilingEvent(EventType.ITIMER) + .setFormat(Format.JFR) + .setServerAddress("http://pyroscope-server:4040") + // Optionally, if authentication is enabled, specify the API key. + // .setAuthToken(System.getenv("PYROSCOPE_AUTH_TOKEN")) + // Optionally, if you'd like to sets allocation threshold to register events, in bytes. '0' registers all events + // .setProfilingAlloc("0") + .build() + ); +}` \ No newline at end of file