Skip to content

Commit

Permalink
sdk-exporter: add OtlpHttpSpanExporter
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Jan 4, 2024
1 parent 04fd83a commit e5c2ccb
Show file tree
Hide file tree
Showing 15 changed files with 1,481 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ jobs:
if: matrix.java == 'temurin@8' && steps.setup-java-temurin-8.outputs.cache-hit == 'false'
run: sbt +update

- name: Install brew formulae (ubuntu)
if: startsWith(matrix.os, 'ubuntu')
run: /home/linuxbrew/.linuxbrew/bin/brew install s2n utf8proc

- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

Expand Down Expand Up @@ -239,7 +243,7 @@ jobs:
- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: otel4s-sdk-common_native0.4_2.13 otel4s-sdk-common_native0.4_3 otel4s-benchmarks_2.13 otel4s-benchmarks_3 otel4s-examples_2.13 otel4s-examples_3 otel4s-sdk-common_sjs1_2.13 otel4s-sdk-common_sjs1_3 otel4s-sdk-trace_sjs1_2.13 otel4s-sdk-trace_sjs1_3 otel4s_2.13 otel4s_3 docs_2.13 docs_3 otel4s-sdk_native0.4_2.13 otel4s-sdk_native0.4_3 otel4s-sdk-common_2.13 otel4s-sdk-common_3 otel4s_2.13 otel4s_3 otel4s_2.13 otel4s_3 otel4s-sdk-trace_native0.4_2.13 otel4s-sdk-trace_native0.4_3 otel4s-sdk_sjs1_2.13 otel4s-sdk_sjs1_3 otel4s-sdk_2.13 otel4s-sdk_3 otel4s-sdk-trace_2.13 otel4s-sdk-trace_3
modules-ignore: otel4s-sdk-exporter-common_sjs1_2.13 otel4s-sdk-exporter-common_sjs1_3 otel4s-sdk-common_native0.4_2.13 otel4s-sdk-common_native0.4_3 otel4s-benchmarks_2.13 otel4s-benchmarks_3 otel4s-examples_2.13 otel4s-examples_3 otel4s-sdk-common_sjs1_2.13 otel4s-sdk-common_sjs1_3 otel4s-sdk-exporter_2.13 otel4s-sdk-exporter_3 otel4s-sdk-trace_sjs1_2.13 otel4s-sdk-trace_sjs1_3 otel4s-sdk-exporter-common_native0.4_2.13 otel4s-sdk-exporter-common_native0.4_3 otel4s-sdk-exporter-trace_2.13 otel4s-sdk-exporter-trace_3 otel4s_2.13 otel4s_3 docs_2.13 docs_3 otel4s-sdk-exporter-proto_2.13 otel4s-sdk-exporter-proto_3 otel4s-sdk-exporter-proto_sjs1_2.13 otel4s-sdk-exporter-proto_sjs1_3 otel4s-sdk_native0.4_2.13 otel4s-sdk_native0.4_3 otel4s-sdk-exporter-trace_native0.4_2.13 otel4s-sdk-exporter-trace_native0.4_3 otel4s-sdk-common_2.13 otel4s-sdk-common_3 otel4s_2.13 otel4s_3 otel4s_2.13 otel4s_3 otel4s-sdk-trace_native0.4_2.13 otel4s-sdk-trace_native0.4_3 otel4s-sdk-exporter-proto_native0.4_2.13 otel4s-sdk-exporter-proto_native0.4_3 otel4s-sdk-exporter-common_2.13 otel4s-sdk-exporter-common_3 otel4s-sdk-exporter-trace_sjs1_2.13 otel4s-sdk-exporter-trace_sjs1_3 otel4s-sdk-exporter_sjs1_2.13 otel4s-sdk-exporter_sjs1_3 otel4s-sdk_sjs1_2.13 otel4s-sdk_sjs1_3 otel4s-sdk_2.13 otel4s-sdk_3 otel4s-sdk-exporter_native0.4_2.13 otel4s-sdk-exporter_native0.4_3 otel4s-sdk-trace_2.13 otel4s-sdk-trace_3
configs-ignore: test scala-tool scala-doc-tool test-internal

validate-steward:
Expand Down
109 changes: 106 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.5"

ThisBuild / organization := "org.typelevel"
Expand Down Expand Up @@ -27,6 +25,8 @@ val Scala213 = "2.13.12"
ThisBuild / crossScalaVersions := Seq(Scala213, "3.3.1")
ThisBuild / scalaVersion := Scala213 // the default Scala

ThisBuild / githubWorkflowBuildPreamble ++= nativeBrewInstallWorkflowSteps.value

val CatsVersion = "2.10.0"
val CatsEffectVersion = "3.5.2"
val CatsMtlVersion = "1.4.0"
Expand All @@ -38,11 +38,15 @@ val MUnitScalaCheckEffectVersion = "2.0.0-M2"
val OpenTelemetryVersion = "1.33.0"
val OpenTelemetryInstrumentationVersion = "1.32.0"
val OpenTelemetrySemConvVersion = "1.23.1-alpha"
val OpenTelemetryProtoVersion = "1.0.0-alpha"
val PekkoStreamVersion = "1.0.2"
val PekkoHttpVersion = "1.0.0"
val PlatformVersion = "1.0.2"
val ScodecVersion = "1.1.38"
val VaultVersion = "3.5.0"
val Http4sVersion = "0.23.25"
val CirceVersion = "0.14.6"
val EpollcatVersion = "0.1.6"

lazy val scalaReflectDependency = Def.settings(
libraryDependencies ++= {
Expand Down Expand Up @@ -77,6 +81,10 @@ lazy val root = tlCrossRootProject
`sdk-common`,
`sdk-trace`,
sdk,
`sdk-exporter-common`,
`sdk-exporter-proto`,
`sdk-exporter-trace`,
`sdk-exporter`,
`testkit-common`,
`testkit-metrics`,
testkit,
Expand Down Expand Up @@ -198,12 +206,104 @@ lazy val sdk = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.enablePlugins(NoPublishPlugin)
.in(file("sdk/all"))
.dependsOn(`sdk-common`, `sdk-trace`)
.dependsOn(core, `sdk-common`, `sdk-trace`)
.settings(
name := "otel4s-sdk"
)
.settings(scalafixSettings)

//
// SDK exporter
//

lazy val `sdk-exporter-common` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("sdk-exporter/common"))
.enablePlugins(NoPublishPlugin)
.dependsOn(`sdk-common`)
.settings(
name := "otel4s-sdk-exporter-common",
startYear := Some(2023)
)
.settings(munitDependencies)
.settings(scalafixSettings)

lazy val `sdk-exporter-proto` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.enablePlugins(NoPublishPlugin)
.in(file("sdk-exporter/proto"))
.settings(
name := "otel4s-sdk-exporter-proto",
Compile / PB.protoSources += baseDirectory.value.getParentFile / "src" / "main" / "protobuf",
Compile / PB.targets ++= Seq(
scalapb.gen(grpc = false) -> (Compile / sourceManaged).value / "scalapb"
),
// We use open-telemetry protobuf spec to generate models
// See https://scalapb.github.io/docs/third-party-protos/#there-is-a-library-on-maven-with-the-protos-and-possibly-generated-java-code
libraryDependencies ++= Seq(
"io.opentelemetry.proto" % "opentelemetry-proto" % OpenTelemetryProtoVersion % "protobuf-src" intransitive ()
)
)

lazy val `sdk-exporter-trace` =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("sdk-exporter/trace"))
.enablePlugins(NoPublishPlugin, IntegrationEnvPlugin)
.dependsOn(
`sdk-exporter-common`,
`sdk-exporter-proto`,
`sdk-trace` % "compile->compile;test->test"
)
.settings(
name := "otel4s-sdk-exporter-trace",
startYear := Some(2023),
libraryDependencies ++= Seq(
"org.http4s" %%% "http4s-ember-client" % Http4sVersion,
"org.http4s" %%% "http4s-circe" % Http4sVersion,
"org.scalameta" %%% "munit-scalacheck" % MUnitVersion % Test,
"io.circe" %%% "circe-generic" % CirceVersion % Test
),
integrationEnvProvider := IntegrationEnv.DockerCompose.Provider(
composeProjectName = s"${name.value}-it-env",
dockerComposeFile =
crossProjectBaseDirectory.value / "docker" / "docker-compose.yml",
network = None
),
Test / testOptions := integrationEnvTestOpts.value
)
.jsSettings(
scalaJSLinkerConfig ~= (_.withESFeatures(
_.withESVersion(org.scalajs.linker.interface.ESVersion.ES2018)
)),
Test / scalaJSLinkerConfig ~= (_.withModuleKind(
ModuleKind.CommonJSModule
))
)
.nativeEnablePlugins(ScalaNativeBrewedConfigPlugin)
.nativeSettings(
libraryDependencies += "com.armanbilge" %%% "epollcat" % EpollcatVersion % Test,
Test / nativeBrewFormulas ++= Set("s2n", "utf8proc"),
Test / envVars ++= Map("S2N_DONT_MLOCK" -> "1")
)
.settings(munitDependencies)

lazy val `sdk-exporter` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("sdk-exporter/all"))
.enablePlugins(NoPublishPlugin)
.dependsOn(`sdk-exporter-common`, `sdk-exporter-trace`)
.settings(
name := "otel4s-sdk-exporter"
)
.settings(scalafixSettings)

//
// Testkit
//

lazy val `testkit-common` = crossProject(JVMPlatform)
.crossType(CrossType.Full)
.in(file("testkit/common"))
Expand Down Expand Up @@ -399,6 +499,9 @@ lazy val unidocs = project
`sdk-common`.jvm,
`sdk-trace`.jvm,
sdk.jvm,
`sdk-exporter-common`.jvm,
`sdk-exporter-trace`.jvm,
`sdk-exporter`.jvm,
`testkit-common`.jvm,
`testkit-metrics`.jvm,
testkit.jvm,
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
typelevelShell = {
jdk.package = pkgs.jdk8;
nodejs.enable = true;
native.libraries = [ pkgs.zlib pkgs.s2n ];
native.enable = true;
};
};
Expand Down
7 changes: 7 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")
addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")
addSbtPlugin("io.github.irevive" % "sbt-integration-env" % "0.4.0")
addSbtPlugin(
"com.armanbilge" % "sbt-scala-native-config-brew-github-actions" % "0.2.0-RC1"
)

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.14"
22 changes: 22 additions & 0 deletions sdk-exporter/trace/docker/config/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
receivers:
otlp:
protocols: # enable OpenTelemetry Protocol receiver, both gRPC and HTTP
grpc:
http:

exporters:
jaeger: # export received traces to Jaeger
endpoint: jaeger:14250
tls:
insecure: true

processors:
batch:
timeout: 0 # send data immediately

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [jaeger]
17 changes: 17 additions & 0 deletions sdk-exporter/trace/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.7'
services:
otel-collector: # receives application metrics and traces via gRPC or HTTP protocol
image: otel/opentelemetry-collector-contrib
command: [--config=/etc/otel-collector-config.yaml]
volumes:
- "./config/otel-collector-config.yaml:/etc/otel-collector-config.yaml"
ports:
- "4317:4317" # OTLP gRPC receiver
- "4318:4318" # OTLP http receiver

jaeger: # stores traces received from the OpenTelemetry Collector
image: jaegertracing/all-in-one:latest
ports:
- "14250:14250"
- "16685:16685" # GRPC
- "16686:16686" # UI
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.otel4s.sdk.exporter.otlp

import munit.CatsEffectSuite

trait ExporterSuitePlatform { self: CatsEffectSuite => }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2023 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.otel4s.sdk.exporter.otlp

import munit.CatsEffectSuite

trait ExporterSuitePlatform { self: CatsEffectSuite => }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.otel4s.sdk.exporter.otlp

import cats.effect.unsafe.IORuntime
import epollcat.unsafe.EpollRuntime
import munit.CatsEffectSuite

trait ExporterSuitePlatform { self: CatsEffectSuite =>
override def munitIORuntime: IORuntime = EpollRuntime.global
}
Loading

0 comments on commit e5c2ccb

Please sign in to comment.