1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 // This implementation is based on the experimental specs for resource semantic convention as
7 // https://github.com/open-telemetry/opentelemetry-specification/tree/v1.0.0/specification/resource/semantic_conventions
8 // and MAY will change in future.
12 #include <type_traits>
13 #include <unordered_map>
15 #include "opentelemetry/common/string_util.h"
16 #include "opentelemetry/version.h"
18 #define OTEL_GET_RESOURCE_ATTR(name) \
19 opentelemetry::sdk::resource::attr(OTEL_CPP_CONST_HASHCODE(name))
21 OPENTELEMETRY_BEGIN_NAMESPACE
27 static const std::unordered_map
<uint32_t, const char *> attribute_ids
= {
28 {OTEL_CPP_CONST_HASHCODE(AttrServiceName
), "service.name"},
29 {OTEL_CPP_CONST_HASHCODE(AttrServiceNamespace
), "service.namespace"},
30 {OTEL_CPP_CONST_HASHCODE(AttrServiceInstance
), "service.instance.id"},
31 {OTEL_CPP_CONST_HASHCODE(AttrServiceVersion
), "service.version"},
33 // telemetry attributes
34 {OTEL_CPP_CONST_HASHCODE(AttrTelemetrySdkName
), "telemetry.sdk.name"},
35 {OTEL_CPP_CONST_HASHCODE(AttrTelemetrySdkLanguage
), "telemetry.sdk.language"},
36 {OTEL_CPP_CONST_HASHCODE(AttrTelemetrySdkVersion
), "telemetry.sdk.version"},
37 {OTEL_CPP_CONST_HASHCODE(AttrTelemetryAutoVersion
), "telemetry.auto.version"},
39 // compute unit: container attributes
40 {OTEL_CPP_CONST_HASHCODE(AttrContainerName
), "container.name"},
41 {OTEL_CPP_CONST_HASHCODE(AttrContainerId
), "container.id"},
42 {OTEL_CPP_CONST_HASHCODE(AttrContainerRuntime
), "container.runtime"},
43 {OTEL_CPP_CONST_HASHCODE(AttrContainerImageName
), "container.image.name"},
44 {OTEL_CPP_CONST_HASHCODE(AttrContainerImageTag
), "container.image.tag"},
46 // compute unit: faas attributes
47 {OTEL_CPP_CONST_HASHCODE(AttrFaasName
), "faas.name"},
48 {OTEL_CPP_CONST_HASHCODE(AttrFaasId
), "faas.id"},
49 {OTEL_CPP_CONST_HASHCODE(AttrFaasVersion
), "faas.version"},
50 {OTEL_CPP_CONST_HASHCODE(AttrFaasInstance
), "faas.instance"},
51 {OTEL_CPP_CONST_HASHCODE(AttrFaasMaxMemory
), "faas.max_memory"},
53 // compute unit : process attributes
54 {OTEL_CPP_CONST_HASHCODE(AttrProcessId
), "process.pid"},
55 {OTEL_CPP_CONST_HASHCODE(AttrProcessExecutableName
), "process.executable.name"},
56 {OTEL_CPP_CONST_HASHCODE(AttrProcessExecutablePath
), "process.executable.path"},
57 {OTEL_CPP_CONST_HASHCODE(AttrProcessCommand
), "process.command"},
58 {OTEL_CPP_CONST_HASHCODE(AttrProcessCommandLine
), "process.command_line"},
59 {OTEL_CPP_CONST_HASHCODE(AttrProcessCommandArgs
), "process.command_args"},
60 {OTEL_CPP_CONST_HASHCODE(AttrProcessOwner
), "process.owner"},
62 // compute : process runtimes
63 {OTEL_CPP_CONST_HASHCODE(AttrProcessRuntimeName
), "process.runtime.name"},
64 {OTEL_CPP_CONST_HASHCODE(AttrProcessRuntimeVersion
), "process.runtime.version"},
65 {OTEL_CPP_CONST_HASHCODE(AttrProcessRuntimeDescription
), "process.runtime.description"},
67 // compute unit : WebEngine
68 {OTEL_CPP_CONST_HASHCODE(AttrWebEngineName
), "webengine.name"},
69 {OTEL_CPP_CONST_HASHCODE(AttrWebEngineVersion
), "webengine.version"},
70 {OTEL_CPP_CONST_HASHCODE(AttrWebEngineDescription
), "webengine.description"},
72 // compute instance : host
73 {OTEL_CPP_CONST_HASHCODE(AttrHostId
), "host.id"},
74 {OTEL_CPP_CONST_HASHCODE(AttrHostName
), "host.name"},
75 {OTEL_CPP_CONST_HASHCODE(AttrHostType
), "host.type"},
76 {OTEL_CPP_CONST_HASHCODE(AttrHostArch
), "host.arch"},
77 {OTEL_CPP_CONST_HASHCODE(AttrHostImageName
), "host.image.name"},
78 {OTEL_CPP_CONST_HASHCODE(AttrHostImageId
), "host.image.id"},
79 {OTEL_CPP_CONST_HASHCODE(AttrHostImageVersion
), "host.image.version"},
82 {OTEL_CPP_CONST_HASHCODE(AttrOsType
), "os.type"},
83 {OTEL_CPP_CONST_HASHCODE(AttrOsDescription
), "os.description"},
84 {OTEL_CPP_CONST_HASHCODE(AttrOsName
), "os.name"},
85 {OTEL_CPP_CONST_HASHCODE(AttrOsVersion
), "os.version"},
87 // env device attributes
88 {OTEL_CPP_CONST_HASHCODE(AttrDeviceId
), "device.id"},
89 {OTEL_CPP_CONST_HASHCODE(AttrDeviceModelIdentifier
), "device.model.identifier"},
90 {OTEL_CPP_CONST_HASHCODE(AttrDeviceModelName
), "device.model.name"},
93 {OTEL_CPP_CONST_HASHCODE(AttrCloudProvider
), "cloud.provider"},
94 {OTEL_CPP_CONST_HASHCODE(AttrCloudAccountId
), "cloud.account.id"},
95 {OTEL_CPP_CONST_HASHCODE(AttrCloudRegion
), "cloud.region"},
96 {OTEL_CPP_CONST_HASHCODE(AttrCloudAvailabilityZone
), "cloud.availability_zone"},
97 {OTEL_CPP_CONST_HASHCODE(AttrCloudPlatform
), "cloud.platform"},
100 {OTEL_CPP_CONST_HASHCODE(AttrDeploymentEnvironment
), "deployment.environment"},
104 {OTEL_CPP_CONST_HASHCODE(AttrK8sClusterName
), "k8s.cluster.name"},
106 {OTEL_CPP_CONST_HASHCODE(AttrK8sNodeName
), "k8s.node.name"},
107 {OTEL_CPP_CONST_HASHCODE(AttrK8sNodeUid
), "k8s.node.uid"},
109 {OTEL_CPP_CONST_HASHCODE(AttrK8sNamespaceName
), "k8s.namespace.name"},
111 {OTEL_CPP_CONST_HASHCODE(AttrK8sPodUid
), "k8s.pod.uid"},
112 {OTEL_CPP_CONST_HASHCODE(AttrK8sPodName
), "k8s.pod.name"},
114 {OTEL_CPP_CONST_HASHCODE(AttrK8sContainerName
), "k8s.container.name"},
116 {OTEL_CPP_CONST_HASHCODE(AttrK8sReplicaSetUid
), "k8s.replicaset.uid"},
117 {OTEL_CPP_CONST_HASHCODE(AttrK8sReplicaSetName
), "k8s.replicaset.name"},
119 {OTEL_CPP_CONST_HASHCODE(AttrK8sDeploymentUid
), "k8s.deployment.uid"},
120 {OTEL_CPP_CONST_HASHCODE(AttrK8sDeploymentName
), "k8s.deployment.name"},
122 {OTEL_CPP_CONST_HASHCODE(AttrK8sStatefulSetUid
), "k8s.statefulset.uid"},
123 {OTEL_CPP_CONST_HASHCODE(AttrK8sStatefulSetName
), "k8s.statefulset.name"},
125 {OTEL_CPP_CONST_HASHCODE(AttrK8sDaemonSetUid
), "k8s.daemonset.uid"},
126 {OTEL_CPP_CONST_HASHCODE(AttrK8sDaemonSetName
), "k8s.daemonset.name"},
128 {OTEL_CPP_CONST_HASHCODE(AttrK8sJobUid
), "k8s.job.uid"},
129 {OTEL_CPP_CONST_HASHCODE(AttrK8sJobName
), "k8s.job.name"},
131 {OTEL_CPP_CONST_HASHCODE(AttrCronjobUid
), "k8s.cronjob.id"},
132 {OTEL_CPP_CONST_HASHCODE(AttrCronjobName
), "k8s.cronjob.name"}};
134 // function to generate hash code for semantic conventions attributes.
135 inline const char *attr(uint32_t attr
)
137 return (attribute_ids
.find(attr
) != attribute_ids
.end()) ? attribute_ids
.at(attr
) : "";
139 } // namespace resource
141 OPENTELEMETRY_END_NAMESPACE