-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add an opentelemetry
module
#368
Merged
mpilquist
merged 369 commits into
typelevel:series/0.0
from
andimiller:feature/opentelemetry-module
Nov 16, 2022
Merged
Changes from 2 commits
Commits
Show all changes
369 commits
Select commit
Hold shift + click to select a range
df5739b
Update ciris to 2.3.1
scala-steward f645df2
Update fs2-io to 3.2.3
scala-steward 08bb494
Merge pull request #461 from scala-steward/update/fs2-io-3.2.3
mergify[bot] dc20828
Update http4s-client, http4s-dsl to 0.23.7
scala-steward 3bb2968
Update dd-trace-api, dd-trace-ot to 0.91.0
scala-steward 4022648
Update libhoney-java to 1.3.2
scala-steward d114eec
Update sbt to 1.5.6
scala-steward ae1747b
Merge pull request #464 from scala-steward/update/libhoney-java-1.3.2
mergify[bot] d041a5a
Update libhoney-java to 1.4.0
scala-steward 91287f8
Update sbt-scalajs, scalajs-compiler, ... to 1.8.0
scala-steward 46ddaa6
Merge branch 'series/0.1' into xray
armanbilge 1ce5a78
Merge pull request #468 from armanbilge/xray
tpolecat cea6726
Merge remote-tracking branch 'steward/update/sbt-scalajs-crossproject…
armanbilge 1f829f9
Merge remote-tracking branch 'steward/update/sbt-updates-0.6.0' into …
armanbilge c9eb771
Merge remote-tracking branch 'steward/update/kind-projector-0.13.2' i…
armanbilge a28e917
Merge remote-tracking branch 'steward/update/scala-library-2.12.15' i…
armanbilge 5f34271
Merge remote-tracking branch 'steward/update/sbt-scalajs-1.8.0' into …
armanbilge ab58a91
Merge remote-tracking branch 'steward/update/scala3-library-3.1.0' in…
armanbilge f0177c9
Merge remote-tracking branch 'steward/update/mdoc-2.2.24' into topic/…
armanbilge de14bb1
Merge remote-tracking branch 'steward/update/scala-library-2.13.7' in…
armanbilge fc173f2
Merge remote-tracking branch 'steward/update/scala-collection-compat-…
armanbilge a065d5c
Merge remote-tracking branch 'steward/update/grpc-netty-1.42.1' into …
armanbilge 64d1242
Merge remote-tracking branch 'steward/update/netty-tcnative-boringssl…
armanbilge 62d7f60
Merge remote-tracking branch 'steward/update/cats-core-2.7.0' into to…
armanbilge a1ac249
Merge remote-tracking branch 'steward/update/cats-effect-3.3.0' into …
armanbilge 503958e
Merge remote-tracking branch 'steward/update/refined-0.9.28' into top…
armanbilge 643619f
Merge remote-tracking branch 'steward/update/ciris-2.3.1' into topic/…
armanbilge 4773904
Merge remote-tracking branch 'steward/update/http4s-client-0.23.7' in…
armanbilge 37dd3d5
Merge remote-tracking branch 'steward/update/dd-trace-api-0.91.0' int…
armanbilge 056d12f
Merge remote-tracking branch 'steward/update/sbt-1.5.6' into topic/up…
armanbilge 7a5e48a
Merge remote-tracking branch 'steward/update/libhoney-java-1.4.0' int…
armanbilge 77d9d81
Fix compile
armanbilge 2bd14be
Fix conflicting cross version thing
armanbilge 2e2ad62
Poke ci
armanbilge 00cb936
Merge pull request #469 from armanbilge/topic/update-bundle
tpolecat 5f66fe8
Update sbt to 1.5.7
scala-steward 9646d68
Merge pull request #472 from scala-steward/update/sbt-1.5.7
mergify[bot] 89a8450
Update cats-effect, cats-effect-kernel to 3.3.1
scala-steward f8fd182
Merge pull request #478 from scala-steward/update/cats-effect-3.3.1
mergify[bot] 212bd46
Update fs2-io to 3.2.4
scala-steward ce90c60
Merge pull request #479 from scala-steward/update/fs2-io-3.2.4
mergify[bot] 743d3d3
Update cats-effect, cats-effect-kernel to 3.3.2
scala-steward 28097fb
Merge pull request #481 from scala-steward/update/cats-effect-3.3.2
mergify[bot] 9d79614
Update cats-effect, cats-effect-kernel to 3.3.3
scala-steward 18d7095
Merge pull request #482 from scala-steward/update/cats-effect-3.3.3
mergify[bot] 823aab7
Setting appropriate error flags and logs in JaegerSpan
msosnicki 0b08083
Update Kernel.scala - cleanup documentation
iRevive cdd719e
Update grpc-netty to 1.42.2
scala-steward 38012c2
Merge pull request #488 from scala-steward/update/grpc-netty-1.42.2
mergify[bot] a2a259b
Merge branch 'series/0.1' into patch-1
iRevive 31954a0
Update cats-effect, cats-effect-kernel to 3.3.4
scala-steward 455a716
Merge pull request #489 from scala-steward/update/cats-effect-3.3.4
mergify[bot] dd448df
Merge branch 'series/0.1' into jaeger-error-case
msosnicki bfc5851
Update ciris to 2.3.2
scala-steward 40ac9a1
Merge pull request #490 from scala-steward/update/ciris-2.3.2
mergify[bot] 1d198fd
Make DDSpan public
DougC 90d76d5
Update scala-library to 2.13.8
scala-steward ebb5fc8
Merge pull request #492 from scala-steward/update/scala-library-2.13.8
mergify[bot] bd2cbb5
Merge branch 'series/0.1' into make-ddspan-public
DougC 12e8722
Update slf4j-simple to 1.7.33
scala-steward 731fbcd
Merge pull request #493 from scala-steward/update/slf4j-simple-1.7.33
mergify[bot] 8a3d401
Merge branch 'series/0.1' into make-ddspan-public
DougC 6010a5c
Update slf4j-simple to 1.7.35
scala-steward 6cc9b22
Merge pull request #498 from scala-steward/update/slf4j-simple-1.7.35
mergify[bot] 030c3d2
Merge branch 'series/0.1' into make-ddspan-public
DougC 499075f
Update cats-effect, cats-effect-kernel to 3.3.5
scala-steward f2a5e10
Merge pull request #506 from scala-steward/update/cats-effect-3.3.5
mergify[bot] c776fcc
Merge branch 'series/0.1' into make-ddspan-public
DougC 52ddd6e
Update scala3-library, ... to 3.1.1
scala-steward 85c496e
Merge pull request #508 from scala-steward/update/scala3-library-3.1.1
mergify[bot] 281327d
Update libhoney-java to 1.4.1
scala-steward f0fd10e
Merge pull request #509 from scala-steward/update/libhoney-java-1.4.1
mergify[bot] e094e26
Update sbt-header to 5.6.5
scala-steward 95112cf
Merge pull request #512 from scala-steward/update/sbt-header-5.6.5
mergify[bot] 34f0f67
Update slf4j-simple to 1.7.36
scala-steward 4af5b22
Merge pull request #513 from scala-steward/update/slf4j-simple-1.7.36
mergify[bot] 96ebd10
Merge branch 'series/0.1' into make-ddspan-public
DougC 598b36f
Update fs2-io to 3.2.5
scala-steward 3efa0e7
Merge pull request #521 from scala-steward/update/fs2-io-3.2.5
mergify[bot] 8d76cf7
Update cats-effect, cats-effect-kernel to 3.3.6
scala-steward 351d888
Merge pull request #525 from scala-steward/update/cats-effect-3.3.6
mergify[bot] 63cf973
Update cats-effect, cats-effect-kernel to 3.3.7
scala-steward 2b650e8
Merge pull request #529 from scala-steward/update/cats-effect-3.3.7
mergify[bot] e61094f
Fix example in documentation
ant8e 017726c
Update cats-effect, cats-effect-kernel to 3.3.8
scala-steward 7ba762f
Merge pull request #535 from scala-steward/update/cats-effect-3.3.8
mergify[bot] 6ddfbf7
Update cats-effect, cats-effect-kernel to 3.3.9
scala-steward df9c83d
Merge pull request #538 from scala-steward/update/cats-effect-3.3.9
mergify[bot] 06a5d76
Add OpenTelemetry module
hamnis cb9326f
Update example in README.md
hamnis 08ad907
include parent span in child
hamnis dded221
Add TextMapPropagators to example
hamnis 1917249
Update fs2-io to 3.2.6
scala-steward 73a11ed
Merge pull request #545 from scala-steward/update/fs2-io-3.2.6
mergify[bot] 2cb326f
Update fs2-io to 3.2.7
scala-steward 15359b7
Merge pull request #546 from scala-steward/update/fs2-io-3.2.7
mergify[bot] 1c6c6d1
Update cats-effect, cats-effect-kernel to 3.3.10
scala-steward 715283b
Merge pull request #547 from scala-steward/update/cats-effect-3.3.10
mergify[bot] 0dc8239
Update cats-effect, cats-effect-kernel to 3.3.11
scala-steward 058f325
Merge pull request #549 from scala-steward/update/cats-effect-3.3.11
mergify[bot] 5e5b2b7
Update scala3-library, ... to 3.1.2
scala-steward 4261cf7
Merge pull request #550 from scala-steward/update/scala3-library-3.1.2
mergify[bot] 8a83ad1
Update scodec-bits to 1.1.31
scala-steward a11412c
Merge pull request #555 from scala-steward/update/scodec-bits-1.1.31
mergify[bot] edcda65
Update opencensus-exporter-trace-ocagent to 0.31.1
scala-steward 08c71b1
Update refined to 0.9.29
scala-steward 32377b4
Update ip4s-core to 3.1.3
scala-steward ff2e34c
Merge pull request #561 from scala-steward/update/ip4s-core-3.1.3
mergify[bot] c1e470d
Update circe-core to 0.14.2
scala-steward 5bb0f2b
Update cats-effect, cats-effect-kernel to 3.3.12
scala-steward 8da87bc
Merge pull request #564 from scala-steward/update/cats-effect-3.3.12
mergify[bot] bcef34d
Update fs2-io to 3.2.9
scala-steward 4766952
Update paradox-theme-generic, sbt-paradox to 0.10.2
scala-steward 059e037
Update sbt-updates to 0.6.3
scala-steward b4bafc9
Update scala-java-time to 2.4.0
scala-steward 76283ee
Update jaeger-client to 1.8.1
scala-steward 0c62bb2
Update scala-library to 2.12.16
scala-steward 7d09953
Update scala3-library, ... to 3.1.3
scala-steward af283e3
Update scodec-bits to 1.1.34
scala-steward 4cb590f
Update cats-core to 2.8.0
scala-steward 6814590
Update cats-mtl to 1.3.0
scala-steward efc2741
Merge pull request #567 from scala-steward/update/fs2-io-3.2.9
mergify[bot] 68e96f5
Revert commit(s) c1e470d
scala-steward 3d58411
Merge branch 'series/0.1' into update/circe-core-0.14.2
scala-steward dc0da7a
Update circe-core to 0.14.2
scala-steward 05aa35c
add long to the allowed values
massimosiani 00f6a06
Update fs2-io to 3.2.10
scala-steward abe8c1b
Update telemetry-core, ... to 0.15.0
scala-steward f8db934
Update ciris to 2.3.3
scala-steward d0113d2
Update cats-effect, cats-effect-kernel to 3.3.14
scala-steward a584d09
Merge pull request #586 from scala-steward/update/fs2-io-3.2.10
mergify[bot] 59954da
Applied Scalafix rule(s) github:typelevel/cats/Cats_v2_2_0?sha=v2.2.0
scala-steward 69240f0
Update log4cats-core, log4cats-slf4j to 2.4.0
scala-steward ad1c658
Revert commit(s) dc0da7a
scala-steward 2e08a42
Merge branch 'series/0.1' into update/circe-core-0.14.2
scala-steward 90a5c49
Update circe-core to 0.14.2
scala-steward bfe02b0
Update netty-tcnative-boringssl-static to 2.0.54.Final
scala-steward c59ad97
Update fs2-io to 3.2.11
scala-steward c4edbe1
Update mdoc, sbt-mdoc to 2.3.3
scala-steward 9441de9
Merge pull request #595 from scala-steward/update/fs2-io-3.2.11
mergify[bot] 6858f80
Revert commit(s) 90a5c49
scala-steward ad730b9
Merge branch 'series/0.1' into update/circe-core-0.14.2
scala-steward a7ec812
Update circe-core to 0.14.2
scala-steward c522272
Update scala-collection-compat to 2.8.1
scala-steward 7ddd1ef
Update fs2-io to 3.2.12
scala-steward 04a4b77
Update libhoney-java to 1.5.2
scala-steward 4233eb9
Merge pull request #601 from scala-steward/update/fs2-io-3.2.12
mergify[bot] 236a57f
Revert commit(s) a7ec812
scala-steward d0f0e8f
Merge branch 'series/0.1' into update/circe-core-0.14.2
scala-steward 00d452a
Update circe-core to 0.14.2
scala-steward fe0c21b
Update slf4j-simple to 2.0.0
scala-steward 2dd6e54
Update grpc-netty to 1.49.0
scala-steward bff998e
Update http4s-client, http4s-dsl to 0.23.15
scala-steward e4dd6f7
Update dd-trace-api, dd-trace-ot to 0.108.1
scala-steward 83eefb4
Update fs2-io to 3.2.14
scala-steward b90cc4a
Merge pull request #611 from scala-steward/update/fs2-io-3.2.14
mergify[bot] 343da43
Revert commit(s) 00d452a
scala-steward e714e51
Merge branch 'series/0.1' into update/circe-core-0.14.2
scala-steward 4729253
Update circe-core to 0.14.2
scala-steward 9f96f2b
Merge branch 'series/0.1' into update/dd-trace-api-0.108.1
mpilquist dd5e2fe
Merge pull request #610 from scala-steward/update/dd-trace-api-0.108.1
mpilquist 01dc3b8
Merge branch 'series/0.1' into update/http4s-client-0.23.15
mpilquist 08764c5
Merge pull request #608 from scala-steward/update/http4s-client-0.23.15
mpilquist 4bd4fcd
Merge branch 'series/0.1' into update/grpc-netty-1.49.0
mpilquist 0b0f83d
Merge pull request #607 from scala-steward/update/grpc-netty-1.49.0
mpilquist 079f20d
Merge branch 'series/0.1' into update/slf4j-simple-2.0.0
mpilquist 4fcca56
Merge pull request #605 from scala-steward/update/slf4j-simple-2.0.0
mpilquist 8fd6f36
Merge branch 'series/0.1' into update/libhoney-java-1.5.2
mpilquist eaf5bae
Merge pull request #603 from scala-steward/update/libhoney-java-1.5.2
mpilquist 6fbcf94
Merge branch 'series/0.1' into update/scala-collection-compat-2.8.1
mpilquist 6d05f1f
Merge pull request #599 from scala-steward/update/scala-collection-co…
mpilquist 25efb4c
Merge branch 'series/0.1' into update/mdoc-2.3.3
mpilquist 2013124
Merge pull request #597 from scala-steward/update/mdoc-2.3.3
mpilquist 2b5bc0b
Merge branch 'series/0.1' into update/netty-tcnative-boringssl-static…
mpilquist 45a1d7e
Merge pull request #594 from scala-steward/update/netty-tcnative-bori…
mpilquist 3b756ea
Merge branch 'series/0.1' into update/log4cats-core-2.4.0
mpilquist cc49630
Merge pull request #592 from scala-steward/update/log4cats-core-2.4.0
mpilquist 0238b6f
Merge branch 'series/0.1' into update/cats-effect-3.3.14
mpilquist f37b2c5
Merge pull request #591 from scala-steward/update/cats-effect-3.3.14
mergify[bot] 9e07327
Merge branch 'series/0.1' into update/ciris-2.3.3
mpilquist da7ddbc
Merge pull request #589 from scala-steward/update/ciris-2.3.3
mergify[bot] 278ff9e
Merge branch 'series/0.1' into update/telemetry-core-0.15.0
mpilquist 867565f
Merge pull request #588 from scala-steward/update/telemetry-core-0.15.0
mpilquist c213bdd
Merge branch 'series/0.1' into update/cats-mtl-1.3.0
mpilquist c3cdbd0
Merge pull request #583 from scala-steward/update/cats-mtl-1.3.0
mpilquist 7bf92d4
Merge branch 'series/0.1' into update/cats-core-2.8.0
mpilquist cd59035
Update Scala.js and SBT
mpilquist 7d91990
Merge pull request #581 from scala-steward/update/cats-core-2.8.0
mpilquist c5379e3
Merge branch 'series/0.1' into update/scodec-bits-1.1.34
mpilquist 7d096ef
Merge pull request #580 from scala-steward/update/scodec-bits-1.1.34
mergify[bot] 6b16249
Merge branch 'series/0.1' into update/scala3-library-3.1.3
mpilquist e289963
Merge pull request #579 from scala-steward/update/scala3-library-3.1.3
mpilquist 38f2af1
Merge branch 'series/0.1' into update/scala-library-2.12.16
mpilquist d52d313
Migrate to sbt-typelevel
armanbilge ab4af58
Merge remote-tracking branch 'upstream/series/0.1' into topic/sbt-typ…
armanbilge 25c3246
Merge branch 'series/0.1' into topic/sbt-typelevel
armanbilge 449a863
Merge pull request #578 from scala-steward/update/scala-library-2.12.16
mpilquist 30933e6
Merge branch 'series/0.1' into topic/sbt-typelevel
mpilquist bbcaf95
regenerate workflow
armanbilge f1742a3
add vestigial build job
armanbilge d362d33
regenerate workflow
armanbilge 592c300
Merge pull request #612 from armanbilge/topic/sbt-typelevel
mpilquist 0bf7e84
Merge branch 'series/0.1' into update/jaeger-client-1.8.1
mpilquist 79d84dc
Merge pull request #574 from scala-steward/update/jaeger-client-1.8.1
mpilquist 1fc43ac
Merge branch 'series/0.1' into update/scala-java-time-2.4.0
mpilquist 0d2860c
Merge pull request #572 from scala-steward/update/scala-java-time-2.4.0
mpilquist ecce44d
Merge branch 'series/0.1' into update/sbt-updates-0.6.3
mpilquist 40550b7
Merge pull request #571 from scala-steward/update/sbt-updates-0.6.3
mpilquist 9161140
Merge branch 'series/0.1' into update/paradox-theme-generic-0.10.2
mpilquist 3ef8f2c
Merge branch 'series/0.1' into update/circe-core-0.14.2
mpilquist a416b6e
Merge pull request #563 from scala-steward/update/circe-core-0.14.2
mpilquist f25ca3f
Merge branch 'series/0.1' into update/refined-0.9.29
mpilquist 832706e
Cross-build for Native
armanbilge 261af2e
Merge branch 'series/0.1' into feature/native
armanbilge 6c6c784
Publish snapshots
armanbilge d7f6b9c
Merge pull request #560 from scala-steward/update/refined-0.9.29
mpilquist 3b636c5
Merge branch 'series/0.1' into feature/native
mpilquist 4609b80
fix native MiMa
armanbilge b21a4ad
Merge pull request #613 from armanbilge/feature/native
mpilquist 2216a00
Merge branch 'series/0.1' into update/paradox-theme-generic-0.10.2
mpilquist 239289f
Merge pull request #569 from scala-steward/update/paradox-theme-gener…
mpilquist f728732
Merge branch 'series/0.1' into update/opencensus-exporter-trace-ocage…
mpilquist 8022162
Merge pull request #557 from scala-steward/update/opencensus-exporter…
mpilquist 7d27fc0
Merge branch 'series/0.1' into patch-1
mpilquist c202765
Merge pull request #531 from ant8e/patch-1
mpilquist dd9455b
Merge branch 'series/0.1' into long-as-value
mpilquist 3662f1b
Add float and double support
mpilquist e1cd586
Merge pull request #585 from massimosiani/long-as-value
mpilquist bb1f5a0
Merge branch 'series/0.1' into patch-1
mpilquist 1cac5a1
Merge pull request #485 from iRevive/patch-1
mpilquist 0f732fd
Merge branch 'series/0.1' into make-ddspan-public
mpilquist b43126e
Merge pull request #614 from tpolecat/make-ddspan-public
mpilquist 1398774
Merge branch 'series/0.1' into jaeger-error-case
mpilquist c66f0b3
Merge pull request #484 from msosnicki/jaeger-error-case
mpilquist b15a3c4
Merge branch 'series/0.1' into topic/noop
mpilquist f8b4f84
Fix typo
mpilquist 8d6bbd7
Merge pull request #362 from mpilquist/topic/noop
mpilquist 3daed0f
Merge branch 'series/0.1' into bring-odin-module-back
mpilquist 30dfede
Update workflow
mpilquist 2bee708
Update build.sbt
mpilquist 34b6b0e
Fix headers in odin module
mpilquist 6fa5274
Merge branch 'bring-odin-module-back' of https://github.com/ybasket/n…
mpilquist a3a0f3b
Merge pull request #391 from ybasket/bring-odin-module-back
mpilquist 323d7d7
Merge branch 'series/0.1' into opentelemetry
mpilquist 51104be
Fix doc typo
mpilquist f48ebda
Update workflow
mpilquist 3e3e327
Mima
mpilquist 01b07b1
Merge pull request #539 from hamnis/opentelemetry
mpilquist 36a8ab8
Merge branch 'series/0.1' into feature/opentelemetry-module
mpilquist 1aab064
Update otel doc page
mpilquist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# OpenTelemetry | ||
|
||
The `natchez-opentelemetry` module provides a backend that uses [OpenTelemetry](https://opentelemetry.io) to report spans. | ||
|
||
To use it, add the following dependency. | ||
|
||
@@dependency[sbt,Maven,Gradle] { | ||
group="$org$" | ||
artifact="natchez-opentelemetry-2.13" | ||
version="$version$" | ||
} | ||
|
||
Then add any exporter, for example: | ||
|
||
@@dependency[sbt,Maven,Gradle] { | ||
group="io.opentelemetry" | ||
artifact="opentelemetry-exporter-otlp" | ||
version="1.4.0-SNAPSHOT" | ||
} | ||
|
||
## Note on the OpenTelemetry version numbers | ||
|
||
Currently, this depends on `1.4.0-SNAPSHOT` because of a bug I discovered upstream while writing this, where the `shutdown()` calls could block indefinitely, this has been fixed in the snapshot build, and this note can be removed once there's a stable release with this fix. | ||
|
||
## Configuring an OpenTelemetry entrypoint | ||
|
||
There are two methods you'll need to construct an `OpenTelemetry` `EndPoint`. | ||
|
||
`OpenTelemetry.lift` is used to turn an `F[_]` that constructs a `SpanExporter`, `SpanProcessor` or `SdkTraceProvider` into a `Resource` that will shut it down cleanly. | ||
This takes a `String` of what you've constructed, so we can give a nice error if it fails to shut down cleanly. | ||
|
||
The `OpenTelemetry.entryPoint` method takes a boolean called `globallyRegister` which tells it whether to register this `OpenTelemetrySdk` globally, this may be helpful if you have other java dependencies that use the global tracer, it defaults to false. | ||
It also takes an `OpenTelemetrySdkBuilder => Resource[F, OpenTelemetrySdkBuilder]` so that you can configure the Sdk. | ||
|
||
Here's an example of configuring one with the `otlp` exporter with batch span processing: | ||
|
||
```scala mdoc:passthrough | ||
import natchez.EntryPoint | ||
import natchez.opentelemetry.OpenTelemetry | ||
import cats.effect._ | ||
import io.opentelemetry.api.common.Attributes | ||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes | ||
import io.opentelemetry.sdk.resources.{Resource => OtelResource} | ||
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator | ||
import io.opentelemetry.context.propagation.ContextPropagators | ||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter | ||
import io.opentelemetry.sdk.trace.SdkTracerProvider | ||
import io.opentelemetry.sdk.trace.`export`.BatchSpanProcessor | ||
|
||
def entryPoint[F[_]: Async]: Resource[F, EntryPoint[F]] = | ||
for { | ||
exporter <- OpenTelemetry.lift( | ||
"OtlpGrpcSpanExporter", | ||
Sync[F].delay { | ||
OtlpGrpcSpanExporter.builder() | ||
.setEndpoint("http://localhost:4317") | ||
.build() | ||
} | ||
) | ||
processor <- OpenTelemetry.lift( | ||
"BatchSpanProcessor", | ||
Sync[F].delay { | ||
BatchSpanProcessor.builder(exporter).build() | ||
} | ||
) | ||
tracer <- OpenTelemetry.lift( | ||
"Tracer", | ||
Sync[F].delay { | ||
SdkTracerProvider.builder() | ||
.setResource( | ||
OtelResource.create( | ||
Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenTelemetryExample") | ||
) | ||
) | ||
.addSpanProcessor(processor) | ||
.build() | ||
} | ||
) | ||
ep <- OpenTelemetry.entryPoint(globallyRegister = true) { builder => | ||
Resource.eval(Sync[F].delay { | ||
builder | ||
.setTracerProvider(tracer) | ||
.setPropagators( | ||
ContextPropagators.create(W3CTraceContextPropagator.getInstance()) | ||
) | ||
} | ||
)} | ||
} yield ep | ||
``` |
79 changes: 79 additions & 0 deletions
79
modules/examples/src/main/scala-2/OpenTelemetryExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import cats.data.Kleisli | ||
import cats.effect._ | ||
import cats.implicits._ | ||
import io.opentelemetry.api.common.Attributes | ||
import io.opentelemetry.sdk.resources.{Resource => OtelResource} | ||
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator | ||
import io.opentelemetry.context.propagation.ContextPropagators | ||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter | ||
import io.opentelemetry.sdk.trace.SdkTracerProvider | ||
import io.opentelemetry.sdk.trace.`export`.BatchSpanProcessor | ||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes | ||
import natchez.{EntryPoint, Span, Trace} | ||
import natchez.opentelemetry.OpenTelemetry | ||
|
||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration.DurationInt | ||
|
||
// change this into an object if you'd like to run it | ||
class OpenTelemetryExample extends IOApp { | ||
def entryPoint[F[_]: Async]: Resource[F, EntryPoint[F]] = | ||
for { | ||
exporter <- OpenTelemetry.lift( | ||
"OtlpGrpcSpanExporter", | ||
Sync[F].delay { | ||
OtlpGrpcSpanExporter.builder() | ||
.setEndpoint("http://localhost:4317") | ||
.build() | ||
} | ||
) | ||
processor <- OpenTelemetry.lift( | ||
"BatchSpanProcessor", | ||
Sync[F].delay { | ||
BatchSpanProcessor.builder(exporter).build() | ||
} | ||
) | ||
tracer <- OpenTelemetry.lift( | ||
"Tracer", | ||
Sync[F].delay { | ||
SdkTracerProvider.builder() | ||
.setResource( | ||
OtelResource.create( | ||
Attributes.of(ResourceAttributes.SERVICE_NAME, "OpenTelemetryExample") | ||
) | ||
) | ||
.addSpanProcessor(processor) | ||
.build() | ||
} | ||
) | ||
ep <- OpenTelemetry.entryPoint(globallyRegister = true) { builder => | ||
Resource.eval(Sync[F].delay { | ||
builder | ||
.setTracerProvider(tracer) | ||
.setPropagators( | ||
ContextPropagators.create(W3CTraceContextPropagator.getInstance()) | ||
) | ||
} | ||
)} | ||
} yield ep | ||
|
||
override def run(args: List[String]): IO[ExitCode] = | ||
entryPoint[IO].use { ep => | ||
ep.root("root span").use { span => | ||
span.put("service.name" -> "natchez opentelemetry example") *> | ||
program[Kleisli[IO, Span[IO], *]].apply(span).as(ExitCode.Success) | ||
} | ||
} | ||
|
||
def program[F[_]: Sync: Trace: Timer]: F[Unit] = | ||
Trace[F].traceId.flatTap(tid => Sync[F].delay { println(s"did some work with traceid of $tid") }) *> | ||
Trace[F].span("outer span") { | ||
Trace[F].put("foo" -> "bar") *> | ||
(Trace[F].span("first thing") { | ||
Timer[F].sleep(2.seconds) | ||
}, | ||
Trace[F].span("second thing") { | ||
Timer[F].sleep(2.seconds) | ||
}).tupled | ||
}.void | ||
} |
60 changes: 60 additions & 0 deletions
60
modules/opentelemetry/src/main/scala/natchez/opentelemetry/OpenTelemetry.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2019-2020 by Rob Norris and Contributors | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package natchez | ||
package opentelemetry | ||
|
||
import cats.effect._ | ||
import cats.implicits._ | ||
import io.opentelemetry.api.GlobalOpenTelemetry | ||
import io.opentelemetry.api.trace.Tracer | ||
import io.opentelemetry.sdk.{OpenTelemetrySdk, OpenTelemetrySdkBuilder} | ||
|
||
import java.net.URI | ||
|
||
object OpenTelemetry { | ||
private final val instrumentationName = "natchez.opentelemetry" | ||
|
||
// Helper methods to help you construct Otel resources that clean themselves up | ||
// We need a name so the failure error can contain something useful | ||
def lift[F[_]: Async, T: Shutdownable](name: String, create: F[T]): Resource[F, T] = | ||
Resource.make(create) { t => | ||
Sync[F].delay { Shutdownable[T].shutdown(t) } | ||
.flatMap(Utils.asyncFromCompletableResultCode(s"$name cleanup", _)) | ||
} | ||
|
||
def entryPoint[F[_] : Sync](uriPrefix: Option[URI] = None, globallyRegister: Boolean = false)( | ||
configure: OpenTelemetrySdkBuilder => Resource[F, OpenTelemetrySdkBuilder] | ||
): Resource[F, EntryPoint[F]] = { | ||
val register: OpenTelemetrySdkBuilder => Resource[F, (OpenTelemetrySdk, Tracer)] = { b => | ||
Resource.make( | ||
Sync[F].delay { | ||
val sdk = if (globallyRegister) | ||
b.buildAndRegisterGlobal() | ||
else | ||
b.build() | ||
val tracer = sdk.getTracer(instrumentationName) | ||
(sdk, tracer) | ||
} | ||
) { case (_, _) => | ||
Sync[F].delay { | ||
if (globallyRegister) | ||
GlobalOpenTelemetry.resetForTest() // this seems to be the only way to deregister it | ||
} | ||
} | ||
} | ||
Resource.eval(Sync[F].delay { OpenTelemetrySdk.builder() }) | ||
.flatMap(configure) | ||
.flatMap(register) | ||
.map { case (sdk, tracer) => | ||
OpenTelemetryEntryPoint(sdk, tracer, uriPrefix) | ||
} | ||
} | ||
|
||
def globalEntryPoint[F[_]: Sync](uriPrefix: Option[URI] = None): F[OpenTelemetryEntryPoint[F]] = | ||
Sync[F].delay { | ||
val ot = GlobalOpenTelemetry.get() | ||
OpenTelemetryEntryPoint(ot, ot.getTracer(instrumentationName), uriPrefix) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
modules/opentelemetry/src/main/scala/natchez/opentelemetry/OpenTelemetryEntryPoint.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2019-2020 by Rob Norris and Contributors | ||
// This software is licensed under the MIT License (MIT). | ||
// For more information see LICENSE or https://opensource.org/licenses/MIT | ||
|
||
package natchez | ||
package opentelemetry | ||
|
||
import cats.effect.{Resource, Sync} | ||
import io.opentelemetry.api.{OpenTelemetry => OtelOpenTelemetry} | ||
import io.opentelemetry.api.trace.{Span => OtelSpan, Tracer => OtelTracer} | ||
import io.opentelemetry.context.Context | ||
import io.opentelemetry.context.propagation.TextMapGetter | ||
|
||
import java.lang | ||
import java.net.URI | ||
import scala.jdk.CollectionConverters._ | ||
|
||
final case class OpenTelemetryEntryPoint[F[_]: Sync](sdk: OtelOpenTelemetry, tracer: OtelTracer, uriPrefix: Option[URI]) extends EntryPoint[F] { | ||
override def root(name: String): Resource[F, Span[F]] = | ||
Resource.make[F, OtelSpan] ( | ||
Sync[F].delay { tracer.spanBuilder(name).startSpan() } | ||
) { s => | ||
Sync[F].delay { s.end() } | ||
}.map { span => | ||
OpenTelemetrySpan(sdk, tracer, span, uriPrefix) | ||
} | ||
|
||
object MapGetter extends TextMapGetter[Map[String, String]] { | ||
override def keys(carrier: Map[String, String]): lang.Iterable[String] = carrier.keys.asJava | ||
override def get(carrier: Map[String, String], key: String): String = carrier.get(key).orNull | ||
} | ||
|
||
override def continue(name: String, kernel: Kernel): Resource[F, Span[F]] = | ||
Resource.make( | ||
Sync[F].delay { | ||
val c = Context.root() | ||
val p = sdk.getPropagators.getTextMapPropagator.extract( | ||
c, | ||
kernel.toHeaders, | ||
MapGetter | ||
) | ||
tracer.spanBuilder(name).setParent(p).startSpan() | ||
} | ||
) { s => | ||
Sync[F].delay { s.end() } | ||
}.map(OpenTelemetrySpan(sdk, tracer, _, uriPrefix)) | ||
|
||
override def continueOrElseRoot(name: String, kernel: Kernel): Resource[F, Span[F]] = | ||
continue(name, kernel) // this is already the behaviour of `continue` since it defaults to not changing the context | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the signature for configure be more accurate to be
OpenTelemetrySdkBuilder => F[OpenTelemetrySdkBuilder]
? Is there a configuration that you'd want to control a finalizer on it?