Skip to content

Add a tracing-subscriber Layer integration #205

Description

@marandaneto

Summary

Provide an optional tracing_subscriber::Layer integration that converts selected Rust tracing events into PostHog events.

Motivation

This was requested in #29 for applications and local-first tools that already instrument their code with tracing. Today the SDK uses tracing internally, but applications must write their own visitor and subscriber integration to capture tracing events in PostHog.

Example desired usage:

tracing::trace!(src = "posthog", field1 = "one", field2 = "two");

Proposed scope

The integration may be an optional crate feature or a separate integration crate to keep core dependencies low. It should:

  • Implement a tracing_subscriber::Layer and field visitor.
  • Allow callers to select which events are captured and derive the PostHog event name.
  • Map tracing fields into event properties.
  • Provide a way to supply identity and shared context.
  • Delegate batching and delivery to the existing PostHog client.
  • Exclude the SDK's own tracing targets by default to prevent recursive capture.

Span lifecycle/trace export is not required for the first version unless separately designed; the initial scope can be tracing events/logs only.

Acceptance criteria

  • The integration can capture a selected tracing event as a PostHog event with its fields preserved.
  • Filtering and event-name mapping are configurable.
  • SDK-internal logs cannot recursively generate PostHog events.
  • Sync and async PostHog client usage is documented where applicable.
  • Flush/shutdown behavior for CLIs and short-lived processes is documented.
  • Tests cover field conversion, filtering, identity/context, and recursion prevention.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions