A Pulse integration that automatically forwards log entries to Sentry's structured logging system, capturing application logs with full context including metadata, source location, and log levels.
Note
This repo is a mirror of github.com/getsentry/sentry-cocoa. The source code lives in 3rd-party-integrations/SentryPulse/. This allows users to import only what they need via SPM while keeping all integration code in the main repository.
Add the following dependencies to your Package.swift or Xcode package manager:
dependencies: [
.package(url: "https://github.com/getsentry/sentry-apple-pulse", from: "9.0.0")
]import Sentry
import Pulse
import SentryPulse
SentrySDK.start { options in
options.dsn = "YOUR_DSN"
}
SentryPulse.start()
let logger = LoggerStore.shared.makeLogger(label: "com.example.app")
logger.info("User logged in", metadata: ["userId": "12345"])
logger.error("Payment failed", metadata: ["errorCode": 500])By default, SentryPulse.start() uses LoggerStore.shared. You can specify a custom LoggerStore:
let customStore = try LoggerStore(storeURL: customURL, options: [.inMemory])
SentryPulse.start(loggerStore: customStore)The integration automatically observes Pulse's LoggerStore.events publisher and forwards all .messageStored events to Sentry. You can stop the integration if needed:
SentryPulse.stop()
SentryPulse.start()Calling start() multiple times has no effect - the integration is started only once.
Pulse log levels are automatically mapped to Sentry log levels:
| Pulse Level | Sentry Log Level |
|---|---|
.trace |
.trace |
.debug |
.debug |
.info |
.info |
.notice |
.info |
.warning |
.warn |
.error |
.error |
.critical |
.fatal |
All Pulse metadata is automatically forwarded to Sentry with the pulse. prefix:
logger.info("User action", metadata: [
"userId": "12345",
"action": "purchase"
])The metadata will appear in Sentry as pulse.userId and pulse.action.
Pulse metadata is already converted to [String: String] format before being forwarded, ensuring compatibility with Sentry's attribute system.
The integration automatically includes the following attributes with every log entry:
sentry.origin:"auto.logging.pulse"pulse.level: The original Pulse level namepulse.label: The logger labelcode.file.path: The source file name (if available)code.function.name: The function name (if available)code.line.number: The line number
All Pulse metadata is prefixed with pulse. in Sentry attributes (e.g., pulse.userId, pulse.action).
This integration follows the same license as the Sentry Cocoa SDK. See the LICENSE file for details.