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
#5936)

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/pdata@v0.58.0/plog).

Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Aug 24, 2022
1 parent 18700db commit 58fa059
Show file tree
Hide file tree
Showing 75 changed files with 7,412 additions and 7,297 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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
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 58fa059

Please sign in to comment.