feat(logger,tracing): share OTel resource for logs and traces
Factor the resource detector list into internal/otlpresource so the logger's OTLP provider and the trace provider describe the same process with the same attributes. OTLP log records now carry the full resource (process.pid, service.name, service.version, host.*, os.*, etc.) instead of no resource attributes at all.
This commit is contained in:
@@ -36,6 +36,8 @@ import (
|
||||
|
||||
slogtraceid "github.com/remychantenay/slog-otel"
|
||||
slogmulti "github.com/samber/slog-multi"
|
||||
"go.ntppool.org/common/internal/otlpresource"
|
||||
"go.ntppool.org/common/version"
|
||||
"go.opentelemetry.io/contrib/bridges/otelslog"
|
||||
"go.opentelemetry.io/otel/log/global"
|
||||
otellog "go.opentelemetry.io/otel/sdk/log"
|
||||
@@ -167,9 +169,18 @@ func setupOtlpLogger() *slog.Logger {
|
||||
otellog.WithExportMaxBatchSize(512),
|
||||
)
|
||||
|
||||
// Build the shared OTel resource (process.pid, host.*, service.name
|
||||
// from OTEL_SERVICE_NAME, service.version, etc.). Environment is only
|
||||
// known to the tracing package and is intentionally omitted here; see
|
||||
// common/internal/otlpresource.
|
||||
res, _ := otlpresource.New(context.Background(), Setup(), otlpresource.Options{
|
||||
ServiceVersion: version.Version(),
|
||||
})
|
||||
|
||||
// Create logger provider
|
||||
provider := otellog.NewLoggerProvider(
|
||||
otellog.WithProcessor(processor),
|
||||
otellog.WithResource(res),
|
||||
)
|
||||
|
||||
// Set global provider
|
||||
|
||||
Reference in New Issue
Block a user