| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otelconftelemetry |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
config "go.opentelemetry.io/contrib/otelconf/v0.3.0" |
| 10 |
sdkresource "go.opentelemetry.io/otel/sdk/resource" |
| 11 |
semconv "go.opentelemetry.io/otel/semconv/v1.37.0" |
| 12 |
) |
| 13 |
|
| 14 |
func newSDK(ctx context.Context, res *sdkresource.Resource, conf config.OpenTelemetryConfiguration) (config.SDK, error) { |
| 15 |
resourceAttrs := make([]config.AttributeNameValue, 0, res.Len()) |
| 16 |
for _, r := range res.Attributes() { |
| 17 |
key := string(r.Key) |
| 18 |
resourceAttrs = append(resourceAttrs, config.AttributeNameValue{ |
| 19 |
Name: key, |
| 20 |
Value: mustAttributeValueString(key, r.Value), |
| 21 |
}) |
| 22 |
} |
| 23 |
conf.Resource = &config.Resource{ |
| 24 |
SchemaUrl: ptr(semconv.SchemaURL), |
| 25 |
Attributes: resourceAttrs, |
| 26 |
} |
| 27 |
return config.NewSDK(config.WithContext(ctx), config.WithOpenTelemetryConfiguration(conf)) |
| 28 |
} |