feat(logs): add public captureLog API and logger facade#592
feat(logs): add public captureLog API and logger facade#592turnipdabeets wants to merge 1 commit intofeat/logs-storage-queuefrom
Conversation
posthog-ios Compliance ReportDate: 2026-05-07 15:12:25 UTC
|
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 104ms |
| Request Payload.Flags Request Uses V2 Query Param | ❌ | 93ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ❌ | 123ms |
| Request Payload.Flags Request Omits Authorization Header | ❌ | 110ms |
| Request Payload.Token In Flags Body Matches Init | ❌ | 111ms |
| Request Payload.Groups Round Trip | ❌ | 187ms |
| Request Payload.Groups Default To Empty Object | ❌ | 71ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ❌ | 186ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ❌ | 130ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 146ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ❌ | 150ms |
| Request Lifecycle.No Flags Request On Init Alone | ❌ | 88ms |
| Request Lifecycle.No Flags Request On Normal Capture | ❌ | 2373ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ❌ | 72ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 146ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 71ms |
Failures
request_payload.request_with_person_properties_device_id
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.flags_request_uses_v2_query_param
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.flags_request_hits_flags_path_not_decide
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.flags_request_omits_authorization_header
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.token_in_flags_body_matches_init
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.groups_round_trip
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.groups_default_to_empty_object
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.disable_geoip_false_propagates_as_geoip_disable_false
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.disable_geoip_omitted_defaults_to_false
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_payload.flag_keys_to_evaluate_contains_only_requested_key
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_lifecycle.no_flags_request_on_init_alone
Expected 0 /flags requests, got 1
request_lifecycle.no_flags_request_on_normal_capture
Expected 0 /flags requests, got 1
request_lifecycle.two_flag_calls_produce_two_remote_requests
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
request_lifecycle.mock_response_value_is_returned_to_caller
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
side_effect_events.get_feature_flag_captures_feature_flag_called_event
404, message='Not Found', url='http://host.docker.internal:8080/get_feature_flag'
f46ed04 to
c1eb83a
Compare
|
|
||
| // Cache the latest screen name so `captureLog` can tag log records | ||
| // without needing main-thread access to UIViewController helpers. | ||
| screenViewToken = DI.main.screenViewPublisher.onScreenView.subscribe { [weak self] name in |
There was a problem hiding this comment.
Feels like this should be responsibility of PostHogLogger instead?. PostHogSDK can read from logger instance logger.lastScreenName
| /// - traceId: 32-character lowercase hex W3C trace id. | ||
| /// - spanId: 16-character lowercase hex W3C span id. | ||
| /// - traceFlags: W3C trace flags bitfield (bit 0 is the `sampled` flag). |
There was a problem hiding this comment.
Should we validate these at capture time you think? Probably a question for @PostHog/logs team
| let sId = sessionManager.getSessionId(readOnly: true) | ||
| let scr = currentScreenName | ||
| let appState = sessionManager.isAppInBackgroundSnapshot ? PostHogLogRecord.AppState.background : PostHogLogRecord.AppState.foreground | ||
| let flagKeys = remoteConfig?.getFeatureFlags()?.keys.map { String($0) } ?? [] |
There was a problem hiding this comment.
Should these be only active flags? For normal events in dynamicContext() we include only active flags I think. Also on the first PR, the comment for this field calls out for active flags only
cd30009 to
d7bc6bd
Compare
86c0645 to
0217342
Compare
User-facing surface on top of the storage + queue infrastructure:
- PostHogSDK.captureLog(_:level:attributes:traceId:spanId:traceFlags:)
with @objc overloads and a Swift default-arg variant
- PostHogSDK.logger — lazy facade with trace / debug / info / warn /
error / fatal
The existing PostHogSDK.flush() now drains all three queues (events,
replay, logs) — no separate flushLogs() needed.
beforeSend runs at the SDK layer (before logsQueue.add) so sensitive
data is scrubbed before it can enter any internal pipeline. Rate cap
stays at the queue layer.
Capture-time context (distinctId, sessionId, screenName, appState,
featureFlagKeys) is snapshotted on the calling thread; identity or
session changes between capture and flush cannot mutate a queued
record. Screen name is cached on PostHogSDK via the existing
screen-view publisher so log records can be tagged without needing
main-thread access to UIViewController helpers.
Also adds:
- PostHogTests/PostHogLogsCaptureTest.swift — integration tests
covering main / background / concurrent capture, empty-body and
opt-out drops, distinctId snapshotting, all six severity numbers
on the wire, OTLP resource attributes, and backgrounding triggers
flush.
- PostHogExample/Views/LogsView.swift — demo each level, flush,
traced-log, and a 1000-record flood.
- .changeset/logs-feature.md — combined-feature entry.
fix test
no uppercase required
consts
0217342 to
5989997
Compare
💡 Motivation and Context
Public API for the logs feature on top of #590 (storage + queue). Stacked on
feat/logs-storage-queue, notmain.Adds
PostHogSDK.captureLog(_:level:attributes:traceId:spanId:traceFlags:)(@objcoverloads + Swift default-arg variant) andPostHogSDK.logger, a lazy facade withtrace / debug / info / warn / error / fatal.PostHogSDK.flush()now drains all three queues — no separateflushLogs(), matching the existing replay convention.beforeSendruns at the SDK layer beforelogsQueue.addso sensitive data is scrubbed before entering any internal pipeline; rate cap stays at the queue layer. Capture-time context (distinctId,sessionId,screenName,appState,featureFlagKeys) is snapshotted on the calling thread so identity / session changes between capture and flush can't mutate a queued record. Screen name is cached onPostHogSDKvia the existingscreenViewPublishersubscription.💚 How did you test it?
make test— 503 tests in 105 suites pass.PostHogTests/PostHogLogsCaptureTest.swiftcovers main / background / concurrent capture, empty-body drop, opt-out drop, capture-timedistinctIdsnapshotting (identify A → captureLog → identify B → flush → record carries A),logger.info≡captureLog level: .info, all six severity numbers on the wire, OTLP resource attributes, flush from background thread, and backgrounding triggers a logs flush.PostHogExample/Views/LogsView.swift— demo each level, flush, traced-log, and a 1000-record flood (rate-cap demo).📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file (covers the combined feature).