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

Experimental sdk-trace module #325

Closed
wants to merge 141 commits into from
Closed

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Oct 1, 2023

Here is an experimental sdk-trace module fully written in Scala.
Most of the design decisions were based on the Java implementation, and some can be reconsidered.

Currently, there is only InMemoryExporter but it's enough to run tests on Scala Native and ScalaJS platforms.
I've copy-pasted the TracerSuite from Java module and all tests pass.
All other cases work as expected:

  • Propagation of a trace context downstream (via W3CTraceContextPropagator)
  • Joining an external span (via W3CTraceContextPropagator)
  • Tracing scope manipulations: explicit parent, root, default propagation
  • Propagation of a context information (via PasstroughPropagator)

Current scope:

  • Decide the visibility of the SDK classes: private, private[trace], etc
  • Add tests
  • Add docs
  • Simplify API that was influenced by Java implementation
  • Add trace state parser to W3CTraceContextPropagator
  • Unify core and sdk API. e.g. sdk should use TextMapPropagator from core

Next steps:

  • Add more propagators
  • Implement otlp gRPC and HTTP exporters
  • Consider an autoloading tool: creating a tracer provider based on the env variables, etc

import org.typelevel.otel4s.trace.SpanContext
import org.typelevel.otel4s.trace.Tracer

final class SdkTracer[F[_]: Concurrent: Clock] private[trace] (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nearly identical to the TracerImpl in the java module. The different part is:

def spanBuilder(name: String): SpanBuilder[F] =
    new SdkSpanBuilder[F](name, scopeInfo, sharedState, scope)

import scala.concurrent.duration._

// Tree-like representation of a span
final case class SpanNode(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy-pasted from the java module

import org.typelevel.otel4s.sdk.trace.exporter.BatchSpanProcessor
import org.typelevel.otel4s.sdk.trace.exporter.InMemorySpanExporter

object TraceSdkExample extends IOApp.Simple {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A fully functional example


object instances {
// We hope this instance is moved into Cats Effect.
implicit def localForIoLocal[F[_]: MonadCancelThrow: LiftIO, E](implicit
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy-pasted from the java module

if (attributes.isEmpty) Applicative[F].unit
else
mutableState.update { s =>
s.copy(attributes = s.attributes |+| Attributes(attributes: _*))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spanLimits should be applied here.
To make it work, we should also tweak the implementation of the Attributes class.

# Conflicts:
#	sdk/common/src/main/scala/org/typelevel/otel4s/sdk/autoconfigure/AutoConfigure.scala
#	sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/autoconfigure/SamplerAutoConfigure.scala
# Conflicts:
#	sdk-exporter/trace/shared/src/test/scala/org/typelevel/otel4s/sdk/exporter/otlp/trace/autoconfigure/OtlpSpanExporterAutoConfigureSuite.scala
# Conflicts:
#	sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/autoconfigure/SpanExportersAutoConfigure.scala
# Conflicts:
#	sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/SdkTracerProvider.scala
#	sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/autoconfigure/TracerProviderAutoConfigureSuite.scala
# Conflicts:
#	build.sbt
#	sdk/all/src/main/scala/org/typelevel/otel4s/sdk/OpenTelemetrySdk.scala
#	sdk/all/src/test/scala/org/typelevel/otel4s/sdk/OpenTelemetrySdkSuite.scala
#	sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/SdkTracerBuilder.scala
#	sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/SdkTraces.scala
#	sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/SdkTracesSuite.scala
@iRevive
Copy link
Contributor Author

iRevive commented Feb 19, 2024

Almost all changes from this branch exist in the main branch.

@iRevive iRevive closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk module Features and improvements to the sdk module tracing Improvements to tracing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants