Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Last active September 21, 2023 19:18
Show Gist options
  • Select an option

  • Save alexanderankin/088f72e775a24e260225ccd4c2f810b5 to your computer and use it in GitHub Desktop.

Select an option

Save alexanderankin/088f72e775a24e260225ccd4c2f810b5 to your computer and use it in GitHub Desktop.
plugins {
id 'java'
}
java {
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_17
}
repositories.mavenCentral()
tasks.withType(Test).configureEach { useJUnitPlatform() } // also changing/ed soon? :(
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:3.1.3')
annotationProcessor platform('org.springframework.boot:spring-boot-dependencies:3.1.3')
implementation platform('org.springframework.cloud:spring-cloud-dependencies:2022.0.4')
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// implementation 'org.springframework.boot:spring-boot-starter-data-cassandra'
// implementation 'org.springframework.boot:spring-boot-starter-data-cassandra-reactive'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
// implementation 'org.springframework.kafka:spring-kafka'
implementation 'io.micrometer:micrometer-tracing-bridge-brave' { exclude('group': 'io.zipkin.brave') }
implementation 'io.micrometer:micrometer-tracing'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:cassandra'
// testImplementation 'org.springframework.kafka:spring-kafka-test'
// testImplementation 'org.testcontainers:junit-jupiter'
// testImplementation 'org.testcontainers:kafka'
}
package info.ankin.example;
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import zipkin2.Call;
import zipkin2.codec.Encoding;
import zipkin2.reporter.Sender;
import java.util.List;
@SpringBootApplication
class ReproducerApplication {
public static void main(String[] args) {
// https://github.com/micrometer-metrics/tracing/wiki/Spring-Cloud-Sleuth-3.1-Migration-Guide#log-pattern
System.setProperty("logging.pattern.level", "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]");
SpringApplication.run(ReproducerApplication.class, args);
}
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/")
static class RaController {
final RestTemplateBuilder restTemplateBuilder;
final DefaultTracingObservationHandler a; // placed here to ensure MicrometerTracingAutoConfiguration was actually loaded
RestTemplate restTemplate;
@PostConstruct
void init() {
restTemplate = restTemplateBuilder.build();
}
@GetMapping("/")
String abc() {
/*
this should print a trace
*/
log.info("hello");
/*
what is running on localhost:3000?
npx express-generator --no-view example-app-returns-headers
cd example-app-returns-headers
sed -i -e '/static/s/^/\/\//' -e "/app.use('\//s/^/\/\//" app.js
echo >> app.js
echo "app.use('/', function returnHeaders(req, res, next) { res.send(req.headers); });" >> app.js
npm i
npm run start
*/
return restTemplate.getForObject("http://localhost:3000/", String.class);
}
}
@Bean
Sender noopSender() {
return new Sender() {
@Override
public Encoding encoding() {
return Encoding.JSON;
}
@Override
public int messageMaxBytes() {
return Integer.MAX_VALUE;
}
@Override
public int messageSizeInBytes(List<byte[]> encodedSpans) {
return 0;
}
@Override
public Call<Void> sendSpans(List<byte[]> encodedSpans) {
return Call.create(null);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment