|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include "opentelemetry/common/string_util.h" |
| 7 | +#include "opentelemetry/version.h" |
| 8 | + |
| 9 | +OPENTELEMETRY_BEGIN_NAMESPACE |
| 10 | +namespace trace |
| 11 | +{ |
| 12 | + |
| 13 | +#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name)) |
| 14 | + |
| 15 | +/** |
| 16 | + * Stores the Constants for semantic kAttribute names outlined by the OpenTelemetry specifications. |
| 17 | + * <see |
| 18 | + * href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/README.md"/>. |
| 19 | + */ |
| 20 | +static const struct |
| 21 | +{ |
| 22 | + uint32_t attribute_id; |
| 23 | + const char *attribute_key; |
| 24 | +} attribute_ids[] = { |
| 25 | + // The set of constants matches the specification as of this commit. |
| 26 | + // https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions |
| 27 | + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md |
| 28 | + |
| 29 | + // General network connection attributes |
| 30 | + {OTEL_CPP_CONST_HASHCODE(AttrNetTransport), "net.transport"}, |
| 31 | + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerIp), "net.peer.ip"}, |
| 32 | + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerPort), "net.peer.port"}, |
| 33 | + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerName), "net.peer.name"}, |
| 34 | + {OTEL_CPP_CONST_HASHCODE(AttrNetHostIp), "net.host.ip"}, |
| 35 | + {OTEL_CPP_CONST_HASHCODE(AttrNetHostPort), "net.host.port"}, |
| 36 | + {OTEL_CPP_CONST_HASHCODE(AttrNetHostName), "net.host.name"}, |
| 37 | + |
| 38 | + // General identity attributes |
| 39 | + {OTEL_CPP_CONST_HASHCODE(AttrEnduserId), "enduser.id"}, |
| 40 | + {OTEL_CPP_CONST_HASHCODE(AttrEnduserRole), "enduser.role"}, |
| 41 | + {OTEL_CPP_CONST_HASHCODE(AttrEnduserScope), "enduser.scope"}, |
| 42 | + |
| 43 | + // General remote service attributes |
| 44 | + {OTEL_CPP_CONST_HASHCODE(AttrPeerService), "peer.service"}, |
| 45 | + |
| 46 | + // General thread attributes |
| 47 | + {OTEL_CPP_CONST_HASHCODE(AttrThreadId), "thread.id"}, |
| 48 | + {OTEL_CPP_CONST_HASHCODE(AttrThreadName), "thread.name"}, |
| 49 | + |
| 50 | + // Source Code Attributes |
| 51 | + {OTEL_CPP_CONST_HASHCODE(AttrCodeFunction), "code.function"}, |
| 52 | + {OTEL_CPP_CONST_HASHCODE(AttrCodeNamespace), "code.namespace"}, |
| 53 | + {OTEL_CPP_CONST_HASHCODE(AttrCodeFilepath), "code.filepath"}, |
| 54 | + {OTEL_CPP_CONST_HASHCODE(AttrCodeLineno), "code.lineno"}, |
| 55 | + |
| 56 | + // Http Span Common Attributes |
| 57 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpMethod), "http.method"}, |
| 58 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpUrl), "http.url"}, |
| 59 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpTarget), "http.target"}, |
| 60 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpHost), "http.host"}, |
| 61 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpScheme), "http.scheme"}, |
| 62 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpStatusCode), "http.status_code"}, |
| 63 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpFlavor), "http.flavor"}, |
| 64 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpUserAgent), "http.user_agent"}, |
| 65 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpRequestContentLength), "http.request_content_length"}, |
| 66 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpRequestContentLengthUncompressed), |
| 67 | + "http.request_content_length_uncompressed"}, |
| 68 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpResponseContentLength), "http.response_content_length"}, |
| 69 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpResponseContentLengthUncompressed), |
| 70 | + "http.response_content_length_uncompressed"}, |
| 71 | + |
| 72 | + // HTTP Span Client Attributes |
| 73 | + // One of the following combinations: |
| 74 | + // - http.url |
| 75 | + // - http.scheme, http.host, http.target |
| 76 | + // - http.scheme, net.peer.name, net.peer.port, http.target |
| 77 | + // - http.scheme, net.peer.ip, net.peer.port, http.target |
| 78 | + |
| 79 | + // HTTP Span Server Attributes |
| 80 | + // One of the following combinations: |
| 81 | + // -http.scheme, http.host, http.target |
| 82 | + // -http.scheme, http.server_name, net.host.port, http.target |
| 83 | + // -http.scheme, net.host.name, net.host.port, http.target |
| 84 | + // -http.url |
| 85 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpServerName), "http.server_name"}, |
| 86 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpRoute), "http.route"}, |
| 87 | + {OTEL_CPP_CONST_HASHCODE(AttrHttpClientIp), "http.client_ip"}, |
| 88 | + |
| 89 | + // DB: Connection-level attributes |
| 90 | + {OTEL_CPP_CONST_HASHCODE(AttrDbSystem), "db.system"}, // other_sql, mssql, mysql... |
| 91 | + {OTEL_CPP_CONST_HASHCODE(AttrDbConnectionString), "db.connection_string"}, |
| 92 | + {OTEL_CPP_CONST_HASHCODE(AttrDbUser), "db.user"}, |
| 93 | + // DB: Connection-level attributes for specific technologies |
| 94 | + {OTEL_CPP_CONST_HASHCODE(AttrDbMssqlInstanceName), "db.mssql.instance_name"}, |
| 95 | + {OTEL_CPP_CONST_HASHCODE(AttrDbJdbcDriverClassname), "db.jdbc.driver_classname"}, |
| 96 | + // DB: Call-level attributes |
| 97 | + {OTEL_CPP_CONST_HASHCODE(AttrDbName), "db.name"}, |
| 98 | + {OTEL_CPP_CONST_HASHCODE(AttrDbStatement), "db.statement"}, |
| 99 | + {OTEL_CPP_CONST_HASHCODE(AttrDbOperation), "db.operation"}, |
| 100 | + // DB: Call-level attributes for specific technologies |
| 101 | + {OTEL_CPP_CONST_HASHCODE(AttrDbHbaseNamespace), "db.hbase.namespace"}, |
| 102 | + {OTEL_CPP_CONST_HASHCODE(AttrDbRedisDatabaseIndex), "db.redis.database_index"}, |
| 103 | + {OTEL_CPP_CONST_HASHCODE(AttrDbMongodbCollection), "db.mongodb.collection"}, |
| 104 | + |
| 105 | + // // DB: Call-level attributes for Cassandra for clarity |
| 106 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraKeyspace), "db.cassandra.keyspace"}, |
| 107 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraPageSize), "db.cassandra.page_size"}, |
| 108 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraConsistencyLevel), "db.cassandra.consistency_level"}, |
| 109 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraTable), "db.cassandra.table"}, |
| 110 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraIdempotence), "db.cassandra.idempotence"}, |
| 111 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraSpeculativeExecutionCount), |
| 112 | + "db.cassandra.speculative_execution_count"}, |
| 113 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraCoordinatorId), "db.cassandra.coordinator.id"}, |
| 114 | + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraCoordinatorDC), "db.cassandra.coordinator.dc"}, |
| 115 | + |
| 116 | + // Common RPC attributes |
| 117 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcSystem), "rpc.system"}, |
| 118 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcService), "rpc.service"}, |
| 119 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcMethod), "rpc.method"}, |
| 120 | + // gRPC attributes |
| 121 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcGrpcStatusCode), "rpc.grpc.status_code"}, |
| 122 | + // JSON-RPC attributes |
| 123 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcVersion), "rpc.jsonrpc.version"}, |
| 124 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcRequestId), "rpc.jsonrpc.request_id"}, |
| 125 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcErrorCode), "rpc.jsonrpc.error_code"}, |
| 126 | + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcErrorMessage), "rpc.jsonrpc.error_message"}, |
| 127 | + |
| 128 | + // faas: General Attributes |
| 129 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasTrigger), "faas.trigger"}, |
| 130 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasExecution), "faas.execution"}, |
| 131 | + // faas: incoming invocations |
| 132 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasColdStart), "faas.coldstart"}, |
| 133 | + // faas: outgoing invocations |
| 134 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedName), "faas.invoked_name"}, |
| 135 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedProvider), "faas.invoked_provider"}, |
| 136 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedRegion), "faas.invoked_region"}, |
| 137 | + // faas: datastore trigger |
| 138 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentCollection), "faas.document.collection"}, |
| 139 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentOperation), "faas.document.operation"}, |
| 140 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentTime), "faas.document.time"}, |
| 141 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentName), "faas.document.name"}, |
| 142 | + // faas: timer trigger |
| 143 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasTime), "faas.time"}, |
| 144 | + {OTEL_CPP_CONST_HASHCODE(AttrFaasCron), "faas.cron"}, |
| 145 | + |
| 146 | + // messaging attributes |
| 147 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingSystem), "messaging.system"}, |
| 148 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingDestination), "messaging.destination"}, |
| 149 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingDestinationKind), "messaging.destination_kind"}, |
| 150 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingTempDestination), "messaging.temp_destination"}, |
| 151 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingProtocol), "messaging.protocol"}, |
| 152 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingProtocolVersion), "messaging.protocol_version"}, |
| 153 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingUrl), "messaging.url"}, |
| 154 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingMessageId), "messaging.message_id"}, |
| 155 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingConversationId), "messaging.conversation_id"}, |
| 156 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingPayloadSize), "messaging.message_payload_size_bytes"}, |
| 157 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingPayloadCompressedSize), |
| 158 | + "messaging.message_payload_compressed_size_bytes"}, |
| 159 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingOperation), "messaging.operation"}, |
| 160 | + // messaging attributes specific to messaging systems |
| 161 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingRabbitMQRoutingKey), "messaging.rabbitmq.routing_key"}, |
| 162 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaMessageKey), "messaging.kafka.message_key"}, |
| 163 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaConsumerGroup), "messaging.kafka.consumer_group"}, |
| 164 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaClientId), "messaging.kafka.client_id"}, |
| 165 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaPartition), "messaging.kafka.partition"}, |
| 166 | + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaTombstone), "messaging.kafka.tombstone"}, |
| 167 | + |
| 168 | + // Exceptions attributes |
| 169 | + {OTEL_CPP_CONST_HASHCODE(AttrExceptionType), "exception.type"}, |
| 170 | + {OTEL_CPP_CONST_HASHCODE(AttrExceptionMessage), "exception.message"}, |
| 171 | + {OTEL_CPP_CONST_HASHCODE(AttrExceptionStacktrace), "exception.stacktrace"}, |
| 172 | + {OTEL_CPP_CONST_HASHCODE(AttrExceptionEscapted), "exception.escaped"}, |
| 173 | +}; |
| 174 | +// function to generate hash code for semantic conventions attributes. |
| 175 | + |
| 176 | +#define OTEL_CPP_TRACE_ATTRIBUTES_MAX (sizeof(attribute_ids) / sizeof(attribute_ids[0])) |
| 177 | + |
| 178 | +inline const char *attr(uint32_t attr) |
| 179 | +{ |
| 180 | + for (int i = 0; i < OTEL_CPP_TRACE_ATTRIBUTES_MAX; i++) |
| 181 | + { |
| 182 | + if (attribute_ids[i].attribute_id == attr) |
| 183 | + return attribute_ids[i].attribute_key; |
| 184 | + } |
| 185 | + return ""; |
| 186 | +} |
| 187 | + |
| 188 | +} // namespace trace |
| 189 | +OPENTELEMETRY_END_NAMESPACE |
0 commit comments