// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package resource // import "go.opentelemetry.io/otel/sdk/resource"

import (
	
	
	
	

	

	
	
	semconv 
)

type (
	// telemetrySDK is a Detector that provides information about
	// the OpenTelemetry SDK used.  This Detector is included as a
	// builtin. If these resource attributes are not wanted, use
	// resource.New() to explicitly disable them.
	telemetrySDK struct{}

	// host is a Detector that provides information about the host
	// being run on. This Detector is included as a builtin. If
	// these resource attributes are not wanted, use the
	// resource.New() to explicitly disable them.
	host struct{}

	stringDetector struct {
		schemaURL string
		K         attribute.Key
		F         func() (string, error)
	}

	defaultServiceNameDetector struct{}

	defaultServiceInstanceIDDetector struct{}
)

var (
	_ Detector = telemetrySDK{}
	_ Detector = host{}
	_ Detector = stringDetector{}
	_ Detector = defaultServiceNameDetector{}
	_ Detector = defaultServiceInstanceIDDetector{}
)

// Detect returns a *Resource that describes the OpenTelemetry SDK used.
func (telemetrySDK) (context.Context) (*Resource, error) {
	return NewWithAttributes(
		semconv.SchemaURL,
		semconv.TelemetrySDKName("opentelemetry"),
		semconv.TelemetrySDKLanguageGo,
		semconv.TelemetrySDKVersion(sdk.Version()),
	), nil
}

// Detect returns a *Resource that describes the host being run on.
func (host) ( context.Context) (*Resource, error) {
	return StringDetector(semconv.SchemaURL, semconv.HostNameKey, os.Hostname).Detect()
}

// StringDetector returns a Detector that will produce a *Resource
// containing the string as a value corresponding to k. The resulting Resource
// will have the specified schemaURL.
func ( string,  attribute.Key,  func() (string, error)) Detector {
	return stringDetector{schemaURL: , K: , F: }
}

// Detect returns a *Resource that describes the string as a value
// corresponding to attribute.Key as well as the specific schemaURL.
func ( stringDetector) (context.Context) (*Resource, error) {
	,  := .F()
	if  != nil {
		return nil, fmt.Errorf("%s: %w", string(.K), )
	}
	 := .K.String()
	if !.Valid() {
		return nil, fmt.Errorf("invalid attribute: %q -> %q", .Key, .Value.Emit())
	}
	return NewWithAttributes(.schemaURL, .K.String()), nil
}

// Detect implements Detector.
func (defaultServiceNameDetector) ( context.Context) (*Resource, error) {
	return StringDetector(
		semconv.SchemaURL,
		semconv.ServiceNameKey,
		func() (string, error) {
			,  := os.Executable()
			if  != nil {
				return "unknown_service:go", nil
			}
			return "unknown_service:" + filepath.Base(), nil
		},
	).Detect()
}

// Detect implements Detector.
func (defaultServiceInstanceIDDetector) ( context.Context) (*Resource, error) {
	return StringDetector(
		semconv.SchemaURL,
		semconv.ServiceInstanceIDKey,
		func() (string, error) {
			,  := uuid.NewRandom()
			if  != nil {
				return "", 
			}

			return .String(), nil
		},
	).Detect()
}