custom-transport-attribute

command
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 4 Imported by: 0

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL