Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional details to Java integration #169

Merged
merged 5 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions docs/integration-java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}")
```

<Tabs
defaultValue="maven"
values={[
{label: 'Maven', value: 'maven'},
{label: 'Gradle', value: 'gradle'},
]}>
<TabItem value="maven">
<CodeBlock className="language-xml">{exampleMaven}</CodeBlock>
</TabItem>
<TabItem value="gradle">
<CodeBlock className="language-java">{exampleGradle}</CodeBlock>
</TabItem>
</Tabs>

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()
);
```

<Tabs
defaultValue="plain-java"
values={[
{label: 'Java', value: 'plain-java'},
{label: 'Spring Framework', value: 'spring'},
]}>
<TabItem value="plain-java">
<CodeBlock className="language-java">{examplePlainJava}</CodeBlock>
</TabItem>
<TabItem value="spring">
<CodeBlock className="language-java">{exampleSpringFramework}</CodeBlock>
</TabItem>
</Tabs>

You can also optionally replace some pyroscope components

Expand Down
40 changes: 40 additions & 0 deletions src/javaCodeBlocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const exampleGradle = `implementation("io.pyroscope:agent:\${pyroscope_version}")`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petethepig how do we make this variable actually substitute in here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe out of scope for this pr though, happy to create an issue and address later if you think thats better


export const exampleMaven = `<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>agent</artifactId>
<version>pyroscope_version</version>
</dependency>`

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")
6fears7 marked this conversation as resolved.
Show resolved Hide resolved
.build()
);
}`