Skip to content

Commit

Permalink
Change pdata generated types to use type definition instead of aliases
Browse files Browse the repository at this point in the history
Change the way how objects are generated in `pdata`. Previously the pdata objects were generated in the `internal` package and aliases were created in the public packageas.

This PR changes this, by creating only "wrappers" object inside the internal package, and the public type is a type def of the internal type:

```golang
package internal

type LogRecord struct {
	orig *otlplogs.LogRecord
}

func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord {
	return ms.orig
}

func NewLogRecord(orig *otlplogs.LogRecord) LogRecord {
	return LogRecord{orig: orig}
}
```

```golang
package plog

type LogRecord internal.LogRecord
```

With this approach, we still do not allow users access to the internal origin, which allows us flexibility to change to other representation (something like lazy proto, etc), but improves documentation of the pdata packages, see [current documentation](https://pkg.go.dev/go.opentelemetry.io/collector/[email protected]/plog).

Signed-off-by: Bogdan <[email protected]>
  • Loading branch information
bogdandrutu committed Aug 24, 2022
1 parent 62d41a8 commit decef68
Show file tree
Hide file tree
Showing 75 changed files with 8,673 additions and 8,564 deletions.
2 changes: 1 addition & 1 deletion exporter/loggingexporter/internal/otlptext/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) {
buf.logAttributes("Attributes", lr.Attributes())
buf.logEntry("Trace ID: %s", lr.TraceID().HexString())
buf.logEntry("Span ID: %s", lr.SpanID().HexString())
buf.logEntry("Flags: %d", lr.Flags())
buf.logEntry("Flags: %d", lr.FlagsStruct().AsRaw())
}
}
}
Expand Down
319 changes: 202 additions & 117 deletions pdata/internal/cmd/pdatagen/internal/base_fields.go

Large diffs are not rendered by default.

Loading

0 comments on commit decef68

Please sign in to comment.