Use the phuslog OpenTelemetry Logs Adapter
masterThe phuslog/otel submodule provides compatibility with the OpenTelemetry Logs API while maintaining phuslog's high-performance flat JSON output format. It bridges OpenTelemetry log.Record objects to github.com/phuslu/log, preserving metadata like severity, trace context, scope, and attributes as JSON fields.
Note: This is not an OTLP exporter and does not implement the full OpenTelemetry SDK pipeline. To send logs to an OpenTelemetry Collector, write the phuslog JSON to stdout/file and use a Collector receiver, or use a separate OTLP exporter.
package main
import (
"context"
phuslog "github.com/phuslu/log"
phuslogotel "github.com/phuslu/log/otel"
otellog "go.opentelemetry.io/otel/log"
)
func main() {
var logger otellog.Logger = phuslogotel.Logger{
Log: phuslog.Logger{
Level: phuslog.InfoLevel,
},
}
var record otellog.Record
record.SetSeverity(otellog.SeverityInfo)
record.SetBody(otellog.StringValue("hello from otel"))
record.AddAttributes(otellogog.String("component", "worker"))
logger.Emit(context.Background(), record)
}