1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

Render semconv template attributes (#6939)

Resolve #6934
This commit is contained in:
Tyler Yahn
2025-06-30 00:32:44 -07:00
committed by GitHub
parent f96855b2d3
commit 1ab60d0911
3 changed files with 248 additions and 0 deletions

View File

@@ -8,6 +8,38 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased] ## [Unreleased]
### Added
- Add template attribute functions to the `go.opentelmetry.io/otel/semconv/v1.34.0` package. (#6939)
- `ContainerLabel`
- `DBOperationParameter`
- `DBSystemParameter`
- `HTTPRequestHeader`
- `HTTPResponseHeader`
- `K8SCronJobAnnotation`
- `K8SCronJobLabel`
- `K8SDaemonSetAnnotation`
- `K8SDaemonSetLabel`
- `K8SDeploymentAnnotation`
- `K8SDeploymentLabel`
- `K8SJobAnnotation`
- `K8SJobLabel`
- `K8SNamespaceAnnotation`
- `K8SNamespaceLabel`
- `K8SNodeAnnotation`
- `K8SNodeLabel`
- `K8SPodAnnotation`
- `K8SPodLabel`
- `K8SReplicaSetAnnotation`
- `K8SReplicaSetLabel`
- `K8SStatefulSetAnnotation`
- `K8SStatefulSetLabel`
- `ProcessEnvironmentVariable`
- `RPCConnectRPCRequestMetadata`
- `RPCConnectRPCResponseMetadata`
- `RPCGRPCRequestMetadata`
- `RPCGRPCResponseMetadata`
<!-- Released section --> <!-- Released section -->
<!-- Don't change this section unless doing release --> <!-- Don't change this section unless doing release -->

View File

@@ -119,6 +119,12 @@ const (
func {{to_go_name(attribute.name, pkg)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue { func {{to_go_name(attribute.name, pkg)}}(val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
return {{to_go_name(attribute.name, pkg)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val) return {{to_go_name(attribute.name, pkg)}}Key.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}(val)
} }
{%- elif attribute.type is template_type %}
{{ [to_go_name(attribute.name, pkg) ~ " returns an attribute KeyValue conforming to the \"" ~ attribute.name ~ "\" semantic conventions. " ~ it_reps(attribute.brief) ] | comment(format="go") }}
func {{to_go_name(attribute.name, pkg)}}(key string, val {{attribute.type | instantiated_type | map_text("attribute_type_value")}}) attribute.KeyValue {
return attribute.{{attribute.type | instantiated_type | map_text("attribute_type_method")}}("{{attribute.name}}."+key, val)
}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- endmacro -%} {%- endmacro -%}

View File

@@ -3467,6 +3467,13 @@ func ContainerImageTags(val ...string) attribute.KeyValue {
return ContainerImageTagsKey.StringSlice(val) return ContainerImageTagsKey.StringSlice(val)
} }
// ContainerLabel returns an attribute KeyValue conforming to the
// "container.label" semantic conventions. It represents the container labels,
// `<key>` being the label name, the value being the label value.
func ContainerLabel(key string, val string) attribute.KeyValue {
return attribute.String("container.label."+key, val)
}
// ContainerName returns an attribute KeyValue conforming to the "container.name" // ContainerName returns an attribute KeyValue conforming to the "container.name"
// semantic conventions. It represents the container name used by container // semantic conventions. It represents the container name used by container
// runtime. // runtime.
@@ -3794,6 +3801,22 @@ func DBOperationName(val string) attribute.KeyValue {
return DBOperationNameKey.String(val) return DBOperationNameKey.String(val)
} }
// DBOperationParameter returns an attribute KeyValue conforming to the
// "db.operation.parameter" semantic conventions. It represents a database
// operation parameter, with `<key>` being the parameter name, and the attribute
// value being a string representation of the parameter value.
func DBOperationParameter(key string, val string) attribute.KeyValue {
return attribute.String("db.operation.parameter."+key, val)
}
// DBQueryParameter returns an attribute KeyValue conforming to the
// "db.query.parameter" semantic conventions. It represents a database query
// parameter, with `<key>` being the parameter name, and the attribute value
// being a string representation of the parameter value.
func DBQueryParameter(key string, val string) attribute.KeyValue {
return attribute.String("db.query.parameter."+key, val)
}
// DBQuerySummary returns an attribute KeyValue conforming to the // DBQuerySummary returns an attribute KeyValue conforming to the
// "db.query.summary" semantic conventions. It represents the low cardinality // "db.query.summary" semantic conventions. It represents the low cardinality
// summary of a database query. // summary of a database query.
@@ -7312,6 +7335,14 @@ func HTTPRequestBodySize(val int) attribute.KeyValue {
return HTTPRequestBodySizeKey.Int(val) return HTTPRequestBodySizeKey.Int(val)
} }
// HTTPRequestHeader returns an attribute KeyValue conforming to the
// "http.request.header" semantic conventions. It represents the HTTP request
// headers, `<key>` being the normalized HTTP Header name (lowercase), the value
// being the header values.
func HTTPRequestHeader(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("http.request.header."+key, val)
}
// HTTPRequestMethodOriginal returns an attribute KeyValue conforming to the // HTTPRequestMethodOriginal returns an attribute KeyValue conforming to the
// "http.request.method_original" semantic conventions. It represents the // "http.request.method_original" semantic conventions. It represents the
// original HTTP method sent by the client in the request line. // original HTTP method sent by the client in the request line.
@@ -7347,6 +7378,14 @@ func HTTPResponseBodySize(val int) attribute.KeyValue {
return HTTPResponseBodySizeKey.Int(val) return HTTPResponseBodySizeKey.Int(val)
} }
// HTTPResponseHeader returns an attribute KeyValue conforming to the
// "http.response.header" semantic conventions. It represents the HTTP response
// headers, `<key>` being the normalized HTTP Header name (lowercase), the value
// being the header values.
func HTTPResponseHeader(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("http.response.header."+key, val)
}
// HTTPResponseSize returns an attribute KeyValue conforming to the // HTTPResponseSize returns an attribute KeyValue conforming to the
// "http.response.size" semantic conventions. It represents the total size of the // "http.response.size" semantic conventions. It represents the total size of the
// response in bytes. This should be the total number of bytes sent over the // response in bytes. This should be the total number of bytes sent over the
@@ -8001,6 +8040,22 @@ func K8SContainerStatusLastTerminatedReason(val string) attribute.KeyValue {
return K8SContainerStatusLastTerminatedReasonKey.String(val) return K8SContainerStatusLastTerminatedReasonKey.String(val)
} }
// K8SCronJobAnnotation returns an attribute KeyValue conforming to the
// "k8s.cronjob.annotation" semantic conventions. It represents the cronjob
// annotation placed on the CronJob, the `<key>` being the annotation name, the
// value being the annotation value.
func K8SCronJobAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.cronjob.annotation."+key, val)
}
// K8SCronJobLabel returns an attribute KeyValue conforming to the
// "k8s.cronjob.label" semantic conventions. It represents the label placed on
// the CronJob, the `<key>` being the label name, the value being the label
// value.
func K8SCronJobLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.cronjob.label."+key, val)
}
// K8SCronJobName returns an attribute KeyValue conforming to the // K8SCronJobName returns an attribute KeyValue conforming to the
// "k8s.cronjob.name" semantic conventions. It represents the name of the // "k8s.cronjob.name" semantic conventions. It represents the name of the
// CronJob. // CronJob.
@@ -8014,6 +8069,20 @@ func K8SCronJobUID(val string) attribute.KeyValue {
return K8SCronJobUIDKey.String(val) return K8SCronJobUIDKey.String(val)
} }
// K8SDaemonSetAnnotation returns an attribute KeyValue conforming to the
// "k8s.daemonset.annotation" semantic conventions. It represents the annotation
// key-value pairs placed on the DaemonSet.
func K8SDaemonSetAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.daemonset.annotation."+key, val)
}
// K8SDaemonSetLabel returns an attribute KeyValue conforming to the
// "k8s.daemonset.label" semantic conventions. It represents the label key-value
// pairs placed on the DaemonSet.
func K8SDaemonSetLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.daemonset.label."+key, val)
}
// K8SDaemonSetName returns an attribute KeyValue conforming to the // K8SDaemonSetName returns an attribute KeyValue conforming to the
// "k8s.daemonset.name" semantic conventions. It represents the name of the // "k8s.daemonset.name" semantic conventions. It represents the name of the
// DaemonSet. // DaemonSet.
@@ -8028,6 +8097,20 @@ func K8SDaemonSetUID(val string) attribute.KeyValue {
return K8SDaemonSetUIDKey.String(val) return K8SDaemonSetUIDKey.String(val)
} }
// K8SDeploymentAnnotation returns an attribute KeyValue conforming to the
// "k8s.deployment.annotation" semantic conventions. It represents the annotation
// key-value pairs placed on the Deployment.
func K8SDeploymentAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.deployment.annotation."+key, val)
}
// K8SDeploymentLabel returns an attribute KeyValue conforming to the
// "k8s.deployment.label" semantic conventions. It represents the label key-value
// pairs placed on the Deployment.
func K8SDeploymentLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.deployment.label."+key, val)
}
// K8SDeploymentName returns an attribute KeyValue conforming to the // K8SDeploymentName returns an attribute KeyValue conforming to the
// "k8s.deployment.name" semantic conventions. It represents the name of the // "k8s.deployment.name" semantic conventions. It represents the name of the
// Deployment. // Deployment.
@@ -8054,6 +8137,20 @@ func K8SHPAUID(val string) attribute.KeyValue {
return K8SHPAUIDKey.String(val) return K8SHPAUIDKey.String(val)
} }
// K8SJobAnnotation returns an attribute KeyValue conforming to the
// "k8s.job.annotation" semantic conventions. It represents the annotation
// key-value pairs placed on the Job.
func K8SJobAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.job.annotation."+key, val)
}
// K8SJobLabel returns an attribute KeyValue conforming to the "k8s.job.label"
// semantic conventions. It represents the label key-value pairs placed on the
// Job.
func K8SJobLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.job.label."+key, val)
}
// K8SJobName returns an attribute KeyValue conforming to the "k8s.job.name" // K8SJobName returns an attribute KeyValue conforming to the "k8s.job.name"
// semantic conventions. It represents the name of the Job. // semantic conventions. It represents the name of the Job.
func K8SJobName(val string) attribute.KeyValue { func K8SJobName(val string) attribute.KeyValue {
@@ -8066,6 +8163,20 @@ func K8SJobUID(val string) attribute.KeyValue {
return K8SJobUIDKey.String(val) return K8SJobUIDKey.String(val)
} }
// K8SNamespaceAnnotation returns an attribute KeyValue conforming to the
// "k8s.namespace.annotation" semantic conventions. It represents the annotation
// key-value pairs placed on the Namespace.
func K8SNamespaceAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.namespace.annotation."+key, val)
}
// K8SNamespaceLabel returns an attribute KeyValue conforming to the
// "k8s.namespace.label" semantic conventions. It represents the label key-value
// pairs placed on the Namespace.
func K8SNamespaceLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.namespace.label."+key, val)
}
// K8SNamespaceName returns an attribute KeyValue conforming to the // K8SNamespaceName returns an attribute KeyValue conforming to the
// "k8s.namespace.name" semantic conventions. It represents the name of the // "k8s.namespace.name" semantic conventions. It represents the name of the
// namespace that the pod is running in. // namespace that the pod is running in.
@@ -8073,6 +8184,22 @@ func K8SNamespaceName(val string) attribute.KeyValue {
return K8SNamespaceNameKey.String(val) return K8SNamespaceNameKey.String(val)
} }
// K8SNodeAnnotation returns an attribute KeyValue conforming to the
// "k8s.node.annotation" semantic conventions. It represents the annotation
// placed on the Node, the `<key>` being the annotation name, the value being the
// annotation value, even if the value is empty.
func K8SNodeAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.node.annotation."+key, val)
}
// K8SNodeLabel returns an attribute KeyValue conforming to the "k8s.node.label"
// semantic conventions. It represents the label placed on the Node, the `<key>`
// being the label name, the value being the label value, even if the value is
// empty.
func K8SNodeLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.node.label."+key, val)
}
// K8SNodeName returns an attribute KeyValue conforming to the "k8s.node.name" // K8SNodeName returns an attribute KeyValue conforming to the "k8s.node.name"
// semantic conventions. It represents the name of the Node. // semantic conventions. It represents the name of the Node.
func K8SNodeName(val string) attribute.KeyValue { func K8SNodeName(val string) attribute.KeyValue {
@@ -8085,6 +8212,21 @@ func K8SNodeUID(val string) attribute.KeyValue {
return K8SNodeUIDKey.String(val) return K8SNodeUIDKey.String(val)
} }
// K8SPodAnnotation returns an attribute KeyValue conforming to the
// "k8s.pod.annotation" semantic conventions. It represents the annotation placed
// on the Pod, the `<key>` being the annotation name, the value being the
// annotation value.
func K8SPodAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.pod.annotation."+key, val)
}
// K8SPodLabel returns an attribute KeyValue conforming to the "k8s.pod.label"
// semantic conventions. It represents the label placed on the Pod, the `<key>`
// being the label name, the value being the label value.
func K8SPodLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.pod.label."+key, val)
}
// K8SPodName returns an attribute KeyValue conforming to the "k8s.pod.name" // K8SPodName returns an attribute KeyValue conforming to the "k8s.pod.name"
// semantic conventions. It represents the name of the Pod. // semantic conventions. It represents the name of the Pod.
func K8SPodName(val string) attribute.KeyValue { func K8SPodName(val string) attribute.KeyValue {
@@ -8097,6 +8239,20 @@ func K8SPodUID(val string) attribute.KeyValue {
return K8SPodUIDKey.String(val) return K8SPodUIDKey.String(val)
} }
// K8SReplicaSetAnnotation returns an attribute KeyValue conforming to the
// "k8s.replicaset.annotation" semantic conventions. It represents the annotation
// key-value pairs placed on the ReplicaSet.
func K8SReplicaSetAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.replicaset.annotation."+key, val)
}
// K8SReplicaSetLabel returns an attribute KeyValue conforming to the
// "k8s.replicaset.label" semantic conventions. It represents the label key-value
// pairs placed on the ReplicaSet.
func K8SReplicaSetLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.replicaset.label."+key, val)
}
// K8SReplicaSetName returns an attribute KeyValue conforming to the // K8SReplicaSetName returns an attribute KeyValue conforming to the
// "k8s.replicaset.name" semantic conventions. It represents the name of the // "k8s.replicaset.name" semantic conventions. It represents the name of the
// ReplicaSet. // ReplicaSet.
@@ -8139,6 +8295,20 @@ func K8SResourceQuotaUID(val string) attribute.KeyValue {
return K8SResourceQuotaUIDKey.String(val) return K8SResourceQuotaUIDKey.String(val)
} }
// K8SStatefulSetAnnotation returns an attribute KeyValue conforming to the
// "k8s.statefulset.annotation" semantic conventions. It represents the
// annotation key-value pairs placed on the StatefulSet.
func K8SStatefulSetAnnotation(key string, val string) attribute.KeyValue {
return attribute.String("k8s.statefulset.annotation."+key, val)
}
// K8SStatefulSetLabel returns an attribute KeyValue conforming to the
// "k8s.statefulset.label" semantic conventions. It represents the label
// key-value pairs placed on the StatefulSet.
func K8SStatefulSetLabel(key string, val string) attribute.KeyValue {
return attribute.String("k8s.statefulset.label."+key, val)
}
// K8SStatefulSetName returns an attribute KeyValue conforming to the // K8SStatefulSetName returns an attribute KeyValue conforming to the
// "k8s.statefulset.name" semantic conventions. It represents the name of the // "k8s.statefulset.name" semantic conventions. It represents the name of the
// StatefulSet. // StatefulSet.
@@ -10497,6 +10667,14 @@ func ProcessCreationTime(val string) attribute.KeyValue {
return ProcessCreationTimeKey.String(val) return ProcessCreationTimeKey.String(val)
} }
// ProcessEnvironmentVariable returns an attribute KeyValue conforming to the
// "process.environment_variable" semantic conventions. It represents the process
// environment variables, <key> being the environment variable name, the value
// being the environment variable value.
func ProcessEnvironmentVariable(key string, val string) attribute.KeyValue {
return attribute.String("process.environment_variable."+key, val)
}
// ProcessExecutableBuildIDGNU returns an attribute KeyValue conforming to the // ProcessExecutableBuildIDGNU returns an attribute KeyValue conforming to the
// "process.executable.build_id.gnu" semantic conventions. It represents the GNU // "process.executable.build_id.gnu" semantic conventions. It represents the GNU
// build ID as found in the `.note.gnu.build-id` ELF section (hex string). // build ID as found in the `.note.gnu.build-id` ELF section (hex string).
@@ -10965,6 +11143,38 @@ const (
RPCSystemKey = attribute.Key("rpc.system") RPCSystemKey = attribute.Key("rpc.system")
) )
// RPCConnectRPCRequestMetadata returns an attribute KeyValue conforming to the
// "rpc.connect_rpc.request.metadata" semantic conventions. It represents the
// connect request metadata, `<key>` being the normalized Connect Metadata key
// (lowercase), the value being the metadata values.
func RPCConnectRPCRequestMetadata(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("rpc.connect_rpc.request.metadata."+key, val)
}
// RPCConnectRPCResponseMetadata returns an attribute KeyValue conforming to the
// "rpc.connect_rpc.response.metadata" semantic conventions. It represents the
// connect response metadata, `<key>` being the normalized Connect Metadata key
// (lowercase), the value being the metadata values.
func RPCConnectRPCResponseMetadata(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("rpc.connect_rpc.response.metadata."+key, val)
}
// RPCGRPCRequestMetadata returns an attribute KeyValue conforming to the
// "rpc.grpc.request.metadata" semantic conventions. It represents the gRPC
// request metadata, `<key>` being the normalized gRPC Metadata key (lowercase),
// the value being the metadata values.
func RPCGRPCRequestMetadata(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("rpc.grpc.request.metadata."+key, val)
}
// RPCGRPCResponseMetadata returns an attribute KeyValue conforming to the
// "rpc.grpc.response.metadata" semantic conventions. It represents the gRPC
// response metadata, `<key>` being the normalized gRPC Metadata key (lowercase),
// the value being the metadata values.
func RPCGRPCResponseMetadata(key string, val ...string) attribute.KeyValue {
return attribute.StringSlice("rpc.grpc.response.metadata."+key, val)
}
// RPCJSONRPCErrorCode returns an attribute KeyValue conforming to the // RPCJSONRPCErrorCode returns an attribute KeyValue conforming to the
// "rpc.jsonrpc.error_code" semantic conventions. It represents the `error.code` // "rpc.jsonrpc.error_code" semantic conventions. It represents the `error.code`
// property of response if it is an error response. // property of response if it is an error response.