Skip to content

Commit

Permalink
Merge branch 'main' into cve-feed
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermp authored Dec 10, 2023
2 parents a47a3a8 + 299ad7b commit 57097dc
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
80 changes: 80 additions & 0 deletions content/en/blog/2023/spring-native/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: Observe your Spring Native Image application with OpenTelemetry
linkTitle: Observe Spring Native
date: 2023-12-08
author: >-
[Jean Bisutti](https://github.com/jeanbisutti) (Microsoft)
cSpell:ignore: bisutti datasource logback
---

The [OpenTelemetry Java agent](/docs/instrumentation/java/automatic) is a
convenient and well-established way to instrument Java applications. However, as
of today
[it is not possible to use it with GraalVM Native Images](https://github.com/oracle/graal/issues/1065).

To provide you with an easy and seamless way for Spring Boot Native Image
application nevertheless, the OpenTelemetry Java contributors have improved the
existing OpenTelemetry Spring Boot Starter to work well with Spring Boot Native
Image applications. Read on to learn more!

## A history of the last months

The OpenTelemetry Spring Boot Starter allows to add OpenTelemetry to your
application without byte code instrumentation. The OpenTelemetry Java
contributors have used this to instrument Spring Boot Native Images. By adding
the starter dependency to your project, you will benefit from an OTLP exports of
logs (added the last months), spans and metrics, with an auto-instrumentation
for Spring HTTP frameworks (updated the last months to make it work with Spring
Boot 3) out of the box:

```xml
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
<version>1.32.0-alpha</version>
</dependency>
</dependencies>
```

To get even more visibility, the Starter can be combined with
[instrumentation libraries](/docs/instrumentation/java/libraries/). For this
purpose, the OpenTelemetry Java contributors have improved the JDBC (database)
libraries and logging instrumentation libraries. For example, for the Logback
logging library, they have added GraalVM configuration to make the library work
in native mode[^1].

Furthermore, they have worked to reduce the configuration to set up the logging
and database instrumentation with the Starter. For example, if your application
does not declare a DataSource bean, you can enable the database by simply adding
two properties in the `application.properties` file:

```properties
spring.datasource.url=jdbc:otel:h2:mem:db
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
```

Read the [documentation](/docs/instrumentation/java/automatic/spring-boot/) of
the OpenTelemetry Spring Boot Starter to learn more. You can use
[opentelemetry-java-examples/spring-native](https://github.com/open-telemetry/opentelemetry-java-examples/tree/main/spring-native)
to run a Spring Boot Native Image application and look at the generated logs as
well as HTTP and database telemetry data.

Finally, the OpenTelemetry Java contributors have added GraalVM Native automatic
tests to the OpenTelemetry Java project to detect regressions related to the
native mode execution.

## What’s next?

The OpenTelemetry Java contributors expect to be able to enable automatic
logging and database instrumentation configuration.

If you try out the OpenTelemetry Spring Boot Starter, share your thoughts and
experiences via
[GitHub discussions](https://github.com/open-telemetry/opentelemetry-java/discussions)
or the [#otel-java](https://cloud-native.slack.com/archives/C014L2KCTE3)
[CNCF Slack](https://slack.cncf.io) channel.

[^1]:
Spring Boot Native Image applications
[do not support Log4j2 logging library](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-GraalVM).
2 changes: 1 addition & 1 deletion content/en/docs/instrumentation/java/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aliases: [/java, /java/metrics, /java/tracing]
cascade:
vers:
instrumentation: 1.32.0
otel: 1.32.0
otel: 1.33.0
semconv: 1.23.1
weight: 18
---
Expand Down
21 changes: 21 additions & 0 deletions content/en/docs/instrumentation/net/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ code:
```csharp
using System.Globalization;

using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

Expand All @@ -65,6 +67,11 @@ string HandleRollDice([FromServices]ILogger<Program> logger, string? player)
return result.ToString(CultureInfo.InvariantCulture);
}

int RollDice()
{
return Random.Shared.Next(1, 7);
}

app.MapGet("/rolldice/{player?}", HandleRollDice);

app.Run();
Expand Down Expand Up @@ -114,7 +121,21 @@ that will generate the telemetry, and set them up.

2. Setup the OpenTelemetry code

In Program.cs, replace the following lines:

```csharp
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
```

With:

```csharp
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

const string serviceName = "roll-dice";
Expand Down
24 changes: 24 additions & 0 deletions static/refcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@
"StatusCode": 206,
"LastSeen": "2023-06-30T09:37:46.480932-04:00"
},
"https://cloud-native.slack.com/archives/C014L2KCTE3": {
"StatusCode": 200,
"LastSeen": "2023-12-08T11:19:16.128163+01:00"
},
"https://cloud-native.slack.com/archives/C01N5UCHTEH": {
"StatusCode": 200,
"LastSeen": "2023-06-30T09:38:12.370641-04:00"
Expand Down Expand Up @@ -2371,6 +2375,10 @@
"StatusCode": 200,
"LastSeen": "2023-10-23T22:46:44.940049+02:00"
},
"https://github.com/jeanbisutti": {
"StatusCode": 200,
"LastSeen": "2023-12-08T11:19:13.539577+01:00"
},
"https://github.com/jenniferplusplus/opentelemetry-instrumentation-bullmq": {
"StatusCode": 200,
"LastSeen": "2023-06-30T08:33:32.788394-04:00"
Expand Down Expand Up @@ -3207,6 +3215,10 @@
"StatusCode": 200,
"LastSeen": "2023-11-01T21:52:02.990981-04:00"
},
"https://github.com/open-telemetry/opentelemetry-java/discussions": {
"StatusCode": 200,
"LastSeen": "2023-12-08T11:19:15.572149+01:00"
},
"https://github.com/open-telemetry/opentelemetry-java/releases": {
"StatusCode": 200,
"LastSeen": "2023-06-30T08:47:15.179862-04:00"
Expand Down Expand Up @@ -3739,6 +3751,10 @@
"StatusCode": 200,
"LastSeen": "2023-06-30T08:42:08.536962-04:00"
},
"https://github.com/oracle/graal/issues/1065": {
"StatusCode": 200,
"LastSeen": "2023-12-08T11:19:14.694346+01:00"
},
"https://github.com/orgs/open-telemetry/projects/41/views/1": {
"StatusCode": 200,
"LastSeen": "2023-06-30T09:42:42.642961-04:00"
Expand Down Expand Up @@ -3847,6 +3863,10 @@
"StatusCode": 200,
"LastSeen": "2023-06-30T09:27:42.016103-04:00"
},
"https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-GraalVM": {
"StatusCode": 200,
"LastSeen": "2023-12-08T11:19:16.63837+01:00"
},
"https://github.com/statsd/statsd": {
"StatusCode": 200,
"LastSeen": "2023-06-30T08:39:57.115625-04:00"
Expand Down Expand Up @@ -4915,6 +4935,10 @@
"StatusCode": 206,
"LastSeen": "2023-09-08T10:56:59.732967-04:00"
},
"https://opentelemetry.io/docs/instrumentation/java/automatic/spring-boot/": {
"StatusCode": 206,
"LastSeen": "2023-12-08T11:19:15.011115+01:00"
},
"https://opentracing.io": {
"StatusCode": 206,
"LastSeen": "2023-06-29T18:41:30.83242-04:00"
Expand Down

0 comments on commit 57097dc

Please sign in to comment.