-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Do not merge] Trace API playground #35
Conversation
0d258a2
to
0171d0a
Compare
Examples: examples/src/main/scala/com/example/tracing/JaegerTracing.scala Resource spantracer
.resourceSpan("resource-span")(makeImageLookup(tracer))
.use { case Span.Res(lookup) =>
lookup.exists("my-image")
} Stream spanStream
.resource(tracer.resourceSpan("stream-span")(Resource.unit))
.flatMap(_ => Stream.emits(Seq(1, 2, 3)))
.evalMap(r => tracer.span(s"span-$r").surround(IO.unit))
.compile
.drain Stream span is not ideal, but at least it works out of the box and does not require the fs2 dependency. |
The change set is quite big and it's hard to review it.
|
def traceId: F[Option[String]] | ||
|
||
/** Returns span identifier of a span that is available in a scope. | ||
*/ | ||
def spanId: F[Option[String]] |
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.
I realise this is WIP so not sure if you plan to change this or if the Otel spec has changed, but these are usually represented as byte arrays; e.g TraceId and SpanId in t4c. It would be good to be able to access these directly rather than just the string representation.
Apologies if I've jumped the gun and you're going to change these, or I've missed something and they're represented elsewhere!
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.
It's a draft version and my gut feeling says there will be a lot of changes :)
It would be interesting for me to hear your opinion about the current API.
Open Telemetry has the following info in span context:
String getTraceId();
byte[] getTraceIdBytes();
String getSpanId();
byte[] getSpanIdBytes();
boolean isSampled();
TraceFlags getTraceFlags();
TraceState getTraceState();
boolean isValid();
boolean isRemote();
I believe we can incorporate the majority of attributes.
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.
I'd be happy to see scodec-bits ByteVector
used for byte arrays :) it's a stable dependency used in fs2-core
and beyond.
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.
ah yeah, that makes sense. What we do in t4c is have Show
instances for TraceId
which makes those a bit more FP'y.
Also I made the the isSampled
return an ADT that can turn into a boolean, purely because everyone (including myself) kept getting confused as to what true
meant when it came to sampling!
In terms of the trace context in t4c it more closely follows the W3C standard, so in terms of structure probably doesn't align very well with the Otel spec.
} | ||
} yield new SpanBackendImpl(jTracer, jSpan, scope) | ||
|
||
def reportStatus(backend: Span.Backend[F], ec: Resource.ExitCase): F[Unit] = |
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.
It would be nice to make it configurable. i.e. https://github.com/trace4cats/trace4cats/blob/master/modules/kernel/src/main/scala/trace4cats/kernel/ErrorHandler.scala
|
||
def acquire: F[SpanBackendImpl[F]] = | ||
for { | ||
now <- Sync[F].realTime |
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.
OpenTelemetry requires it to be a realTime
rather than monotonic
I'm closing this PR since it's not relevant anymore. |
This branch contains various experiments with OpenTelemetry tracing.
To simply the review process I made two different PRs:
Currently, the state is stored in
IOLocal
. This approach has several drawbacks:interruptScope
andIOLocal
s fs2#2842The checklist from #11
spanId
andtraceId
fromTrace[F]
Trace[F]
Resource
fs2.Stream
Trace
is not used