org.openrewrite.java.spring.cloud2022.MigrateCloudSleuthToMicrometerTracing
Spring Cloud Sleuth has been discontinued and only compatible with Spring Boot 2.x.
- spring
- cloud
- tracing
- sleuth
- micrometer
GitHub, Issue Tracker, Maven Central
- groupId: org.openrewrite.recipe
- artifactId: rewrite-spring
- version: 5.0.1
{% tabs %} {% tab title="SessionInfoOperator.java" %}
{% code title="SessionInfoOperator.java" %}
import org.springframework.cloud.sleuth.Tracer;
public class SessionInfoOperator {
private Tracer tracer;
public SessionInfoOperator(Tracer tracer) {
this.tracer = tracer;
}
public boolean getSessionInfo(String key) {
return tracer.currentSpan().isNoop();
}
}
{% endcode %}
{% code title="SessionInfoOperator.java" %}
import io.micrometer.tracing.Tracer;
public class SessionInfoOperator {
private Tracer tracer;
public SessionInfoOperator(Tracer tracer) {
this.tracer = tracer;
}
public boolean getSessionInfo(String key) {
return tracer.currentSpan().isNoop();
}
}
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- SessionInfoOperator.java
+++ SessionInfoOperator.java
@@ -1,1 +1,1 @@
-import org.springframework.cloud.sleuth.Tracer;
+import io.micrometer.tracing.Tracer;
{% endcode %} {% endtab %} {% endtabs %}
{% tabs %} {% tab title="SessionInfoOperator.java" %}
{% code title="SessionInfoOperator.java" %}
import org.springframework.cloud.sleuth.Tracer;
public class SessionInfoOperator {
private Tracer tracer;
public SessionInfoOperator(Tracer tracer) {
this.tracer = tracer;
}
public boolean getSessionInfo(String key) {
return tracer.currentSpan().isNoop();
}
}
{% endcode %}
{% code title="SessionInfoOperator.java" %}
import io.micrometer.tracing.Tracer;
public class SessionInfoOperator {
private Tracer tracer;
public SessionInfoOperator(Tracer tracer) {
this.tracer = tracer;
}
public boolean getSessionInfo(String key) {
return tracer.currentSpan().isNoop();
}
}
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- SessionInfoOperator.java
+++ SessionInfoOperator.java
@@ -1,1 +1,1 @@
-import org.springframework.cloud.sleuth.Tracer;
+import io.micrometer.tracing.Tracer;
{% endcode %} {% endtab %} {% endtabs %}
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-spring:5.0.1
in your build file or by running a shell command (in which case no build changes are needed):
{% tabs %}
{% tab title="Gradle" %}
{% code title="build.gradle" %}
plugins {
id("org.openrewrite.rewrite") version("6.1.4")
}
rewrite {
activeRecipe("org.openrewrite.java.spring.cloud2022.MigrateCloudSleuthToMicrometerTracing")
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:5.0.1")
}
{% endcode %} {% endtab %} {% tab title="Maven POM" %} {% code title="pom.xml" %}
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.cloud2022.MigrateCloudSleuthToMicrometerTracing</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
{% endcode %} {% endtab %}
{% tab title="Maven Command Line" %} {% code title="shell" %} You will need to have Maven installed on your machine before you can run the following command.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE \
-Drewrite.activeRecipes=org.openrewrite.java.spring.cloud2022.MigrateCloudSleuthToMicrometerTracing
{% endcode %} {% endtab %} {% endtabs %}
{% tabs %} {% tab title="Recipe List" %}
- Add logging.pattern.level for traceId and spanId
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-starter-sleuth
- newGroupId:
io.micrometer
- newArtifactId:
micrometer-tracing-bridge-brave
- newVersion:
1.0.x
- oldGroupId:
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-sleuth-otel-dependencies
- newGroupId:
io.micrometer
- newArtifactId:
micrometer-tracing-bridge-otel
- newVersion:
1.0.x
- oldGroupId:
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-sleuth-api
- newGroupId:
io.micrometer
- newArtifactId:
micrometer-tracing
- newVersion:
1.0.x
- oldGroupId:
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-sleuth-autoconfigure
- newGroupId:
org.springframework.boot
- newArtifactId:
spring-boot-actuator-autoconfigure
- oldGroupId:
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-sleuth-otel-autoconfigure
- newGroupId:
org.springframework.boot
- newArtifactId:
spring-boot-actuator-autoconfigure
- oldGroupId:
- Change Maven dependency groupId, artifactId and/or the version
- oldGroupId:
org.springframework.cloud
- oldArtifactId:
spring-cloud-sleuth-zipkin
- newGroupId:
io.zipkin.reporter2
- newArtifactId:
zipkin-reporter-brave
- newVersion:
2.16.x
- oldGroupId:
- Add Gradle or Maven dependency
- groupId:
org.springframework.boot
- artifactId:
spring-boot-starter-actuator
- version:
3.0.x
- onlyIfUsing:
org.springframework.cloud.sleuth..*
- acceptTransitive:
true
- groupId:
- Add Gradle or Maven dependency
- groupId:
io.micrometer
- artifactId:
micrometer-tracing
- version:
1.0.x
- onlyIfUsing:
org.springframework.cloud.sleuth.annotation.*
- acceptTransitive:
true
- groupId:
- Add Gradle or Maven dependency
- groupId:
org.springframework.boot
- artifactId:
spring-boot-starter-aop
- version:
3.0.x
- onlyIfUsing:
org.springframework.cloud.sleuth.annotation.*
- acceptTransitive:
true
- groupId:
- Remove a Gradle or Maven dependency
- groupId:
org.springframework.cloud
- artifactId:
spring-cloud-sleuth-*
- groupId:
- Remove Maven managed dependency
- groupId:
org.springframework.cloud
- artifactId:
spring-cloud-sleuth-*
- groupId:
- Remove redundant explicit dependency versions
- groupPattern:
io.micrometer
- artifactPattern:
micrometer-tracing*
- onlyIfVersionsMatch:
false
- groupPattern:
- Change type
- oldFullyQualifiedTypeName:
org.springframework.cloud.sleuth.exporter.SpanFilter
- newFullyQualifiedTypeName:
io.micrometer.tracing.exporter.SpanExportingPredicate
- oldFullyQualifiedTypeName:
- Change type
- oldFullyQualifiedTypeName:
org.springframework.cloud.sleuth.exporter.SpanIgnoringSpanFilter
- newFullyQualifiedTypeName:
io.micrometer.tracing.exporter.SpanIgnoringSpanExportingPredicate
- oldFullyQualifiedTypeName:
- Rename package name
- oldPackageName:
org.springframework.cloud.sleuth.autoconfig
- newPackageName:
org.springframework.boot.actuate.autoconfigure.tracing
- recursive:
true
- oldPackageName:
- Rename package name
- oldPackageName:
org.springframework.cloud.sleuth
- newPackageName:
io.micrometer.tracing
- recursive:
true
- oldPackageName:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.enabled
- newPropertyKey:
management.tracing.enabled
- oldPropertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.batch.enabled
- newPropertyKey:
management.tracing.enabled
- oldPropertyKey:
- Delete a spring configuration property
- propertyKey:
spring.sleuth.supports-join
- propertyKey:
- Delete a spring configuration property
- propertyKey:
spring.sleuth.trace-id128
- propertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.propagation.type
- newPropertyKey:
management.tracing.propagation.type
- oldPropertyKey:
- Delete a spring configuration property
- propertyKey:
spring.sleuth.sampler.rate
- propertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.sampler.probability
- newPropertyKey:
management.tracing.sampling.probability
- oldPropertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.baggage.remote-fields
- newPropertyKey:
management.tracing.baggage.remote-fields
- oldPropertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.propagation-keys
- newPropertyKey:
management.tracing.baggage.remote-fields
- oldPropertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.baggage.correlation-enabled
- newPropertyKey:
management.tracing.baggage.correlation.enabled
- oldPropertyKey:
- Change the key of a spring application property
- oldPropertyKey:
spring.sleuth.baggage.correlation-fields
- newPropertyKey:
management.tracing.baggage.correlation.fields
- oldPropertyKey:
{% endtab %}
{% tab title="Yaml Recipe List" %}
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.cloud2022.MigrateCloudSleuthToMicrometerTracing
displayName: Migrate Spring Cloud Sleuth 3.1 to Micrometer Tracing 1.0
description: Spring Cloud Sleuth has been discontinued and only compatible with Spring Boot 2.x.
tags:
- spring
- cloud
- tracing
- sleuth
- micrometer
recipeList:
- org.openrewrite.java.spring.cloud2022.AddLoggingPatternLevelForSleuth
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-starter-sleuth
newGroupId: io.micrometer
newArtifactId: micrometer-tracing-bridge-brave
newVersion: 1.0.x
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-sleuth-otel-dependencies
newGroupId: io.micrometer
newArtifactId: micrometer-tracing-bridge-otel
newVersion: 1.0.x
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-sleuth-api
newGroupId: io.micrometer
newArtifactId: micrometer-tracing
newVersion: 1.0.x
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-sleuth-autoconfigure
newGroupId: org.springframework.boot
newArtifactId: spring-boot-actuator-autoconfigure
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-sleuth-otel-autoconfigure
newGroupId: org.springframework.boot
newArtifactId: spring-boot-actuator-autoconfigure
- org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId:
oldGroupId: org.springframework.cloud
oldArtifactId: spring-cloud-sleuth-zipkin
newGroupId: io.zipkin.reporter2
newArtifactId: zipkin-reporter-brave
newVersion: 2.16.x
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.springframework.boot
artifactId: spring-boot-starter-actuator
version: 3.0.x
onlyIfUsing: org.springframework.cloud.sleuth..*
acceptTransitive: true
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.micrometer
artifactId: micrometer-tracing
version: 1.0.x
onlyIfUsing: org.springframework.cloud.sleuth.annotation.*
acceptTransitive: true
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.springframework.boot
artifactId: spring-boot-starter-aop
version: 3.0.x
onlyIfUsing: org.springframework.cloud.sleuth.annotation.*
acceptTransitive: true
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: org.springframework.cloud
artifactId: spring-cloud-sleuth-*
- org.openrewrite.maven.RemoveManagedDependency:
groupId: org.springframework.cloud
artifactId: spring-cloud-sleuth-*
- org.openrewrite.maven.RemoveRedundantDependencyVersions:
groupPattern: io.micrometer
artifactPattern: micrometer-tracing*
onlyIfVersionsMatch: false
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.springframework.cloud.sleuth.exporter.SpanFilter
newFullyQualifiedTypeName: io.micrometer.tracing.exporter.SpanExportingPredicate
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.springframework.cloud.sleuth.exporter.SpanIgnoringSpanFilter
newFullyQualifiedTypeName: io.micrometer.tracing.exporter.SpanIgnoringSpanExportingPredicate
- org.openrewrite.java.ChangePackage:
oldPackageName: org.springframework.cloud.sleuth.autoconfig
newPackageName: org.springframework.boot.actuate.autoconfigure.tracing
recursive: true
- org.openrewrite.java.ChangePackage:
oldPackageName: org.springframework.cloud.sleuth
newPackageName: io.micrometer.tracing
recursive: true
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.enabled
newPropertyKey: management.tracing.enabled
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.batch.enabled
newPropertyKey: management.tracing.enabled
- org.openrewrite.java.spring.DeleteSpringProperty:
propertyKey: spring.sleuth.supports-join
- org.openrewrite.java.spring.DeleteSpringProperty:
propertyKey: spring.sleuth.trace-id128
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.propagation.type
newPropertyKey: management.tracing.propagation.type
- org.openrewrite.java.spring.DeleteSpringProperty:
propertyKey: spring.sleuth.sampler.rate
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.sampler.probability
newPropertyKey: management.tracing.sampling.probability
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.baggage.remote-fields
newPropertyKey: management.tracing.baggage.remote-fields
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.propagation-keys
newPropertyKey: management.tracing.baggage.remote-fields
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.baggage.correlation-enabled
newPropertyKey: management.tracing.baggage.correlation.enabled
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.baggage.correlation-fields
newPropertyKey: management.tracing.baggage.correlation.fields
{% endtab %} {% endtabs %}
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.