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 beea276
Show file tree
Hide file tree
Showing 76 changed files with 7,413 additions and 7,298 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
- Remove unnecessary duplicate code and allocations for reading enums in JSON. (#5928)
- Add "dist.build_tags" configuration option to support passing go build flags to builder. (#5659)
- Add an AsRaw func on the flags, lots of places to encode these flags. (#5934)
- Change pdata generated types to use type definition instead of aliases. (#5936)
- Improves documentation, and makes code easier to read/understand.

### 🧰 Bug fixes 🧰

Expand Down
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 beea276

Please sign in to comment.