Documentation
¶
Overview ¶
Implementing a custom Transport (attribute-forwarding / wrapper policy).
This example demonstrates the policy used by the zerolog / zap / slog / logrus / charmlog / phuslu / OpenTelemetry wrappers: forward each piece of structured data to a backend's native attribute API. Map metadata flattens at the root; non-map metadata nests under a single MetadataFieldName key so the backend's own marshaler renders it.
Use transport.MetadataAsRootMap (no allocation, no JSON roundtrip) to branch on whether the metadata is map-shaped before forwarding.
Reach for this pattern when your backend has an attribute API like zerolog's Event.Interface, zap's zap.Any, or OTel's KeyValue.
Run:
go run ./examples/custom-transport-attribute
Click to show internal directories.
Click to hide internal directories.