diff --git a/telemetry.go b/telemetry.go index 220c60e2..f8a43c2d 100644 --- a/telemetry.go +++ b/telemetry.go @@ -78,11 +78,7 @@ func InitTelemetry(ctx context.Context, cfg TelemetryConfig) (func(context.Conte } // Set up resource. - res, err := resource.Merge(resource.Default(), - resource.NewWithAttributes(semconv.SchemaURL, - semconv.ServiceName(cfg.ServiceName), - semconv.ServiceVersion(Version), - )) + res, err := resources(cfg) if err != nil { return nil, handleErr(err) } @@ -227,3 +223,11 @@ func newMeterProvider(exp sdkmetric.Exporter, res *resource.Resource) (*sdkmetri return meterProvider, nil } + +func resources(cfg TelemetryConfig) (*resource.Resource, error) { + return resource.Merge(resource.Default(), + resource.NewWithAttributes(semconv.SchemaURL, + semconv.ServiceName(cfg.ServiceName), + semconv.ServiceVersion(Version), + )) +} diff --git a/telemetry_test.go b/telemetry_test.go new file mode 100644 index 00000000..90129a6c --- /dev/null +++ b/telemetry_test.go @@ -0,0 +1,13 @@ +package bramble + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestResources(t *testing.T) { + cfg := TelemetryConfig{Enabled: true} + _, err := resources(cfg) + require.NoError(t, err) +}