Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure scalafix #20

Merged
merged 5 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

- name: Check scalafix lints
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'scalafixAll --check'

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues
Expand Down
13 changes: 13 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
rules = [
OrganizeImports
LeakingImplicitClassVal
RedundantSyntax
TypelevelUnusedIO
TypelevelMapSequence
]

OrganizeImports {
importsOrder = SymbolsFirst
importSelectorsOrder = SymbolsFirst
removeUnused = false
}
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ ThisBuild / tlSonatypeUseLegacyHost := false
// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")

ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"

val Scala213 = "2.13.8"
ThisBuild / crossScalaVersions := Seq(Scala213, "3.1.3")
ThisBuild / scalaVersion := Scala213 // the default Scala

lazy val root = tlCrossRootProject.aggregate(core, java)
lazy val root = tlCrossRootProject
.aggregate(core, java)
.settings(name := "otel4s")

lazy val core = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package org.typelevel.otel4s
package metrics

import cats.Applicative
import cats.effect.{Resource, Temporal}
import cats.effect.Resource
import cats.effect.Temporal
import cats.syntax.flatMap._
import cats.syntax.functor._

Expand Down
23 changes: 12 additions & 11 deletions java/src/main/scala/org/typelevel/otel4s/java/impl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package org.typelevel.otel4s
package java

import cats.effect.Sync

import io.opentelemetry.api.{OpenTelemetry => JOpenTelemetry}
import io.opentelemetry.api.common.{Attributes => JAttributes}
import io.opentelemetry.api.common.{AttributeKey => JAttributeKey}
import io.opentelemetry.api.common.{AttributeType => JAttributeType}
import io.opentelemetry.api.metrics.{Meter => JMeter}
import io.opentelemetry.api.metrics.{LongCounter => JLongCounter}
import io.opentelemetry.api.common.{Attributes => JAttributes}
import io.opentelemetry.api.metrics.{DoubleHistogram => JDoubleHistogram}
import io.opentelemetry.api.metrics.{LongCounter => JLongCounter}
import io.opentelemetry.api.metrics.{LongUpDownCounter => JLongUpDownCounter}
import io.opentelemetry.api.metrics.{Meter => JMeter}
import org.typelevel.otel4s.metrics._

import scala.jdk.CollectionConverters._
Expand All @@ -49,8 +48,10 @@ object OtelJava {
schemaUrl: Option[String] = None
)(implicit F: Sync[F])
extends MeterBuilder[F] {
def withVersion(version: String) = copy(version = Option(version))
def withSchemaUrl(schemaUrl: String) = copy(schemaUrl = Option(schemaUrl))
def withVersion(version: String): MeterBuilder[F] =
copy(version = Option(version))
def withSchemaUrl(schemaUrl: String): MeterBuilder[F] =
copy(schemaUrl = Option(schemaUrl))

def get: F[Meter[F]] = F.delay {
val b = jOtel.meterBuilder(name)
Expand Down Expand Up @@ -84,8 +85,8 @@ object OtelJava {
extends SyncInstrumentBuilder[F, Counter[F, Long]] {
type Self = CounterBuilderImpl[F]

def withUnit(unit: String) = copy(unit = Option(unit))
def withDescription(description: String) =
def withUnit(unit: String): Self = copy(unit = Option(unit))
def withDescription(description: String): Self =
copy(description = Option(description))

def create: F[Counter[F, Long]] = F.delay {
Expand All @@ -112,8 +113,8 @@ object OtelJava {
extends SyncInstrumentBuilder[F, Histogram[F, Double]] {
type Self = HistogramBuilderImpl[F]

def withUnit(unit: String) = copy(unit = Option(unit))
def withDescription(description: String) =
def withUnit(unit: String): Self = copy(unit = Option(unit))
def withDescription(description: String): Self =
copy(description = Option(description))

def create: F[Histogram[F, Double]] = F.delay {
Expand All @@ -127,7 +128,7 @@ object OtelJava {
private class HistogramImpl[F[_]](histogram: JDoubleHistogram)(implicit
F: Sync[F]
) extends Histogram[F, Double] {
def record(d: Double, attributes: Attribute[_]*) =
def record(d: Double, attributes: Attribute[_]*): F[Unit] =
F.delay(histogram.record(d, toJAttributes(attributes)))
}

Expand Down
7 changes: 3 additions & 4 deletions java/src/test/scala/com/example/PoC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package com.example

import cats.effect.IO
import cats.effect.IOApp
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk
import org.typelevel.otel4s.Attribute
import org.typelevel.otel4s.AttributeKey
import org.typelevel.otel4s.java.OtelJava

import cats.effect.IO
import cats.effect.IOApp

object Poc extends IOApp.Simple {
def run = for {
def run: IO[Unit] = for {
_ <- IO(sys.props("otel.traces.exporter") = "none")
_ <- IO(sys.props("otel.metrics.exporter") = "logging")
_ <- IO(sys.props("otel.logs.exporter") = "none")
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.12")
addSbtPlugin("org.typelevel" % "sbt-typelevel-scalafix" % "0.4.12")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.4.12")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")