Skip to content

Conversation

@abelonogov-ld
Copy link
Contributor

@abelonogov-ld abelonogov-ld commented Nov 5, 2025

Move Traces to LD buffering

Proof of testing:
image


Note

Route trace exporting through the LD event queue with a new OTLP trace event exporter and processor, removing legacy sampling/stdout exporters.

  • Traces:
    • Switch span exporting to LD event-queue pipeline: add EventSpanProcessor, OtlpTraceEventExporter, and SpanItem.
    • Update TracerDecorator to use sampler + EventQueue (removes BatchSpanProcessor/direct SpanExporter usage) and provide start-with-time helper via Tracer extension.
    • Register trace event exporter in ObservabilityClientFactory via BatchWorker.
    • Remove legacy exporters: SamplingTraceExporter.swift, SamplingLogExporter.swift, LDStdoutExporter.swift.
  • Metrics:
    • Make OtlpMetricEventExporter and OtlpMetricScheduleExporter internal and encapsulate properties (no functional change).
  • TestApp:
    • Enable .urlSession in autoInstrumentation config.

Written by Cursor Bugbot for commit 14ec46a. This will update automatically on new commits. Configure here.

It puts failed items in the failedItems and try them until network is restored
…factor

* andrey/offline-stability:
  switch stg
  fix probable crash
  BatchWorker without MultiExporter

# Conflicts:
#	Sources/Observability/Transport/BatchWorker.swift
#	Sources/Observability/Transport/EventQueue.swift
* main:
  chore(main): release 0.9.0 (#68)
  fix: Make Session Replay stable for offline or intermittent network (#67)
  feat: cold, warm and hot launch times meter (#66)

# Conflicts:
#	Sources/Observability/Logs/LogItem.swift
#	Sources/Observability/Transport/BatchWorker.swift
#	Sources/Observability/Transport/EventQueue.swift
let decorator = TracerDecorator(options: options, sessionManager: sessionManager, exporter: tracesExporter)
Task {
await batchWorker.addExporter(traceEventExporter)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Asynchronous Exporter Registration Causes Lost Traces Metrics Logs

Race condition: The trace exporter is added to batchWorker in a fire-and-forget Task, but execution continues immediately without waiting. This means traces could be generated and sent to the eventQueue before the exporter is registered with batchWorker, causing those traces to be lost or not exported properly. The same issue exists for metrics (lines 123-125) and logs (lines 54-56). The Task should be awaited or the exporter should be added synchronously before the TracerDecorator is created and used.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All good. It will be just in buffer for this time.

* main:
  chore: refactor metrics to event exporter (#69)

# Conflicts:
#	Sources/Observability/Metrics/OtlpMetricEventExporter.swift
#	Sources/Observability/Metrics/OtlpMetricScheduleExporter.swift
#	TestApp/Sources/AppDelegate.swift
extension TracerDecorator {
func startSpan(name: String, attributes: [String : AttributeValue], startTime: Date = Date()) -> any Span {
let builder = tracer.spanBuilder(spanName: name)
extension Tracer {
Copy link

Choose a reason for hiding this comment

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

Bug: Flush() Fails to Export Pending Spans

The flush() method now returns true without actually flushing any data. The previous implementation called spanProcessor.forceFlush(timeout: 5.0) to ensure spans were exported. With the new event queue architecture, the flush() method should trigger flushing of the eventQueue or batchWorker to ensure pending spans are exported, but it currently does nothing. This could lead to data loss if callers rely on flush() to ensure spans are exported before shutdown or other critical operations.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just server requirement from protocol and doesn't needed for mobile

Observability.OtlpTraceEventExporter.self
}

let spanData: SpanData
Copy link
Contributor

Choose a reason for hiding this comment

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

private ? understanding that all coming from EventQueueItemPayload could be internal, but why spanData is internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need read spanData in exporter. SpanData is what Protobuf exporter uses

@abelonogov-ld abelonogov-ld merged commit cfa92fb into main Nov 5, 2025
4 checks passed
@abelonogov-ld abelonogov-ld deleted the andrey/otlp-trace-exporters-refactor branch November 5, 2025 18:01
abelonogov-ld pushed a commit that referenced this pull request Nov 5, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.9.1](0.9.0...0.9.1)
(2025-11-05)


### Bug Fixes

* Otlp Trace Exporters to Event Exporter
([#70](#70))
([cfa92fb](cfa92fb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Bumps version to 0.9.1 and updates CHANGELOG with a bug fix for OTLP
Trace Exporters to Event Exporter.
> 
> - **Release 0.9.1**:
> - Update `Sources/LaunchDarklyObservability/Version.swift`
`sdkVersion` to `0.9.1`.
>   - Update `.release-please-manifest.json` to `0.9.1`.
> - Add `CHANGELOG.md` entry noting bug fix: OTLP Trace Exporters to
Event Exporter.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d383ddb. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
abelonogov-ld added a commit that referenced this pull request Nov 5, 2025
* main:
  chore(main): release 0.9.1 (#71)
  fix: Otlp Trace Exporters to Event Exporter (#70)
  chore: refactor metrics to event exporter (#69)

# Conflicts:
#	Sources/Observability/Metrics/OtlpMetricEventExporter.swift
#	Sources/Observability/Metrics/OtlpMetricScheduleExporter.swift
#	Sources/Observability/Traces/EventSpanProcessor.swift
#	Sources/Observability/Traces/OtlpTraceEventExporter.swift
#	Sources/Observability/Traces/SpanItem.swift
#	TestApp/Sources/AppDelegate.swift
abelonogov-ld added a commit that referenced this pull request Nov 6, 2025
* main:
  chore(main): release 0.9.2 (#73)
  fix: user snap tap (#72)
  chore(main): release 0.9.1 (#71)
  fix: Otlp Trace Exporters to Event Exporter (#70)
  chore: refactor metrics to event exporter (#69)

# Conflicts:
#	Sources/Observability/Client/ObservabilityClientFactory.swift
#	Sources/Observability/Metrics/OtlpMetricEventExporter.swift
#	Sources/Observability/Metrics/OtlpMetricScheduleExporter.swift
#	Sources/Observability/Traces/EventSpanProcessor.swift
#	Sources/Observability/Traces/OtlpTraceEventExporter.swift
#	Sources/Observability/Traces/SpanItem.swift
#	Sources/Observability/Traces/TracerDecorator.swift
#	Sources/Observability/UIInteractions/UInteraction+Span.swift
#	TestApp/Sources/AppDelegate.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants