feat(telemetry): extensible log pipeline + rotating file exporter#22
Merged
Conversation
…on path Add building blocks for composing OTel log sinks: - WithLogProcessor: register any number of sdklog.Processor (the canonical OTel pattern; replaces the single-slot WithLogExporter) - ConsoleProcessors: ready-made stdout/stderr split sink, internally wired as Exporter + BatchProcessor + SeverityFilter - NewPlainTextExporter: sdklog.Exporter formatting records as plain text (the previous hand-rolled batching Processor is replaced; async batching, queue management and shutdown draining now come from OTel's BatchProcessor) - NewSeverityFilter: severity gate Processor with min and max bounds, honouring OTel's Enabled protocol so dropped records are short-circuited before formatting - FormatPlainTextRecordLine: exposed so downstream sinks (sdkx/logfile) can emit records in the same on-screen format Deprecate WithLogConsole, WithLogMinSeverity and WithLogExporter with inline migration guides. Behaviour is preserved on v0.1.x — calling InitLog with no options still yields the default console sink — and removal is scheduled for v0.2.0. Pull go.opentelemetry.io/otel/sdk/log/logtest@v0.16.0 as a direct test dependency so log records in tests can be constructed without hitting the default attribute-length truncation. No version drift on the rest of the OTel stack. Made-with: Cursor
New sdklog.Exporter that writes plain-text log records to a local file
with size/age/backup-based rotation via natefinch/lumberjack.
Output format matches sdk/telemetry's console sink (uses
telemetry.FormatPlainTextRecordLine), so file logs read identically to
what a developer sees on stderr.
Typical wiring:
exp, _ := logfile.NewExporter(logfile.Config{
Path: "/var/log/flowcraft/server.log",
MaxSizeMB: 100,
MaxBackups: 7,
MaxAgeDays: 30,
})
telemetry.InitLog(ctx,
telemetry.WithLogProcessor(sdklog.NewBatchProcessor(exp)),
)
Lives in sdkx because lumberjack would be an unwanted transitive
dependency for sdk core consumers.
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce an extensible logging pipeline in
sdk/telemetryand add a rotating file exporter insdkx/telemetry/logfile. Together they unblock the long-standing gap of "the server cannot persist its logs to disk", which on macOS effectively meansflowcraft logsreturns nothing useful (the VM only forwards stdout/stderr that the host never sees).This PR ships the infrastructure; the wiring change in
feat/flowcraft(addingLogConfig.File*fields and pointing the server at a virtio-fs-shared file) is a follow-up.sdk/telemetry — new public API
WithLogProcessor(p sdklog.Processor) LogOptionConsoleProcessors(min) []sdklog.ProcessorNewPlainTextExporter(w io.Writer) sdklog.Exportersdklog.Exporter. The previous hand-rolled batchingProcessoris gone — async batching, queue management and shutdown draining now come from OTel'sBatchProcessor.NewSeverityFilter(base, min, max) sdklog.ProcessorEnabledprotocol so dropped records are short-circuited before formatting.FormatPlainTextRecordLine(*sdklog.Record) []bytesdk/telemetry — deprecations (v0.2.0 removal)
WithLogConsole,WithLogMinSeverity,WithLogExporterare markedDeprecated:with inline migration guides. Behaviour preserved on v0.1.x — callingInitLog()with no options still yields the default console sink.Migration:
`go// before
telemetry.InitLog(ctx)
// after
telemetry.InitLog(ctx,
telemetry.WithLogProcessor(telemetry.ConsoleProcessors(otellog.SeverityInfo)...),
)
`sdkx/telemetry/logfile — new package
go exp, _ := logfile.NewExporter(logfile.Config{ Path: "/var/log/flowcraft/server.log", MaxSizeMB: 100, MaxBackups: 7, MaxAgeDays: 30, }) telemetry.InitLog(ctx, telemetry.WithLogProcessor(sdklog.NewBatchProcessor(exp)), )Lives in sdkx because lumberjack would otherwise be an unwanted transitive dependency for
sdkcore consumers.Compatibility & rollout
go.opentelemetry.io/otel/sdk/log/logtest@v0.16.0as a direct test dep, everything else stays on v1.40 / v0.16.sdk/log v0.16.0+sdk/log/logtest v0.16.0+lumberjack.v2 v2.2.1, everything else stays on v1.40 / v0.16.auto-tagworkflow will tagsdkfirst, then open achore/bump-sdkx-sdk-vX.Y.ZPR. After that PR is merged, sdkx gets tagged with the new logfile package.Test plan
cd sdk && go test -count=1 ./...— full suite greencd sdkx && go test -count=1 ./...— full suite green (logfile package included)cd plugin && go build ./... && go vet ./...— greencd examples/voice-pipeline && go build ./... && go vet ./...— greengofmt -l ./...cleanTestInitLog_ForwardCompatible_ConsoleViaProcessorexercises the recommended migration path end-to-end.TestPlainTextExporter_Export_WrappedInBatchProcessorvalidates the Exporter+BatchProcessor composition thatConsoleProcessorsactually produces.Made with Cursor