Skip to content

Proposal to Adopt Tokio Tracing as the OTel Tracing API #1689

@cijothomas

Description

@cijothomas

Introduction

This issue builds upon Option 2 from the discussion OTel Tracing vs Tokio-Tracing, proposing a strategic shift in our approach to traces in OpenTelemetry Rust.

Summary

We propose deprecating the OpenTelemetry (OTel) Tracing API in favor of adopting Tokio Tracing as the official Tracing API, requiring re-instrumentation for those apps already using OTel Tracing API. The functionalities already provided by the OpenTelemetry Tracing SDK, such as Sampling, SpanProcessors, and Exporters, would remain largely unchanged.

Details

  • Default Behavior: tracing macros act as no-ops when no subscriber is configured, consistent with the current OTel API.
  • Instrumentation: Users will transition from the OTel API to tracing macros for span generation, requiring re-instrumentation.
  • Context Propagation: Users will adopt tracing's methods for in-process context propagation (#instrument attribute or using span.in_scope(closure)), necessitating re-instrumentation. For out-of-process context propagation, OpenTelemetry's abstractions will continue to be used, leveraging the strengths of both tracing for in-process and OpenTelemetry for out-of-process propagation.
  • SDK Enablement: Installation of the opentelemetry-sdk crate and configuration of the TracerProvider will remain mostly unchanged.
  • Telemetry Backends: No changes to exported telemetry are expected, nor are changes required in telemetry backends or vendors.
  • Changes to Existing Crates: Once the OpenTelemetry SDK officially recognizes tracing as the API, there will no longer be a need for tracing-opentelemetry, which currently bridges tracing to OTel. Additionally, the opentelemetry-appender-tracing could be integrated into the OTel SDK itself, allowing users to decide if events from tracing should be converted to SpanEvents or LogRecords resolving issues like this.

Advantages

  • Simplification: Reduces the learning curve by consolidating on a single, familiar, and widely adopted tracing mechanism.
  • Community Focus: Concentrates community efforts on one primary tracing ecosystem. Without consolidation, libraries and applications in the Rust ecosystem will be forced to choose one over the other. This often leads to abstractions on top of these choices, effectively leading to further fragmentation, as humorously illustrated in this xkcd comic.
  • Eliminate interop issues: With only a single choice for instrumentation, an entire class of issues arising from lack of interoperability are eliminated, even resolving issues related to Log Correlation as well.
  • Unblocks OTel Rust GA: Resolving this fundamental issue is a prerequisite for progressing OTel Rust towards a GA release.

Challenges

  • Adaptation by tracing: Necessary modifications in tracing to support OpenTelemetry scenarios are crucial. An initial set of required changes is listed below.
  • Community and Governance Acceptance: Endorsement from the OpenTelemetry Technical and Governance Committees is required for OTel Rust to abandon its Tracing API.
  • Migration Help: Since this involves re-instrumentation efforts, we will need to provide the necessary support and guidance (docs etc.) to minimize disruption.
  • OTel SDK Refactoring: Significant portions of the OpenTelemetry tracing SDK code need refactoring.
  • Deviation from other languages: Since tracing was never written with OTel specs in mind, there would always be some differences compared to other languages OTel based Tracing API. For example, Span macros in tracing has the notion of Level, which is not yet present in OTel.

Required Changes in tracing

  1. Introduction of Span Kind, an enum with 5 variants Server,Client,Producer,Consumer,Internal. The tracing-opentelemetry bridge currently handles this through specially named attributes, serving as a short-term workaround.
  2. Span links - the follow_from in tracing might be the equivalent, but this requires more prototyping.
  3. The notion of "target" in tracing is equivalent to instrumentation scope, and could serve as a reasonable alternative, though it lacks support for version, schema URL, and additional descriptive key-value pairs.
  4. tracing macros require attribute keys to be declared at compile time. This is probably manageable as shown by implementations such as reqwest-tracing and axum-tracing-opentelemetry.
  5. tracing is not a 1.0 crate yet. This is not necessarily an issue, but OTel Rust and Tokio Tracing should require some co-ordination when planning future releases.

Prototype

A minimal prototype is available here: https://github.com/cijothomas/opentelemetry-tracing/tree/main/src

Please share your thoughts, concerns, and issues we may have overlooked. We recognize that re-instrumentation is a considerable effort and not something anyone looks forward to. However, this small investment now is expected to yield significant long-term benefits, setting OpenTelemetry Rust up for greater success in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions