You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Use semconv creation functions (#3683)
This commit is contained in:
		| @@ -60,9 +60,9 @@ var ( | ||||
| func (telemetrySDK) Detect(context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes( | ||||
| 		semconv.SchemaURL, | ||||
| 		semconv.TelemetrySDKNameKey.String("opentelemetry"), | ||||
| 		semconv.TelemetrySDKLanguageKey.String("go"), | ||||
| 		semconv.TelemetrySDKVersionKey.String(otel.Version()), | ||||
| 		semconv.TelemetrySDKName("opentelemetry"), | ||||
| 		semconv.TelemetrySDKLanguageGo, | ||||
| 		semconv.TelemetrySDKVersion(otel.Version()), | ||||
| 	), nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -47,7 +47,7 @@ func (cgroupContainerIDDetector) Detect(ctx context.Context) (*Resource, error) | ||||
| 	if containerID == "" { | ||||
| 		return Empty(), nil | ||||
| 	} | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ContainerIDKey.String(containerID)), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ContainerID(containerID)), nil | ||||
| } | ||||
|  | ||||
| var ( | ||||
|   | ||||
| @@ -59,7 +59,7 @@ func (fromEnv) Detect(context.Context) (*Resource, error) { | ||||
| 	var res *Resource | ||||
|  | ||||
| 	if svcName != "" { | ||||
| 		res = NewSchemaless(semconv.ServiceNameKey.String(svcName)) | ||||
| 		res = NewSchemaless(semconv.ServiceName(svcName)) | ||||
| 	} | ||||
|  | ||||
| 	r2, err := constructOTResources(attrs) | ||||
|   | ||||
| @@ -83,7 +83,7 @@ func TestNoResourceAttributesSet(t *testing.T) { | ||||
| 	res, err := detector.Detect(context.Background()) | ||||
| 	require.NoError(t, err) | ||||
| 	assert.Equal(t, res, NewSchemaless( | ||||
| 		semconv.ServiceNameKey.String("bar"), | ||||
| 		semconv.ServiceName("bar"), | ||||
| 	)) | ||||
| } | ||||
|  | ||||
| @@ -131,6 +131,6 @@ func TestDetectServiceNameFromEnv(t *testing.T) { | ||||
| 	require.NoError(t, err) | ||||
| 	assert.Equal(t, res, NewSchemaless( | ||||
| 		attribute.String("key", "value"), | ||||
| 		semconv.ServiceNameKey.String("bar"), | ||||
| 		semconv.ServiceName("bar"), | ||||
| 	)) | ||||
| } | ||||
|   | ||||
| @@ -63,7 +63,7 @@ func (osDescriptionDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
|  | ||||
| 	return NewWithAttributes( | ||||
| 		semconv.SchemaURL, | ||||
| 		semconv.OSDescriptionKey.String(description), | ||||
| 		semconv.OSDescription(description), | ||||
| 	), nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -120,14 +120,14 @@ type processRuntimeDescriptionDetector struct{} | ||||
| // Detect returns a *Resource that describes the process identifier (PID) of the | ||||
| // executing process. | ||||
| func (processPIDDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessPIDKey.Int(pid())), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessPID(pid())), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the name of the process executable. | ||||
| func (processExecutableNameDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 	executableName := filepath.Base(commandArgs()[0]) | ||||
|  | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutableNameKey.String(executableName)), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutableName(executableName)), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the full path of the process executable. | ||||
| @@ -137,13 +137,13 @@ func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, err | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutablePathKey.String(executablePath)), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutablePath(executablePath)), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes all the command arguments as received | ||||
| // by the process. | ||||
| func (processCommandArgsDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessCommandArgsKey.StringSlice(commandArgs())), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessCommandArgs(commandArgs()...)), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the username of the user that owns the | ||||
| @@ -154,18 +154,18 @@ func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessOwnerKey.String(owner.Username)), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessOwner(owner.Username)), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the name of the compiler used to compile | ||||
| // this process image. | ||||
| func (processRuntimeNameDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeNameKey.String(runtimeName())), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeName(runtimeName())), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the version of the runtime of this process. | ||||
| func (processRuntimeVersionDetector) Detect(ctx context.Context) (*Resource, error) { | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeVersionKey.String(runtimeVersion())), nil | ||||
| 	return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeVersion(runtimeVersion())), nil | ||||
| } | ||||
|  | ||||
| // Detect returns a *Resource that describes the runtime of this process. | ||||
| @@ -175,6 +175,6 @@ func (processRuntimeDescriptionDetector) Detect(ctx context.Context) (*Resource, | ||||
|  | ||||
| 	return NewWithAttributes( | ||||
| 		semconv.SchemaURL, | ||||
| 		semconv.ProcessRuntimeDescriptionKey.String(runtimeDescription), | ||||
| 		semconv.ProcessRuntimeDescription(runtimeDescription), | ||||
| 	), nil | ||||
| } | ||||
|   | ||||
| @@ -227,8 +227,8 @@ func TestDefault(t *testing.T) { | ||||
| 		"default service.name should include executable name") | ||||
|  | ||||
| 	require.Contains(t, res.Attributes(), semconv.TelemetrySDKLanguageGo) | ||||
| 	require.Contains(t, res.Attributes(), semconv.TelemetrySDKVersionKey.String(otel.Version())) | ||||
| 	require.Contains(t, res.Attributes(), semconv.TelemetrySDKNameKey.String("opentelemetry")) | ||||
| 	require.Contains(t, res.Attributes(), semconv.TelemetrySDKVersion(otel.Version())) | ||||
| 	require.Contains(t, res.Attributes(), semconv.TelemetrySDKName("opentelemetry")) | ||||
| } | ||||
|  | ||||
| func TestString(t *testing.T) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user