Files
telemetry/component/identifiable_example_test.go
19a7f7092c docs: add testable examples for component.ID and component.Type Closes Issue #13146 (#13430)
#### Description

Adds testable examples for `component.ID` and `component.Type` to
improve the documentation rendered on
[pkg.go.dev](https://pkg.go.dev/go.opentelemetry.io/collector/component).
These examples demonstrate how to construct and use these types in a
simple and idiomatic way, per the Go documentation guidelines.

#### Link to tracking issue
Fixes #13146

#### Testing
Testable examples were added in `component/identifiable_example_test.go`
and verified using:

```
cd component/
go test ./... -v
```

---------

Co-authored-by: Damien Mathieu <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
2025-07-28 16:38:30 +00:00

65 lines
1.1 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package component_test
import (
"fmt"
"go.opentelemetry.io/collector/component"
)
func ExampleNewType() {
t, err := component.NewType("exampleexporter")
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(t.String())
// Output:
// exampleexporter
}
func ExampleMustNewType() {
t := component.MustNewType("examplereceiver")
fmt.Println(t.String())
// Output:
// examplereceiver
}
func ExampleNewID() {
t := component.MustNewType("exampleprocessor")
id := component.NewID(t)
fmt.Println(id.String())
// Output:
// exampleprocessor
}
func ExampleMustNewID() {
id := component.MustNewID("examplereceiver")
fmt.Println(id.String())
// Output:
// examplereceiver
}
func ExampleNewIDWithName() {
t := component.MustNewType("exampleexporter")
id := component.NewIDWithName(t, "customname")
fmt.Println(id.String())
// Output:
// exampleexporter/customname
}
func ExampleMustNewIDWithName() {
id := component.MustNewIDWithName("exampleprocessor", "customproc")
fmt.Println(id.String())
// Output:
// exampleprocessor/customproc
}