From 782aa617314977d931c8ffeecb66270aee3da5ed Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 21 Jun 2021 16:32:09 +0530 Subject: [PATCH 1/8] sem conv for trace --- .../trace/semantic_conventions.h | 190 ++++++++++++++++++ examples/grpc/client.cpp | 16 +- examples/grpc/server.cpp | 10 +- examples/http/client.cc | 11 +- examples/http/server.cc | 25 ++- 5 files changed, 226 insertions(+), 26 deletions(-) create mode 100644 api/include/opentelemetry/trace/semantic_conventions.h diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h new file mode 100644 index 0000000000..cd527d6b5a --- /dev/null +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -0,0 +1,190 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" + +#define OTEL_TRACE_GENERATE_SEMCONV_METHOD(attribute_name, attribute_value) \ + static const nostd::string_view Get##attribute_name() noexcept \ + { \ + static const nostd::string_view attribute_name = attribute_value; \ + return attribute_name; \ + } + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ + +/** + * Stores the Constants for semantic kAttribute names outlined by the OpenTelemetry specifications. + * . + */ +class SemanticConventions final +{ +public: + // The set of constants matches the specification as of this commit. + // https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md + + // Genetal network connection attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetTransport, "net.transport") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerIp, "net.peer.ip") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerPort, "net.peer.port") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerName, "net.peer.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostIp, "net.host.ip") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostPort, "net.host.port") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostName, "net.host.name") + + // General identity attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserId, "enduser.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserRole, "enduser.role") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserScope, "enduser.scope") + + // General remote service attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributePeerService, "peer.service") + + // General thread attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeThreadId, "thread.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeThreadName, "thread.name") + + // Source Code Attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeFunction, "code.function") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeNamespace, "code.namespace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeFilepath, "code.filepath") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeLineno, "code.lineno") + + // Http Span Common Attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpMethod, "http.method") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpUrl, "http.url") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpTarget, "http.target") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpHost, "http.host") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpScheme, "http.scheme") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpStatusCode, "http.status_code") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpFlavor, "http.flavor") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpUserAgent, "http.user_agent") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRequestContentLength, + "http.request_content_length") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRequestContentLengthUncompressed, + "http.request_content_length_uncompressed") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpResponseContentLength, + "http.response_content_length") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpResponseContentLengthUncompressed, + "http.response_content_length_uncompressed") + + // HTTP Span Client Attributes + // One of the following combinations: + // - http.url + // - http.scheme, http.host, http.target + // - http.scheme, net.peer.name, net.peer.port, http.target + // - http.scheme, net.peer.ip, net.peer.port, http.target + + // HTTP Span Server Attributes + // One of the following combinations: + // -http.scheme, http.host, http.target + // -http.scheme, http.server_name, net.host.port, http.target + // -http.scheme, net.host.name, net.host.port, http.target + // -http.url + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpServerName, "http.server_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRoute, "http.route") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpClientIp, "http.client_ip") + + // DB: Connection-level attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbSystem, "db.system") // other_sql, mssql, mysql... + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbConnectionString, "db.connection_string") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbUser, "db.user") + // DB: Connection-level attributes for specific technologies + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbMssqlInstanceName, "db.mssql.instance_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbJdbcDriverClassname, "db.jdbc.driver_classname") + // DB: Call-level attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbName, "db.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbStatement, "db.statement") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbOperation, "db.operation") + // DB: Call-level attributes for specific technologies + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbHbaseNamespace, "db.hbase.namespace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbRedisDatabaseIndex, "db.redis.database_index") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbMongodbCollection, "db.mongodb.collection") + + // // DB: Call-level attributes for Cassandra for clarity + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraKeyspace, "db.cassandra.keyspace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraPageSize, "db.cassandra.page_size") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraConsistencyLevel, + "db.cassandra.consistency_level") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraTable, "db.cassandra.table") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraIdempotence, "db.cassandra.idempotence") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraSpeculativeExecutionCount, + "db.cassandra.speculative_execution_count") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraCoordinatorId, + "db.cassandra.coordinator.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraCoordinatorDC, + "db.cassandra.coordinator.dc") + + // Common RPC attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcSystem, "rpc.system") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcService, "rpc.service") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcMethod, "rpc.method") + // gRPC attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcGrpcStatusCode, "rpc.grpc.status_code") + // JSON-RPC attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcVersion, "rpc.jsonrpc.version") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcRequestId, "rpc.jsonrpc.request_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcErrorCode, "rpc.jsonrpc.error_code") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcErrorMessage, "rpc.jsonrpc.error_message") + + // faas: General Attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasTrigger, "faas.trigger") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasExecution, "faas.execution") + // faas: incoming invocations + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasColdStart, "faas.coldstart") + // faas: outgoing invocations + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedName, "faas.invoked_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedProvider, "faas.invoked_provider") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedRegion, "faas.invoked_region") + // faas: datastore trigger + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentCollection, "faas.document.collection") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentOperation, "faas.document.operation") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentTime, "faas.document.time") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentName, "faas.document.name") + // faas: timer trigger + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasTime, "faas.time") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasCron, "faas.cron") + + // messaging attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingSystem, "messaging.system") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingDestination, "messaging.destination") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingDestinationKind, + "messaging.destination_kind") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingTempDestination, + "messaging.temp_destination") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingProtocol, "messaging.protocol") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingProtocolVersion, + "messaging.protocol_version") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingUrl, "messaging.url") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingMessageId, "messaging.message_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingConversationId, "messaging.conversation_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingPayloadSize, + "messaging.message_payload_size_bytes") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingPayloadCompressedSize, + "messaging.message_payload_compressed_size_bytes") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingOperation, "messaging.operation") + // messaging attributes specific to messaging systems + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingRabbitMQRoutingKey, + "messaging.rabbitmq.routing_key") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaMessageKey, + "messaging.kafka.message_key") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaConsumerGroup, + "messaging.kafka.consumer_group") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaClientId, "messaging.kafka.client_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaPartition, "messaging.kafka.partition") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaTombstone, "messaging.kafka.tombstone") + + // Exceptions attributes + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionType, "exception.type") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionMessage, "exception.message") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionStacktrace, "exception.stacktrace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionEscapted, "exception.escaped") +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/examples/grpc/client.cpp b/examples/grpc/client.cpp index 719a62225b..c39f8dd8fa 100644 --- a/examples/grpc/client.cpp +++ b/examples/grpc/client.cpp @@ -4,6 +4,7 @@ #include #include "messages.grpc.pb.h" +#include "opentelemetry/trace/semantic_conventions.h" #include "tracer_common.h" #include #include @@ -22,6 +23,7 @@ using grpc_example::GreetResponse; namespace { +using namespace opentelemetry::trace; class GreeterClient { public: @@ -40,11 +42,11 @@ class GreeterClient std::string span_name = "GreeterClient/Greet"; auto span = get_tracer("grpc")->StartSpan(span_name, - {{"rpc.system", "grpc"}, - {"rpc.service", "grpc-example.GreetService"}, - {"rpc.method", "Greet"}, - {"net.peer.ip", ip}, - {"net.peer.port", port}}, + {{SemanticConventions::GetAttributeRpcSystem(), "grpc"}, + {SemanticConventions::GetAttributeRpcService(), "grpc-example.GreetService"}, + {SemanticConventions::GetAttributeRpcMethod(), "Greet"}, + {SemanticConventions::GetAttributeNetPeerIp(), ip}, + {SemanticConventions::GetAttributeNetPeerPort(), port}}, options); auto scope = get_tracer("grpc-client")->WithActiveSpan(span); @@ -60,7 +62,7 @@ class GreeterClient if (status.ok()) { span->SetStatus(opentelemetry::trace::StatusCode::kOk); - span->SetAttribute("rpc.grpc.status_code", status.error_code()); + span->SetAttribute(SemanticConventions::GetAttributeRpcGrpcStatusCode(), status.error_code()); // Make sure to end your spans! span->End(); return response.response(); @@ -69,7 +71,7 @@ class GreeterClient { std::cout << status.error_code() << ": " << status.error_message() << std::endl; span->SetStatus(opentelemetry::trace::StatusCode::kError); - span->SetAttribute("rpc.grpc.status_code", status.error_code()); + span->SetAttribute(SemanticConventions::GetAttributeRpcGrpcStatusCode(), status.error_code()); // Make sure to end your spans! span->End(); return "RPC failed"; diff --git a/examples/grpc/server.cpp b/examples/grpc/server.cpp index 167fc08966..f9f29a7090 100644 --- a/examples/grpc/server.cpp +++ b/examples/grpc/server.cpp @@ -1,6 +1,7 @@ #include "messages.grpc.pb.h" #include "tracer_common.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" +#include "opentelemetry/trace/semantic_conventions.h" #include #include @@ -26,6 +27,7 @@ using grpc_example::GreetResponse; using Span = opentelemetry::trace::Span; using SpanContext = opentelemetry::trace::SpanContext; +using SemanticConventions = opentelemetry::trace::SemanticConventions; namespace { @@ -55,10 +57,10 @@ class GreeterServer final : public Greeter::Service std::string span_name = "GreeterService/Greet"; auto span = get_tracer("grpc") ->StartSpan(span_name, - {{"rpc.system", "grpc"}, - {"rpc.service", "GreeterService"}, - {"rpc.method", "Greet"}, - {"rpc.grpc.status_code", 0}}, + {{SemanticConventions::GetAttributeRpcSystem(), "grpc"}, + {SemanticConventions::GetAttributeRpcService(), "GreeterService"}, + {SemanticConventions::GetAttributeRpcMethod(), "Greet"}, + {SemanticConventions::GetAttributeRpcGrpcStatusCode(), 0}}, options); auto scope = get_tracer("grpc")->WithActiveSpan(span); diff --git a/examples/http/client.cc b/examples/http/client.cc index aa6bc86af7..a96b91abf0 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -3,11 +3,14 @@ #include "opentelemetry/ext/http/client/http_client_factory.h" #include "opentelemetry/ext/http/common/url_parser.h" +#include "opentelemetry/trace/semantic_conventions.h" #include "tracer_common.h" namespace { +using namespace opentelemetry::trace; + void sendRequest(const std::string &url) { auto http_client = opentelemetry::ext::http::client::HttpClientFactory::CreateSync(); @@ -20,9 +23,9 @@ void sendRequest(const std::string &url) std::string span_name = url_parser.path_; auto span = get_tracer("http-client") ->StartSpan(span_name, - {{"http.url", url_parser.url_}, - {"http.scheme", url_parser.scheme_}, - {"http.method", "GET"}}, + {{SemanticConventions::GetAttributeHttpUrl(), url_parser.url_}, + {SemanticConventions::GetAttributeHttpScheme(), url_parser.scheme_}, + {SemanticConventions::GetAttributeHttpMethod(), "GET"}}, options); auto scope = get_tracer("http-client")->WithActiveSpan(span); @@ -38,7 +41,7 @@ void sendRequest(const std::string &url) { // set span attributes auto status_code = result.GetResponse().GetStatusCode(); - span->SetAttribute("http.status_code", status_code); + span->SetAttribute(SemanticConventions::GetAttributeHttpStatusCode(), status_code); result.GetResponse().ForEachHeader([&span](opentelemetry::nostd::string_view header_name, opentelemetry::nostd::string_view header_value) { span->SetAttribute("http.header." + std::string(header_name.data()), header_value); diff --git a/examples/http/server.cc b/examples/http/server.cc index 8a9c437d60..4c199bf0b6 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "server.h" +#include "opentelemetry/trace/semantic_conventions.h" #include "tracer_common.h" #include @@ -9,6 +10,9 @@ namespace { + +using namespace opentelemetry::trace; +; uint16_t server_port = 8800; constexpr const char *server_name = "localhost"; @@ -31,17 +35,16 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback options.parent = opentelemetry::trace::propagation::GetSpan(new_context)->GetContext(); // start span with parent context extracted from http header - auto span = - get_tracer("http-server") - ->StartSpan( - span_name, - {{"http.server_name", server_name}, - {"net.host.port", server_port}, - {"http.method", request.method}, - {"http.scheme", "http"}, - {"http.request_content_length", static_cast(request.content.length())}, - {"http.client_ip", request.client}}, - options); + auto span = get_tracer("http-server") + ->StartSpan(span_name, + {{SemanticConventions::GetAttributeHttpServerName(), server_name}, + {SemanticConventions::GetAttributeNetHostPort(), server_port}, + {SemanticConventions::GetAttributeHttpMethod(), request.method}, + {SemanticConventions::GetAttributeHttpScheme(), "http"}, + {SemanticConventions::GetAttributeHttpRequestContentLength(), + static_cast(request.content.length())}, + {SemanticConventions::GetAttributeHttpClientIp(), request.client}}, + options); auto scope = get_tracer("http_server")->WithActiveSpan(span); From 2067a24198aa032038d488ae9818a74e573bd0ed Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 21 Jun 2021 16:47:39 +0530 Subject: [PATCH 2/8] new line at end --- api/include/opentelemetry/trace/semantic_conventions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index cd527d6b5a..bc3ca0ed9f 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -187,4 +187,4 @@ class SemanticConventions final OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionEscapted, "exception.escaped") }; } // namespace trace -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE From f947863d3b67514b59386e97b4e962722b82987e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 21 Jun 2021 23:59:20 +0530 Subject: [PATCH 3/8] Update api/include/opentelemetry/trace/semantic_conventions.h Co-authored-by: Tom Tan --- api/include/opentelemetry/trace/semantic_conventions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index bc3ca0ed9f..4ba0edd3ba 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -29,7 +29,7 @@ class SemanticConventions final // https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md - // Genetal network connection attributes + // General network connection attributes OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetTransport, "net.transport") OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerIp, "net.peer.ip") OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerPort, "net.peer.port") From 927447a2825a867f7360a1cf8053f9e519b86106 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 22 Jun 2021 08:25:58 +0530 Subject: [PATCH 4/8] use constexpr instead of const --- .../trace/semantic_conventions.h | 205 ++++++++---------- 1 file changed, 94 insertions(+), 111 deletions(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index 4ba0edd3ba..8bea1e343d 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -3,15 +3,10 @@ #pragma once -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" #define OTEL_TRACE_GENERATE_SEMCONV_METHOD(attribute_name, attribute_value) \ - static const nostd::string_view Get##attribute_name() noexcept \ - { \ - static const nostd::string_view attribute_name = attribute_value; \ - return attribute_name; \ - } + static constexpr const char *GetAttribute##attribute_name() noexcept { return attribute_value; } OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -30,48 +25,46 @@ class SemanticConventions final // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md // General network connection attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetTransport, "net.transport") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerIp, "net.peer.ip") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerPort, "net.peer.port") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetPeerName, "net.peer.name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostIp, "net.host.ip") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostPort, "net.host.port") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeNetHostName, "net.host.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetTransport, "net.transport") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerIp, "net.peer.ip") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerPort, "net.peer.port") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerName, "net.peer.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostIp, "net.host.ip") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostPort, "net.host.port") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostName, "net.host.name") // General identity attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserId, "enduser.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserRole, "enduser.role") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeEnduserScope, "enduser.scope") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserId, "enduser.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserRole, "enduser.role") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserScope, "enduser.scope") // General remote service attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributePeerService, "peer.service") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(PeerService, "peer.service") // General thread attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeThreadId, "thread.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeThreadName, "thread.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ThreadId, "thread.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ThreadName, "thread.name") // Source Code Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeFunction, "code.function") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeNamespace, "code.namespace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeFilepath, "code.filepath") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeCodeLineno, "code.lineno") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeFunction, "code.function") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeNamespace, "code.namespace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeFilepath, "code.filepath") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeLineno, "code.lineno") // Http Span Common Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpMethod, "http.method") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpUrl, "http.url") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpTarget, "http.target") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpHost, "http.host") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpScheme, "http.scheme") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpStatusCode, "http.status_code") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpFlavor, "http.flavor") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpUserAgent, "http.user_agent") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRequestContentLength, - "http.request_content_length") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRequestContentLengthUncompressed, + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpMethod, "http.method") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpUrl, "http.url") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpTarget, "http.target") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpHost, "http.host") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpScheme, "http.scheme") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpStatusCode, "http.status_code") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpFlavor, "http.flavor") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpUserAgent, "http.user_agent") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRequestContentLength, "http.request_content_length") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRequestContentLengthUncompressed, "http.request_content_length_uncompressed") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpResponseContentLength, - "http.response_content_length") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpResponseContentLengthUncompressed, + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpResponseContentLength, "http.response_content_length") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpResponseContentLengthUncompressed, "http.response_content_length_uncompressed") // HTTP Span Client Attributes @@ -87,104 +80,94 @@ class SemanticConventions final // -http.scheme, http.server_name, net.host.port, http.target // -http.scheme, net.host.name, net.host.port, http.target // -http.url - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpServerName, "http.server_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpRoute, "http.route") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeHttpClientIp, "http.client_ip") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpServerName, "http.server_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRoute, "http.route") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpClientIp, "http.client_ip") // DB: Connection-level attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbSystem, "db.system") // other_sql, mssql, mysql... - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbConnectionString, "db.connection_string") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbUser, "db.user") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbSystem, "db.system") // other_sql, mssql, mysql... + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbConnectionString, "db.connection_string") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbUser, "db.user") // DB: Connection-level attributes for specific technologies - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbMssqlInstanceName, "db.mssql.instance_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbJdbcDriverClassname, "db.jdbc.driver_classname") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbMssqlInstanceName, "db.mssql.instance_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbJdbcDriverClassname, "db.jdbc.driver_classname") // DB: Call-level attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbName, "db.name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbStatement, "db.statement") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbOperation, "db.operation") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbName, "db.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbStatement, "db.statement") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbOperation, "db.operation") // DB: Call-level attributes for specific technologies - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbHbaseNamespace, "db.hbase.namespace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbRedisDatabaseIndex, "db.redis.database_index") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbMongodbCollection, "db.mongodb.collection") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbHbaseNamespace, "db.hbase.namespace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbRedisDatabaseIndex, "db.redis.database_index") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbMongodbCollection, "db.mongodb.collection") // // DB: Call-level attributes for Cassandra for clarity - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraKeyspace, "db.cassandra.keyspace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraPageSize, "db.cassandra.page_size") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraConsistencyLevel, - "db.cassandra.consistency_level") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraTable, "db.cassandra.table") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraIdempotence, "db.cassandra.idempotence") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraSpeculativeExecutionCount, + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraKeyspace, "db.cassandra.keyspace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraPageSize, "db.cassandra.page_size") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraConsistencyLevel, "db.cassandra.consistency_level") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraTable, "db.cassandra.table") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraIdempotence, "db.cassandra.idempotence") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraSpeculativeExecutionCount, "db.cassandra.speculative_execution_count") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraCoordinatorId, - "db.cassandra.coordinator.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeDbCassandraCoordinatorDC, - "db.cassandra.coordinator.dc") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraCoordinatorId, "db.cassandra.coordinator.id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraCoordinatorDC, "db.cassandra.coordinator.dc") // Common RPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcSystem, "rpc.system") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcService, "rpc.service") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcMethod, "rpc.method") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcSystem, "rpc.system") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcService, "rpc.service") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcMethod, "rpc.method") // gRPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcGrpcStatusCode, "rpc.grpc.status_code") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcGrpcStatusCode, "rpc.grpc.status_code") // JSON-RPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcVersion, "rpc.jsonrpc.version") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcRequestId, "rpc.jsonrpc.request_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcErrorCode, "rpc.jsonrpc.error_code") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeRpcJsonrpcErrorMessage, "rpc.jsonrpc.error_message") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcVersion, "rpc.jsonrpc.version") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcRequestId, "rpc.jsonrpc.request_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcErrorCode, "rpc.jsonrpc.error_code") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcErrorMessage, "rpc.jsonrpc.error_message") // faas: General Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasTrigger, "faas.trigger") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasExecution, "faas.execution") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasTrigger, "faas.trigger") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasExecution, "faas.execution") // faas: incoming invocations - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasColdStart, "faas.coldstart") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasColdStart, "faas.coldstart") // faas: outgoing invocations - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedName, "faas.invoked_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedProvider, "faas.invoked_provider") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasInvokedRegion, "faas.invoked_region") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedName, "faas.invoked_name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedProvider, "faas.invoked_provider") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedRegion, "faas.invoked_region") // faas: datastore trigger - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentCollection, "faas.document.collection") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentOperation, "faas.document.operation") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentTime, "faas.document.time") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasDocumentName, "faas.document.name") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentCollection, "faas.document.collection") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentOperation, "faas.document.operation") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentTime, "faas.document.time") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentName, "faas.document.name") // faas: timer trigger - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasTime, "faas.time") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeFaasCron, "faas.cron") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasTime, "faas.time") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasCron, "faas.cron") // messaging attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingSystem, "messaging.system") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingDestination, "messaging.destination") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingDestinationKind, - "messaging.destination_kind") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingTempDestination, - "messaging.temp_destination") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingProtocol, "messaging.protocol") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingProtocolVersion, - "messaging.protocol_version") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingUrl, "messaging.url") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingMessageId, "messaging.message_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingConversationId, "messaging.conversation_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingPayloadSize, - "messaging.message_payload_size_bytes") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingPayloadCompressedSize, + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingSystem, "messaging.system") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingDestination, "messaging.destination") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingDestinationKind, "messaging.destination_kind") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingTempDestination, "messaging.temp_destination") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingProtocol, "messaging.protocol") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingProtocolVersion, "messaging.protocol_version") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingUrl, "messaging.url") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingMessageId, "messaging.message_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingConversationId, "messaging.conversation_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingPayloadSize, "messaging.message_payload_size_bytes") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingPayloadCompressedSize, "messaging.message_payload_compressed_size_bytes") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingOperation, "messaging.operation") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingOperation, "messaging.operation") // messaging attributes specific to messaging systems - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingRabbitMQRoutingKey, - "messaging.rabbitmq.routing_key") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaMessageKey, - "messaging.kafka.message_key") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaConsumerGroup, - "messaging.kafka.consumer_group") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaClientId, "messaging.kafka.client_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaPartition, "messaging.kafka.partition") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeMessagingKafkaTombstone, "messaging.kafka.tombstone") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingRabbitMQRoutingKey, "messaging.rabbitmq.routing_key") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaMessageKey, "messaging.kafka.message_key") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaConsumerGroup, "messaging.kafka.consumer_group") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaClientId, "messaging.kafka.client_id") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaPartition, "messaging.kafka.partition") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaTombstone, "messaging.kafka.tombstone") // Exceptions attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionType, "exception.type") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionMessage, "exception.message") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionStacktrace, "exception.stacktrace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(AttributeExceptionEscapted, "exception.escaped") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionType, "exception.type") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionMessage, "exception.message") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionStacktrace, "exception.stacktrace") + OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionEscapted, "exception.escaped") }; } // namespace trace OPENTELEMETRY_END_NAMESPACE From 035a0afe4ba32fd4a7782b67252d5da84620dcec Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Jun 2021 12:23:39 +0530 Subject: [PATCH 5/8] reimplement --- .../trace/semantic_conventions.h | 318 +++++++++--------- examples/http/client.cc | 8 +- examples/http/server.cc | 12 +- .../sdk/resource/semantic_conventions.h | 6 +- .../sdk/resource/semantic_conventions_old.h | 136 -------- 5 files changed, 178 insertions(+), 302 deletions(-) delete mode 100644 sdk/include/opentelemetry/sdk/resource/semantic_conventions_old.h diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index 8bea1e343d..4b714ca268 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -3,10 +3,11 @@ #pragma once +#include "opentelemetry/common/string_util.h" #include "opentelemetry/version.h" -#define OTEL_TRACE_GENERATE_SEMCONV_METHOD(attribute_name, attribute_value) \ - static constexpr const char *GetAttribute##attribute_name() noexcept { return attribute_value; } +#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name)) +#define OTEL_CPP_TRACE_ATTRIBUTES_MAX (sizeof(attribute_ids) / sizeof(attribute_ids[0])) OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -17,157 +18,170 @@ namespace trace * . */ -class SemanticConventions final +static const struct { -public: - // The set of constants matches the specification as of this commit. - // https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md - - // General network connection attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetTransport, "net.transport") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerIp, "net.peer.ip") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerPort, "net.peer.port") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetPeerName, "net.peer.name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostIp, "net.host.ip") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostPort, "net.host.port") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(NetHostName, "net.host.name") - - // General identity attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserId, "enduser.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserRole, "enduser.role") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(EnduserScope, "enduser.scope") - - // General remote service attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(PeerService, "peer.service") - - // General thread attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ThreadId, "thread.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ThreadName, "thread.name") - - // Source Code Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeFunction, "code.function") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeNamespace, "code.namespace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeFilepath, "code.filepath") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(CodeLineno, "code.lineno") - - // Http Span Common Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpMethod, "http.method") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpUrl, "http.url") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpTarget, "http.target") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpHost, "http.host") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpScheme, "http.scheme") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpStatusCode, "http.status_code") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpFlavor, "http.flavor") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpUserAgent, "http.user_agent") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRequestContentLength, "http.request_content_length") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRequestContentLengthUncompressed, - "http.request_content_length_uncompressed") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpResponseContentLength, "http.response_content_length") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpResponseContentLengthUncompressed, - "http.response_content_length_uncompressed") - - // HTTP Span Client Attributes - // One of the following combinations: - // - http.url - // - http.scheme, http.host, http.target - // - http.scheme, net.peer.name, net.peer.port, http.target - // - http.scheme, net.peer.ip, net.peer.port, http.target - - // HTTP Span Server Attributes - // One of the following combinations: - // -http.scheme, http.host, http.target - // -http.scheme, http.server_name, net.host.port, http.target - // -http.scheme, net.host.name, net.host.port, http.target - // -http.url - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpServerName, "http.server_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpRoute, "http.route") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(HttpClientIp, "http.client_ip") - - // DB: Connection-level attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbSystem, "db.system") // other_sql, mssql, mysql... - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbConnectionString, "db.connection_string") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbUser, "db.user") - // DB: Connection-level attributes for specific technologies - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbMssqlInstanceName, "db.mssql.instance_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbJdbcDriverClassname, "db.jdbc.driver_classname") - // DB: Call-level attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbName, "db.name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbStatement, "db.statement") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbOperation, "db.operation") - // DB: Call-level attributes for specific technologies - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbHbaseNamespace, "db.hbase.namespace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbRedisDatabaseIndex, "db.redis.database_index") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbMongodbCollection, "db.mongodb.collection") - - // // DB: Call-level attributes for Cassandra for clarity - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraKeyspace, "db.cassandra.keyspace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraPageSize, "db.cassandra.page_size") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraConsistencyLevel, "db.cassandra.consistency_level") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraTable, "db.cassandra.table") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraIdempotence, "db.cassandra.idempotence") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraSpeculativeExecutionCount, - "db.cassandra.speculative_execution_count") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraCoordinatorId, "db.cassandra.coordinator.id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(DbCassandraCoordinatorDC, "db.cassandra.coordinator.dc") - - // Common RPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcSystem, "rpc.system") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcService, "rpc.service") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcMethod, "rpc.method") - // gRPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcGrpcStatusCode, "rpc.grpc.status_code") - // JSON-RPC attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcVersion, "rpc.jsonrpc.version") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcRequestId, "rpc.jsonrpc.request_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcErrorCode, "rpc.jsonrpc.error_code") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(RpcJsonrpcErrorMessage, "rpc.jsonrpc.error_message") - - // faas: General Attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasTrigger, "faas.trigger") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasExecution, "faas.execution") - // faas: incoming invocations - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasColdStart, "faas.coldstart") - // faas: outgoing invocations - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedName, "faas.invoked_name") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedProvider, "faas.invoked_provider") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasInvokedRegion, "faas.invoked_region") - // faas: datastore trigger - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentCollection, "faas.document.collection") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentOperation, "faas.document.operation") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentTime, "faas.document.time") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasDocumentName, "faas.document.name") - // faas: timer trigger - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasTime, "faas.time") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(FaasCron, "faas.cron") - - // messaging attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingSystem, "messaging.system") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingDestination, "messaging.destination") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingDestinationKind, "messaging.destination_kind") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingTempDestination, "messaging.temp_destination") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingProtocol, "messaging.protocol") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingProtocolVersion, "messaging.protocol_version") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingUrl, "messaging.url") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingMessageId, "messaging.message_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingConversationId, "messaging.conversation_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingPayloadSize, "messaging.message_payload_size_bytes") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingPayloadCompressedSize, - "messaging.message_payload_compressed_size_bytes") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingOperation, "messaging.operation") - // messaging attributes specific to messaging systems - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingRabbitMQRoutingKey, "messaging.rabbitmq.routing_key") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaMessageKey, "messaging.kafka.message_key") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaConsumerGroup, "messaging.kafka.consumer_group") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaClientId, "messaging.kafka.client_id") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaPartition, "messaging.kafka.partition") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(MessagingKafkaTombstone, "messaging.kafka.tombstone") - - // Exceptions attributes - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionType, "exception.type") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionMessage, "exception.message") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionStacktrace, "exception.stacktrace") - OTEL_TRACE_GENERATE_SEMCONV_METHOD(ExceptionEscapted, "exception.escaped") + uint32_t attribute_id; + const char *attribute_key; +} attribute_ids[] = { + // The set of constants matches the specification as of this commit. + // https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/exceptions.md + + // General network connection attributes + {OTEL_CPP_CONST_HASHCODE(AttrNetTransport), "net.transport"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerIp), "net.peer.ip"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerPort), "net.peer.port"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetPeerName), "net.peer.name"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetHostIp), "net.host.ip"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetHostPort), "net.host.port"}, + {OTEL_CPP_CONST_HASHCODE(AttrNetHostName), "net.host.name"}, + + // General identity attributes + {OTEL_CPP_CONST_HASHCODE(AttrEnduserId), "enduser.id"}, + {OTEL_CPP_CONST_HASHCODE(AttrEnduserRole), "enduser.role"}, + {OTEL_CPP_CONST_HASHCODE(AttrEnduserScope), "enduser.scope"}, + + // General remote service attributes + {OTEL_CPP_CONST_HASHCODE(AttrPeerService), "peer.service"}, + + // General thread attributes + {OTEL_CPP_CONST_HASHCODE(AttrThreadId), "thread.id"}, + {OTEL_CPP_CONST_HASHCODE(AttrThreadName), "thread.name"}, + + // Source Code Attributes + {OTEL_CPP_CONST_HASHCODE(AttrCodeFunction), "code.function"}, + {OTEL_CPP_CONST_HASHCODE(AttrCodeNamespace), "code.namespace"}, + {OTEL_CPP_CONST_HASHCODE(AttrCodeFilepath), "code.filepath"}, + {OTEL_CPP_CONST_HASHCODE(AttrCodeLineno), "code.lineno"}, + + // Http Span Common Attributes + {OTEL_CPP_CONST_HASHCODE(AttrHttpMethod), "http.method"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpUrl), "http.url"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpTarget), "http.target"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpHost), "http.host"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpScheme), "http.scheme"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpStatusCode), "http.status_code"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpFlavor), "http.flavor"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpUserAgent), "http.user_agent"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpRequestContentLength), "http.request_content_length"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpRequestContentLengthUncompressed), + "http.request_content_length_uncompressed"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpResponseContentLength), "http.response_content_length"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpResponseContentLengthUncompressed), + "http.response_content_length_uncompressed"}, + + // HTTP Span Client Attributes + // One of the following combinations: + // - http.url + // - http.scheme, http.host, http.target + // - http.scheme, net.peer.name, net.peer.port, http.target + // - http.scheme, net.peer.ip, net.peer.port, http.target + + // HTTP Span Server Attributes + // One of the following combinations: + // -http.scheme, http.host, http.target + // -http.scheme, http.server_name, net.host.port, http.target + // -http.scheme, net.host.name, net.host.port, http.target + // -http.url + {OTEL_CPP_CONST_HASHCODE(AttrHttpServerName), "http.server_name"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpRoute), "http.route"}, + {OTEL_CPP_CONST_HASHCODE(AttrHttpClientIp), "http.client_ip"}, + + // DB: Connection-level attributes + {OTEL_CPP_CONST_HASHCODE(AttrDbSystem), "db.system"}, // other_sql, mssql, mysql... + {OTEL_CPP_CONST_HASHCODE(AttrDbConnectionString), "db.connection_string"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbUser), "db.user"}, + // DB: Connection-level attributes for specific technologies + {OTEL_CPP_CONST_HASHCODE(AttrDbMssqlInstanceName), "db.mssql.instance_name"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbJdbcDriverClassname), "db.jdbc.driver_classname"}, + // DB: Call-level attributes + {OTEL_CPP_CONST_HASHCODE(AttrDbName), "db.name"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbStatement), "db.statement"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbOperation), "db.operation"}, + // DB: Call-level attributes for specific technologies + {OTEL_CPP_CONST_HASHCODE(AttrDbHbaseNamespace), "db.hbase.namespace"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbRedisDatabaseIndex), "db.redis.database_index"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbMongodbCollection), "db.mongodb.collection"}, + + // // DB: Call-level attributes for Cassandra for clarity + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraKeyspace), "db.cassandra.keyspace"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraPageSize), "db.cassandra.page_size"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraConsistencyLevel), "db.cassandra.consistency_level"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraTable), "db.cassandra.table"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraIdempotence), "db.cassandra.idempotence"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraSpeculativeExecutionCount), + "db.cassandra.speculative_execution_count"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraCoordinatorId), "db.cassandra.coordinator.id"}, + {OTEL_CPP_CONST_HASHCODE(AttrDbCassandraCoordinatorDC), "db.cassandra.coordinator.dc"}, + + // Common RPC attributes + {OTEL_CPP_CONST_HASHCODE(AttrRpcSystem), "rpc.system"}, + {OTEL_CPP_CONST_HASHCODE(AttrRpcService), "rpc.service"}, + {OTEL_CPP_CONST_HASHCODE(AttrRpcMethod), "rpc.method"}, + // gRPC attributes + {OTEL_CPP_CONST_HASHCODE(AttrRpcGrpcStatusCode), "rpc.grpc.status_code"}, + // JSON-RPC attributes + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcVersion), "rpc.jsonrpc.version"}, + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcRequestId), "rpc.jsonrpc.request_id"}, + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcErrorCode), "rpc.jsonrpc.error_code"}, + {OTEL_CPP_CONST_HASHCODE(AttrRpcJsonrpcErrorMessage), "rpc.jsonrpc.error_message"}, + + // faas: General Attributes + {OTEL_CPP_CONST_HASHCODE(AttrFaasTrigger), "faas.trigger"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasExecution), "faas.execution"}, + // faas: incoming invocations + {OTEL_CPP_CONST_HASHCODE(AttrFaasColdStart), "faas.coldstart"}, + // faas: outgoing invocations + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedName), "faas.invoked_name"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedProvider), "faas.invoked_provider"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasInvokedRegion), "faas.invoked_region"}, + // faas: datastore trigger + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentCollection), "faas.document.collection"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentOperation), "faas.document.operation"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentTime), "faas.document.time"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasDocumentName), "faas.document.name"}, + // faas: timer trigger + {OTEL_CPP_CONST_HASHCODE(AttrFaasTime), "faas.time"}, + {OTEL_CPP_CONST_HASHCODE(AttrFaasCron), "faas.cron"}, + + // messaging attributes + {OTEL_CPP_CONST_HASHCODE(AttrMessagingSystem), "messaging.system"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingDestination), "messaging.destination"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingDestinationKind), "messaging.destination_kind"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingTempDestination), "messaging.temp_destination"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingProtocol), "messaging.protocol"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingProtocolVersion), "messaging.protocol_version"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingUrl), "messaging.url"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingMessageId), "messaging.message_id"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingConversationId), "messaging.conversation_id"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingPayloadSize), "messaging.message_payload_size_bytes"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingPayloadCompressedSize), + "messaging.message_payload_compressed_size_bytes"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingOperation), "messaging.operation"}, + // messaging attributes specific to messaging systems + {OTEL_CPP_CONST_HASHCODE(AttrMessagingRabbitMQRoutingKey), "messaging.rabbitmq.routing_key"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaMessageKey), "messaging.kafka.message_key"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaConsumerGroup), "messaging.kafka.consumer_group"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaClientId), "messaging.kafka.client_id"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaPartition), "messaging.kafka.partition"}, + {OTEL_CPP_CONST_HASHCODE(AttrMessagingKafkaTombstone), "messaging.kafka.tombstone"}, + + // Exceptions attributes + {OTEL_CPP_CONST_HASHCODE(AttrExceptionType), "exception.type"}, + {OTEL_CPP_CONST_HASHCODE(AttrExceptionMessage), "exception.message"}, + {OTEL_CPP_CONST_HASHCODE(AttrExceptionStacktrace), "exception.stacktrace"}, + {OTEL_CPP_CONST_HASHCODE(AttrExceptionEscapted), "exception.escaped"}, }; +// function to generate hash code for semantic conventions attributes. +inline const char *attr(uint32_t attr) +{ + for (int i = 0; i < OTEL_CPP_TRACE_ATTRIBUTES_MAX; i++) + { + if (attribute_ids[i].attribute_id == attr) + return attribute_ids[i].attribute_key; + } + return ""; +} + } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/examples/http/client.cc b/examples/http/client.cc index a96b91abf0..77694815a1 100644 --- a/examples/http/client.cc +++ b/examples/http/client.cc @@ -23,9 +23,9 @@ void sendRequest(const std::string &url) std::string span_name = url_parser.path_; auto span = get_tracer("http-client") ->StartSpan(span_name, - {{SemanticConventions::GetAttributeHttpUrl(), url_parser.url_}, - {SemanticConventions::GetAttributeHttpScheme(), url_parser.scheme_}, - {SemanticConventions::GetAttributeHttpMethod(), "GET"}}, + {{OTEL_CPP_GET_ATTR(AttrHttpUrl), url_parser.url_}, + {OTEL_CPP_GET_ATTR(AttrHttpScheme), url_parser.scheme_}, + {OTEL_CPP_GET_ATTR(AttrHttpMethod), "GET"}}, options); auto scope = get_tracer("http-client")->WithActiveSpan(span); @@ -41,7 +41,7 @@ void sendRequest(const std::string &url) { // set span attributes auto status_code = result.GetResponse().GetStatusCode(); - span->SetAttribute(SemanticConventions::GetAttributeHttpStatusCode(), status_code); + span->SetAttribute(OTEL_CPP_GET_ATTR(AttrHttpStatusCode), status_code); result.GetResponse().ForEachHeader([&span](opentelemetry::nostd::string_view header_name, opentelemetry::nostd::string_view header_value) { span->SetAttribute("http.header." + std::string(header_name.data()), header_value); diff --git a/examples/http/server.cc b/examples/http/server.cc index 4c199bf0b6..6c1c9ce713 100644 --- a/examples/http/server.cc +++ b/examples/http/server.cc @@ -37,13 +37,13 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback // start span with parent context extracted from http header auto span = get_tracer("http-server") ->StartSpan(span_name, - {{SemanticConventions::GetAttributeHttpServerName(), server_name}, - {SemanticConventions::GetAttributeNetHostPort(), server_port}, - {SemanticConventions::GetAttributeHttpMethod(), request.method}, - {SemanticConventions::GetAttributeHttpScheme(), "http"}, - {SemanticConventions::GetAttributeHttpRequestContentLength(), + {{OTEL_CPP_GET_ATTR(AttrHttpServerName), server_name}, + {OTEL_CPP_GET_ATTR(AttrNetHostPort), server_port}, + {OTEL_CPP_GET_ATTR(AttrHttpMethod), request.method}, + {OTEL_CPP_GET_ATTR(AttrHttpScheme), "http"}, + {OTEL_CPP_GET_ATTR(AttrHttpRequestContentLength), static_cast(request.content.length())}, - {SemanticConventions::GetAttributeHttpClientIp(), request.client}}, + {OTEL_CPP_GET_ATTR(AttrHttpClientIp), request.client}}, options); auto scope = get_tracer("http_server")->WithActiveSpan(span); diff --git a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h index c604a5094f..693b3e108a 100644 --- a/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h +++ b/sdk/include/opentelemetry/sdk/resource/semantic_conventions.h @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include @@ -20,7 +18,7 @@ static const std::unordered_map attribute_ids = { {OTEL_CPP_CONST_HASHCODE(AttrServiceName), "service.name"}, {OTEL_CPP_CONST_HASHCODE(AttrServiceNamespace), "service.namespace"}, {OTEL_CPP_CONST_HASHCODE(AttrServiceInstance), "service.instance.id"}, - {OTEL_CPP_CONST_HASHCODE(AttrServiceVersion), "service.version "}, + {OTEL_CPP_CONST_HASHCODE(AttrServiceVersion), "service.version"}, // telemetry attributes {OTEL_CPP_CONST_HASHCODE(AttrTelemetrySdkName), "telemetry.sdk.name"}, @@ -123,7 +121,7 @@ static const std::unordered_map attribute_ids = { {OTEL_CPP_CONST_HASHCODE(AttrCronjobUid), "k8s.cronjob.id"}, {OTEL_CPP_CONST_HASHCODE(AttrCronjobName), "k8s.cronjob.name"}}; -// macro and function to generate hash code for semantic conventions attributes. +// function to generate hash code for semantic conventions attributes. inline const char *attr(uint32_t attr) { return (attribute_ids.find(attr) != attribute_ids.end()) ? attribute_ids.at(attr) : ""; diff --git a/sdk/include/opentelemetry/sdk/resource/semantic_conventions_old.h b/sdk/include/opentelemetry/sdk/resource/semantic_conventions_old.h deleted file mode 100644 index 7fcdc525ad..0000000000 --- a/sdk/include/opentelemetry/sdk/resource/semantic_conventions_old.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "opentelemetry/version.h" - -#define OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(attribute_name, attribute_value) \ - static constexpr const char *GetAttribute##attribute_name() noexcept { return attribute_value; } - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace sdk -{ -namespace resource -{ -/** - * Stores the Constants for semantic Attribute names for resources outlined by the OpenTelemetry - * specifications. . - */ - -class SemanticConventions final -{ - -public: - // service attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ServiceName, "service.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ServiceNamespace, "service.namespace"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ServiceInstance, "service.instance.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ServiceVersion, "service.version "); - - // telemetry attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(TelemetrySdkName, "telemetry.sdk.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(TelemetrySdkLanguage, "telemetry.sdk.language"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(TelemetrySdkVersion, "telemetry.sdk.version"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(TelemetryAutoVersion, "telemetry.auto.version"); - - // compute unit: container attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ContainerName, "container.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ContainerId, "container.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ContainerRuntime, "container.runtime"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ContainerImageName, "container.image.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ContainerImageTag, "container.image.tag"); - - // compute unit: faas attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(FaasName, "faas.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(FaasId, "faas.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(FaasVersion, "faas.version"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(FaasInstance, "faas.instance"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(FaasMaxMemory, "faas.max_memory"); - - // compute unit : process attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessId, "process.pid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessExecutableName, "process.executable.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessExecutablePath, "process.executable.path"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessCommand, "process.command"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessCommandLine, "process.command_line"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessCommandArgs, "process.command_args"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessOwner, "process.owner"); - - // compute : process runtimes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessRuntimeName, "process.runtime.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessRuntimeVersion, "process.runtime.version"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(ProcessRuntimeDescription, "process.runtime.description"); - - // compute unit : WebEngine - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(WebEngineName, "webengine.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(WebEngineVersion, "webengine.version"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(WebEngineDescription, "webengine.description"); - - // compute instance : host - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostId, "host.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostName, "host.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostType, "host.type"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostArch, "host.arch"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostImageName, "host.image.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostImageId, "host.image.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(HostImageVersion, "host.image.version"); - - // env os attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(OsType, "os.type"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(OsDescription, "os.description"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(OsName, "os.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(OsVersion, "os.version"); - - // env device attributes - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(DeviceId, "device.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(DeviceModelIdentifier, "device.model.identifier"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(DeviceModelName, "device.model.name"); - - // env cloud - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CloudProvider, "cloud.provider"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CloudAccountId, "cloud.account.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CloudRegion, "cloud.region"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CloudAvailabilityZone, "cloud.availability_zone"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CloudPlatform, "cloud.platform"); - - // env deployment - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(DeploymentEnvironment, "deployment.environment"); - - // env kubernetes - // - cluster - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sClusterName, "k8s.cluster.name"); - // - node - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sNodeName, "k8s.node.name"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sNodeUid, "k8s.node.uid"); - // - namespace - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sNamespaceName, "k8s.namespace.name"); - // - pod - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sPodUid, "k8s.pod.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sPodName, "k8s.pod.name"); - // - container - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sContainerName, "k8s.container.name"); - // - replicaset - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sReplicaSetUid, "k8s.replicaset.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sReplicaSetName, "k8s.replicaset.name"); - // - deployment - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sDeploymentUid, "k8s.deployment.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sDeploymentName, "k8s.deployment.name"); - // - stateful-set - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sStatefulSetUid, "k8s.statefulset.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sStatefulSetName, "k8s.statefulset.name"); - // - daemon set - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sDaemonSetUid, "k8s.daemonset.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sDaemonSetName, "k8s.daemonset.name"); - // - job - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sJobUid, "k8s.job.uid"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(K8sJobName, "k8s.job.name"); - // - cronjob - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CronjobUid, "k8s.cronjob.id"); - OTEL_RESOURCE_GENERATE_SEMCONV_METHOD(CronjobName, "k8s.cronjob.name"); -}; - -} // namespace resource -} // namespace sdk -OPENTELEMETRY_END_NAMESPACE From 2c88f161e96bc9f14f145a37af4c5d49719ae3cf Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Jun 2021 12:36:06 +0530 Subject: [PATCH 6/8] fix grpc example --- examples/grpc/client.cpp | 10 +++++----- examples/grpc/server.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/grpc/client.cpp b/examples/grpc/client.cpp index c39f8dd8fa..ade3053915 100644 --- a/examples/grpc/client.cpp +++ b/examples/grpc/client.cpp @@ -42,11 +42,11 @@ class GreeterClient std::string span_name = "GreeterClient/Greet"; auto span = get_tracer("grpc")->StartSpan(span_name, - {{SemanticConventions::GetAttributeRpcSystem(), "grpc"}, - {SemanticConventions::GetAttributeRpcService(), "grpc-example.GreetService"}, - {SemanticConventions::GetAttributeRpcMethod(), "Greet"}, - {SemanticConventions::GetAttributeNetPeerIp(), ip}, - {SemanticConventions::GetAttributeNetPeerPort(), port}}, + {{OTEL_CPP_GET_ATTR(AttrRpcSystem), "grpc"}, + {OTEL_CPP_GET_ATTR(AttrRpcService), "grpc-example.GreetService"}, + {OTEL_CPP_GET_ATTR(AttrRpcMethod), "Greet"}, + {OTEL_CPP_GET_ATTR(AttrNetPeerIp), ip}, + {OTEL_CPP_GET_ATTR(AttrNetPeerPort), port}}, options); auto scope = get_tracer("grpc-client")->WithActiveSpan(span); diff --git a/examples/grpc/server.cpp b/examples/grpc/server.cpp index f9f29a7090..1a123f298b 100644 --- a/examples/grpc/server.cpp +++ b/examples/grpc/server.cpp @@ -57,10 +57,10 @@ class GreeterServer final : public Greeter::Service std::string span_name = "GreeterService/Greet"; auto span = get_tracer("grpc") ->StartSpan(span_name, - {{SemanticConventions::GetAttributeRpcSystem(), "grpc"}, - {SemanticConventions::GetAttributeRpcService(), "GreeterService"}, - {SemanticConventions::GetAttributeRpcMethod(), "Greet"}, - {SemanticConventions::GetAttributeRpcGrpcStatusCode(), 0}}, + {{OTEL_CPP_GET_ATTR(AttrRpcSystem), "grpc"}, + {OTEL_CPP_GET_ATTR(AttrRpcService), "GreeterService"}, + {OTEL_CPP_GET_ATTR(AttrRpcMethod), "Greet"}, + {OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), 0}}, options); auto scope = get_tracer("grpc")->WithActiveSpan(span); From b4406368c3e21eb59782ab9485eb0e15f7b7eb49 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Jun 2021 12:51:32 +0530 Subject: [PATCH 7/8] fix grpc --- examples/grpc/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/grpc/client.cpp b/examples/grpc/client.cpp index ade3053915..e2224f0446 100644 --- a/examples/grpc/client.cpp +++ b/examples/grpc/client.cpp @@ -62,7 +62,7 @@ class GreeterClient if (status.ok()) { span->SetStatus(opentelemetry::trace::StatusCode::kOk); - span->SetAttribute(SemanticConventions::GetAttributeRpcGrpcStatusCode(), status.error_code()); + span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code()); // Make sure to end your spans! span->End(); return response.response(); @@ -71,7 +71,7 @@ class GreeterClient { std::cout << status.error_code() << ": " << status.error_message() << std::endl; span->SetStatus(opentelemetry::trace::StatusCode::kError); - span->SetAttribute(SemanticConventions::GetAttributeRpcGrpcStatusCode(), status.error_code()); + span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code()); // Make sure to end your spans! span->End(); return "RPC failed"; From 24cc6b38b0fa905bcf297f1d93613518b9430ab5 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Jun 2021 14:15:32 +0530 Subject: [PATCH 8/8] final fix for grpc --- api/include/opentelemetry/trace/semantic_conventions.h | 8 +++++--- examples/grpc/server.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h index 4b714ca268..13c5905783 100644 --- a/api/include/opentelemetry/trace/semantic_conventions.h +++ b/api/include/opentelemetry/trace/semantic_conventions.h @@ -6,13 +6,12 @@ #include "opentelemetry/common/string_util.h" #include "opentelemetry/version.h" -#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name)) -#define OTEL_CPP_TRACE_ATTRIBUTES_MAX (sizeof(attribute_ids) / sizeof(attribute_ids[0])) - OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { +#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name)) + /** * Stores the Constants for semantic kAttribute names outlined by the OpenTelemetry specifications. *