Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Upgrade Spring Boot to 3.2.0 (#52)
Browse files Browse the repository at this point in the history
* - Upgrade Spring Boot to 3.2.0
- apply spotless in all projects
- add telemetry.distro.name and telemetry.distro.version as resource attributes

* set version to 1.4.0

* set version to 1.4.0
  • Loading branch information
zeitlinger authored Dec 7, 2023
1 parent 782fcb6 commit d0a762e
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: gradle/[email protected]
- name: Test and build Jar
uses: gradle/[email protected]
env:
CHECK_GENERATED_FILES: true
with:
arguments: test jar
publish:
Expand Down
21 changes: 13 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
# Changelog
## Version 1.3.2. (2023-07-19)
## Version 1.4.0 (2023-12-07)

* This version supports Spring Boot 3.2.0
* Add resource attributes `telemetry.distro.name` = `grafana-opentelemetry-starter` and `telemetry.distro.version` = `1.4.0`

## Version 1.3.2 (2023-07-19)
* You can now disable the starter by setting `spring.opentelemetry.enabled=false` in your application.yaml or application.properties

## Version 1.3.1. (2023-06-29)
## Version 1.3.1 (2023-06-29)
* Fix histogram bucket boundaries - it was a lower bound of 1 - regardless of the unit (and 1s is too large for server response times)
* enable histograms for "http.server.requests"
* Logger is configured automatically for Logback and Log4j2 - no need to add any configuration to your application (if you have configured the OpenTelemetry logger already, it will be used)

## Version 1.3.0. (2023-06-26)
## Version 1.3.0 (2023-06-26)
* Broken for log4j - use 1.3.1 instead

## Version 1.2.0. (2023-06-06)
## Version 1.2.0 (2023-06-06)

* Set the base time unit to "seconds" - which ensures future compatibility with upcoming versions of the Grafana Agent
* Support thread name for logging

## Version 1.1.0. (2023-06-02)
## Version 1.1.0 (2023-06-02)

* Add support for log4j
* Bugfix: starter can now be used with maven

## Version 1.0.1. (2023-05-23)
## Version 1.0.1 (2023-05-23)

### Enhancements

* Include open-telemetry resources [(#14)](https://github.com/grafana/grafana-opentelemetry-starter/pull/14)

## Version 1.0.0. (2023-04-24)
## Version 1.0.0 (2023-04-24)

* Initial release
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ in Grafana Cloud or the Grafana OSS stack.

## Compatibility

| Spring Boot Version | Java Version | Recommended Setup |
|---------------------|--------------|------------------------------------------------------------------------------------------|
| 3.1+ | 17+ | Use this starter |
| 3.0.4 - 3.1 | 17+ | Use this starter in version 1.0.0 (only works with gradle) |
| 2.x | 8+ | Use the [Java Agent](https://grafana.com/docs/opentelemetry/instrumentation/java-agent/) |
| Spring Boot Version | Java Version | Recommended Setup |
|---------------------|--------------|----------------------------------------------------------------------------------------------------------|
| 3.2.x | 17+ | Use this starter in version 1.4.x |
| 3.1.x | 17+ | Use this starter in version 1.3.x |
| 3.0.4 < 3.1.0 | 17+ | Use this starter in version 1.0.0 (only works with gradle) |
| 2.x | 8+ | Use [Grafana OpenTelemetry Distribution for Java](https://github.com/grafana/grafana-opentelemetry-java) |

Logging is supported with Logback and Log4j2
(a separate appender is added automatically, leaving your console or file appenders untouched).
Expand All @@ -19,7 +20,7 @@ Logging is supported with Logback and Log4j2
Add the following dependency to your `build.gradle`

```groovy
implementation 'com.grafana:grafana-opentelemetry-starter:1.3.2'
implementation 'com.grafana:grafana-opentelemetry-starter:1.4.0'
```

... or `pom.xml`
Expand All @@ -28,7 +29,7 @@ implementation 'com.grafana:grafana-opentelemetry-starter:1.3.2'
<dependency>
<groupId>com.grafana</groupId>
<artifactId>grafana-opentelemetry-starter</artifactId>
<version>1.3.2</version>
<version>1.4.0</version>
</dependency>
```

Expand Down
91 changes: 66 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'maven-publish'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
id 'signing'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id "com.diffplug.spotless" version "6.22.0"
}

Expand All @@ -14,20 +14,6 @@ targetCompatibility = JavaVersion.VERSION_17
group = "com.grafana"
version = project.properties['grafanaOtelStarterVersion']

repositories {
mavenCentral()
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
mavenContent {
snapshotsOnly()
}
}
}

test {
useJUnitPlatform()
}

java {
withJavadocJar()
withSourcesJar()
Expand All @@ -38,20 +24,47 @@ jar {
archiveClassifier.set('')
}

allprojects {
version = rootProject.version

apply plugin: "java"
apply plugin: "com.diffplug.spotless"

repositories {
mavenCentral()
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
mavenContent {
snapshotsOnly()
}
}
}

test {
useJUnitPlatform()
}

spotless {
java {
googleJavaFormat()
target("src/**/*.java")
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'

def otelVersion = dependencyManagement.importedProperties['opentelemetry.version']
implementation "io.opentelemetry:opentelemetry-exporter-otlp"
implementation "io.opentelemetry:opentelemetry-exporter-otlp-logs:$otelVersion-alpha"
implementation "io.opentelemetry:opentelemetry-exporter-logging" // only for debug
implementation "io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0:$otelVersion-alpha"
implementation "io.opentelemetry.instrumentation:opentelemetry-log4j-appender-2.17:$otelVersion-alpha"
compileOnly 'org.springframework.boot:spring-boot-starter-log4j2'

runtimeOnly "io.opentelemetry.instrumentation:opentelemetry-resources:$otelVersion-alpha"
implementation "io.opentelemetry.instrumentation:opentelemetry-micrometer-1.5:$otelVersion-alpha"
implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:$otelVersion-alpha"
implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:$otelVersion"
runtimeOnly "io.micrometer:micrometer-tracing-bridge-otel"

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
Expand All @@ -60,13 +73,6 @@ dependencies {
testImplementation "org.springframework.boot:spring-boot-starter-web"
}

spotless {
java {
googleJavaFormat()
target("src/**/*.java")
}
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down Expand Up @@ -128,3 +134,38 @@ if (gradle.startParameter.taskNames.contains("publishToSonatype")) {
useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD"))
}
}

def updateGeneratedFile(file, newContent) {
if (System.getenv("CHECK_GENERATED_FILES") == "true") {
def oldContent = file.text
if (oldContent != newContent) {
throw new GradleException("File ${file} was modified in CI. Please update it locally and commit.")
}
} else {
project.mkdir(file.parent)
file.text = newContent
}
}

task manageVersionClass() {
doLast {
updateGeneratedFile(new File("${projectDir}/src/main/java/com/grafana/opentelemetry", "DistributionVersion.java"),
"""/*
* Copyright Grafana Labs
* SPDX-License-Identifier: Apache-2.0
*/
package com.grafana.opentelemetry;
// This class is generated by custom/build.gradle. Do not edit.
public class DistributionVersion {
public static final String VERSION = "$version";
}
""")
}
}

compileJava.dependsOn(manageVersionClass)

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grafanaOtelStarterVersion=1.3.2
grafanaOtelStarterVersion=1.4.0
4 changes: 2 additions & 2 deletions integrationTests/disable/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
import org.springframework.test.context.TestPropertySource;

@SuppressWarnings("SpringBootApplicationProperties")
@SpringBootTest(
classes = {HelloController.class, DemoApplication.class, OpenTelemetryConfig.class}

)
@SpringBootTest(classes = {HelloController.class, DemoApplication.class, OpenTelemetryConfig.class})
@AutoConfigureObservability
@TestPropertySource(properties = {
"grafana.otlp.enabled = false",
})
@TestPropertySource(
properties = {
"grafana.otlp.enabled = false",
})
public class DisableOpenTelemetryTest {

@Test
void starterIsNotApplied() {
// we could also check that no data is sent, but this would require us to wait a certain amount of time
// e.g. 10 seconds - and this would make the test slow and complicated
Assertions.assertThat(LogbackConfig.hasAppender(LogbackConfig.getLogger())).isFalse();
}
@Test
void starterIsNotApplied() {
// we could also check that no data is sent, but this would require us to wait a certain amount
// of time
// e.g. 10 seconds - and this would make the test slow and complicated
Assertions.assertThat(LogbackConfig.hasAppender(LogbackConfig.getLogger())).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "hello LGTM";
}
@GetMapping("/hello")
public String sayHello() {
return "hello LGTM";
}
}
4 changes: 2 additions & 2 deletions integrationTests/log4j/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "hello LGTM";
}
@GetMapping("/hello")
public String sayHello() {
return "hello LGTM";
}
}
Loading

0 comments on commit d0a762e

Please sign in to comment.