Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

  • Removed redundant imports (cats.syntax.flatMap.* and cats.syntax.functor.*)
  • Fixed misleading log message placement - now logs right after OpenTelemetry initialization
  • Added Grafana provisioning configuration to auto-configure Prometheus datasource
  • All tests passing
Original prompt

Add opentelemetry libs to scrape metrics. You can find details by this link https://typelevel.org/otel4s/oteljava/metrics-jvm-runtime.html
Also add prometheus and grafana to the docker-compose file to observe new metrics in real time.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits December 6, 2025 13:01
…heus/Grafana support

Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Co-authored-by: trett <1980024+trett@users.noreply.github.com>
…source lifecycle

Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Copilot AI changed the title [WIP] Add OpenTelemetry libraries for metrics scraping Add OpenTelemetry JVM metrics with Prometheus and Grafana observability stack Dec 6, 2025
Copilot AI requested a review from trett December 6, 2025 13:10
@trett
Copy link
Owner

trett commented Dec 6, 2025

@copilot 1. According the docs there is more simple usage of this library. Try to apply this approach:

import cats.syntax.flatMap._
import cats.syntax.functor._
import io.opentelemetry.api.{OpenTelemetry => JOpenTelemetry}
import io.opentelemetry.instrumentation.runtimemetrics.java17._
import org.typelevel.otel4s.oteljava.OtelJava

object Service extends IOApp.Simple {
  
  def run: IO[Unit] = 
    OtelJava
      .autoConfigured[IO]()
      .flatTap(otel4s => registerRuntimeMetrics(otel4s.underlying))
      .use { otel4s =>
        val _ = otel4s
        ???
      }

  private def registerRuntimeMetrics[F[_]: Sync](
      openTelemetry: JOpenTelemetry
  ): Resource[F, Unit] = {
    val acquire = Sync[F].delay(RuntimeMetrics.create(openTelemetry))

    Resource.fromAutoCloseable(acquire).void
  }
}
  1. Also there are newest version of these libraries are available
libraryDependencies ++= Seq(
  "org.typelevel" %% "otel4s-oteljava" % "0.14.0", // <1>
  "io.opentelemetry.instrumentation" % "opentelemetry-runtime-telemetry-java17" % "2.22.0-alpha" // <2>
)
  1. Remove too detailed description of changes from the README file.

Copilot AI and others added 2 commits December 6, 2025 13:26
…nd update to latest library versions

Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 6, 2025

@copilot 1. According the docs there is more simple usage of this library. Try to apply this approach:

import cats.syntax.flatMap._...

I've addressed all three points in commit fb960c5:

  1. ✅ Simplified implementation using OtelJava.autoConfigured() with RuntimeMetrics.create() as suggested
  2. ✅ Updated to latest versions: otel4s 0.14.0 and runtime-telemetry 2.22.0-alpha
  3. ✅ Simplified README by removing detailed descriptions - now just lists the access points

The implementation now uses OpenTelemetry's autoconfiguration via environment variables (OTEL_EXPORTER_PROMETHEUS_PORT and OTEL_METRICS_EXPORTER) configured in docker-compose.yml.

@trett trett marked this pull request as ready for review December 6, 2025 13:31
Copilot AI review requested due to automatic review settings December 6, 2025 13:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements comprehensive JVM runtime metrics collection using OpenTelemetry with Prometheus export and Grafana visualization capabilities. The implementation uses otel4s for Scala integration and provides automatic JVM metrics collection for memory, GC, threads, CPU, and other runtime statistics.

Key changes:

  • Integrated OpenTelemetry with automatic configuration and JVM runtime metrics collection
  • Added Prometheus and Grafana services to docker-compose for metrics monitoring
  • Updated documentation with observability features and access points

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
server/src/main/scala/ru/trett/rss/server/Server.scala Adds OpenTelemetry initialization with runtime metrics registration and proper resource management
build.sbt Adds otel4s and OpenTelemetry runtime metrics dependencies
scripts/local-docker/docker-compose.yml Configures Prometheus and Grafana services with proper environment variables for metrics export
scripts/local-docker/prometheus.yml Defines Prometheus scraping configuration targeting the server metrics endpoint
README.md Documents new observability features and access endpoints
client/package-lock.json Minor npm dependency metadata cleanup
Files not reviewed (1)
  • client/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@trett
Copy link
Owner

trett commented Dec 6, 2025

@copilot apply changes based on the comments in this thread

…, add Grafana provisioning

Co-authored-by: trett <1980024+trett@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 6, 2025

@copilot apply changes based on the comments in this thread

Applied all changes from the review in commit 20b6869:

  1. ✅ Removed redundant cats.syntax.flatMap.* and cats.syntax.functor.* imports (already included in cats.implicits.*)
  2. ✅ Fixed log message placement - now logs "OpenTelemetry metrics initialized" right after initialization via .evalTap() instead of later in the app flow
  3. ✅ Added Grafana provisioning configuration to auto-configure Prometheus datasource on startup - created grafana/provisioning/datasources/prometheus.yml and updated docker-compose volume mount

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • client/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@trett trett merged commit febaf48 into main Dec 6, 2025
7 checks passed
@trett trett deleted the copilot/add-opentelemetry-metrics branch December 6, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants