Skip to content

Commit

Permalink
chore: add tracing endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dweber019 committed Oct 18, 2023
1 parent 5d2ee2b commit 5633587
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 26 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<artifactId>agent</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
<groupId>io.pyroscope</groupId>
<artifactId>otel</artifactId>
<version>0.10.1.4</version>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,30 @@
@SpringBootApplication
public class GabelStaplerBuggyApplication {

@Value("${spring.application.name}")
private String applicationName;

@Value("${pyroscope.url}")
private String pyroscopeUrl;

public static void main(String[] args) {
Hooks.enableAutomaticContextPropagation();
SpringApplication.run(GabelStaplerBuggyApplication.class, args);
}

@PostConstruct
public void init() {
PyroscopeAgent.start(
new Config.Builder()
.setApplicationName(applicationName)
.setProfilingEvent(EventType.ITIMER)
.setFormat(Format.JFR)
.setServerAddress(pyroscopeUrl)
// Optionally, if authentication is enabled, specify the API key.
// .setAuthToken(System.getenv("PYROSCOPE_AUTH_TOKEN"))
// Optionally, if you'd like to set allocation threshold to register events, in bytes. '0' registers all events
.setProfilingAlloc("0")
//.setSamplingDuration(Duration.)
.setLogLevel(Logger.Level.DEBUG)
.setProfilingLock("10ms")
.setProfilingInterval(Duration.ofMillis(10))
.setUploadInterval(Duration.ofSeconds(10))
.build()
);
}
// @PostConstruct
// public void init() {
// PyroscopeAgent.start(
// new Config.Builder()
// .setApplicationName(applicationName)
// .setProfilingEvent(EventType.ITIMER)
// .setFormat(Format.JFR)
// .setServerAddress(pyroscopeUrl)
// // Optionally, if authentication is enabled, specify the API key.
// // .setAuthToken(System.getenv("PYROSCOPE_AUTH_TOKEN"))
// // Optionally, if you'd like to set allocation threshold to register events, in bytes. '0' registers all events
// .setProfilingAlloc("0")
// //.setSamplingDuration(Duration.)
// .setLogLevel(Logger.Level.DEBUG)
// .setProfilingLock("10ms")
// .setProfilingInterval(Duration.ofMillis(10))
// .setUploadInterval(Duration.ofSeconds(10))
// .build()
// );
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.otel.pyroscope.PyroscopeOtelConfiguration;
import io.otel.pyroscope.PyroscopeOtelSpanProcessor;
import io.pyroscope.http.Format;
import io.pyroscope.javaagent.EventType;
import io.pyroscope.javaagent.PyroscopeAgent;
import io.pyroscope.javaagent.api.Logger;
import io.pyroscope.javaagent.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -13,6 +22,43 @@
@EnableConfigurationProperties(OtlpProperties.class)
public class OtlpConfiguration {

@Value("${spring.application.name}")
private String applicationName;

@Value("${pyroscope.url}")
private String pyroscopeUrl;

@Value("${pyroscope.frontend-url}")
private String pyroscopeFrontendUrl;

@Bean
Config pyroscopeConfig() {
return new Config.Builder()
.setApplicationName(applicationName)
.setProfilingEvent(EventType.ITIMER)
.setFormat(Format.JFR)
.setLogLevel(Logger.Level.DEBUG)
.setServerAddress(pyroscopeUrl)
.build();
}

@Bean
SpanProcessor pyroscopeSpanProcessor(Config pyroscopeConfig) {
PyroscopeAgent.start(
new PyroscopeAgent.Options.Builder(pyroscopeConfig)
.build()
);

PyroscopeOtelConfiguration pyroscopeOtelConfig = new PyroscopeOtelConfiguration.Builder()
.setAppName(pyroscopeConfig.applicationName + "." + pyroscopeConfig.profilingEvent.id)
.setPyroscopeEndpoint(pyroscopeFrontendUrl)
.setAddProfileURL(true)
.setAddSpanName(true)
.setAddProfileBaselineURLs(true)
.build();
return new PyroscopeOtelSpanProcessor(pyroscopeOtelConfig);
}

// OtlpAutoConfiguration use HTTP by default, we update it to use GRPC
// https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/otlp/OtlpAutoConfiguration.java
@Bean
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ logging:

pyroscope:
url: ${PYROSCOPE_URL:http://pyroscope:4040}
frontend-url: ${PYROSCOPE_FRONTEND_URL:http://pyroscope:4040}
"https://pyroscope-monitoring-stack.apps.baloise.dev/"

0 comments on commit 5633587

Please sign in to comment.