Skip to content

Commit

Permalink
Tweak otel stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Feb 4, 2025
1 parent 2480658 commit 5bb8346
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
<exclusions>
<exclusion>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-sender-okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-sender-jdk</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.contrib</groupId>
<artifactId>opentelemetry-samplers</artifactId>
<version>1.41.0-alpha</version>
</dependency>
<dependency>
<groupId>am.ik.spring</groupId>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/am/ik/translation/config/OtelConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package am.ik.translation.config;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.contrib.sampler.RuleBasedRoutingSampler;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class OtelConfig {

@Bean
public static BeanPostProcessor filteringSpanExporterRegistrar() {
return new BeanPostProcessor() {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Sampler) {
AttributeKey<String> uri = AttributeKey.stringKey("uri");
return RuleBasedRoutingSampler.builder(SpanKind.SERVER, (Sampler) bean)
.drop(uri, "^/readyz")
.drop(uri, "^/livez")
.drop(uri, "^/actuator")
.drop(uri, "^/cloudfoundryapplication")
.drop(uri, "^/_static")
.build();
}
return bean;
}
};
}

}

0 comments on commit 5bb8346

Please sign in to comment.