| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package autodetect_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"strings" |
| 9 |
|
| 10 |
"go.opentelemetry.io/otel/attribute" |
| 11 |
"go.opentelemetry.io/otel/sdk/resource" |
| 12 |
) |
| 13 |
|
| 14 |
const key = "my.key" |
| 15 |
|
| 16 |
type MyDetector struct{} |
| 17 |
|
| 18 |
func (MyDetector) Detect(context.Context) (*resource.Resource, error) { |
| 19 |
return resource.NewSchemaless(attribute.String(key, "value")), nil |
| 20 |
} |
| 21 |
|
| 22 |
var enc = keyEncoder{} |
| 23 |
|
| 24 |
type keyEncoder struct{} |
| 25 |
|
| 26 |
func (keyEncoder) Encode(iterator attribute.Iterator) string { |
| 27 |
var b strings.Builder |
| 28 |
|
| 29 |
iterator.Next() |
| 30 |
_, _ = b.WriteString(string(iterator.Attribute().Key)) |
| 31 |
|
| 32 |
for iterator.Next() { |
| 33 |
_, _ = b.WriteRune(' ') |
| 34 |
_, _ = b.WriteString(string(iterator.Attribute().Key)) |
| 35 |
} |
| 36 |
return b.String() |
| 37 |
} |