diff --git a/api/include/opentelemetry/trace/semantic_conventions.h b/api/include/opentelemetry/trace/semantic_conventions.h
new file mode 100644
index 0000000000..13c5905783
--- /dev/null
+++ b/api/include/opentelemetry/trace/semantic_conventions.h
@@ -0,0 +1,189 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+#pragma once
+
+#include "opentelemetry/common/string_util.h"
+#include "opentelemetry/version.h"
+
+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.
+ * .
+ */
+static const struct
+{
+ 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.
+
+#define OTEL_CPP_TRACE_ATTRIBUTES_MAX (sizeof(attribute_ids) / sizeof(attribute_ids[0]))
+
+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/grpc/client.cpp b/examples/grpc/client.cpp
index 472a933b98..fc170a7c5b 100644
--- a/examples/grpc/client.cpp
+++ b/examples/grpc/client.cpp
@@ -8,6 +8,7 @@
#include "messages.grpc.pb.h"
#endif
+#include "opentelemetry/trace/semantic_conventions.h"
#include "tracer_common.h"
#include
#include
@@ -26,6 +27,7 @@ using grpc_example::GreetResponse;
namespace
{
+using namespace opentelemetry::trace;
class GreeterClient
{
public:
@@ -44,11 +46,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}},
+ {{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);
@@ -64,7 +66,7 @@ class GreeterClient
if (status.ok())
{
span->SetStatus(opentelemetry::trace::StatusCode::kOk);
- span->SetAttribute("rpc.grpc.status_code", status.error_code());
+ span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code());
// Make sure to end your spans!
span->End();
return response.response();
@@ -73,7 +75,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(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), 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 6bbdfc64ba..b22ad2a6ca 100644
--- a/examples/grpc/server.cpp
+++ b/examples/grpc/server.cpp
@@ -5,6 +5,7 @@
#endif
#include "tracer_common.h"
#include "opentelemetry/trace/span_context_kv_iterable_view.h"
+#include "opentelemetry/trace/semantic_conventions.h"
#include
#include
@@ -30,6 +31,7 @@ using grpc_example::GreetResponse;
using Span = opentelemetry::trace::Span;
using SpanContext = opentelemetry::trace::SpanContext;
+using namespace opentelemetry::trace;
namespace
{
@@ -59,10 +61,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}},
+ {{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);
diff --git a/examples/http/client.cc b/examples/http/client.cc
index aa6bc86af7..77694815a1 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"}},
+ {{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);
@@ -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(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 8a9c437d60..6c1c9ce713 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,
+ {{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())},
+ {OTEL_CPP_GET_ATTR(AttrHttpClientIp), request.client}},
+ options);
auto scope = get_tracer("http_server")->WithActiveSpan(span);
diff --git a/exporters/elasticsearch/src/es_log_exporter.cc b/exporters/elasticsearch/src/es_log_exporter.cc
index c7201db907..777bfb9426 100644
--- a/exporters/elasticsearch/src/es_log_exporter.cc
+++ b/exporters/elasticsearch/src/es_log_exporter.cc
@@ -3,8 +3,11 @@
#ifdef ENABLE_LOGS_PREVIEW
+# include // std::stringstream
+
# include "opentelemetry/exporters/elasticsearch/es_log_exporter.h"
# include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
+# include "opentelemetry/sdk_config.h"
namespace nostd = opentelemetry::nostd;
namespace sdklogs = opentelemetry::sdk::logs;
@@ -74,23 +77,19 @@ class ResponseHandler : public http_client::EventHandler
switch (state)
{
case http_client::SessionState::ConnectFailed:
- if (console_debug_)
- std::cout << "Connection to elasticsearch failed\n";
+ OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Connection to elasticsearch failed");
cv_.notify_all();
break;
case http_client::SessionState::SendFailed:
- if (console_debug_)
- std::cout << "Request failed to be sent to elasticsearch\n";
+ OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Request failed to be sent to elasticsearch");
cv_.notify_all();
break;
case http_client::SessionState::TimedOut:
- if (console_debug_)
- std::cout << "Request to elasticsearch timed out\n";
+ OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Request to elasticsearch timed out");
cv_.notify_all();
break;
case http_client::SessionState::NetworkError:
- if (console_debug_)
- std::cout << "Network error to elasticsearch\n";
+ OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Network error to elasticsearch");
cv_.notify_all();
break;
}
@@ -131,11 +130,8 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
// Return failure if this exporter has been shutdown
if (is_shutdown_)
{
- if (options_.console_debug_)
- {
- std::cout << "Export failed, exporter is shutdown" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Export failed, exporter is shutdown");
return sdk::common::ExportResult::kFailure;
}
@@ -172,8 +168,9 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
// Wait for the response to be received
if (options_.console_debug_)
{
- std::cout << "waiting for response from Elasticsearch (timeout = " << options_.response_timeout_
- << " seconds)" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG(
+ "[ES Trace Exporter] waiting for response from Elasticsearch (timeout = "
+ << options_.response_timeout_ << " seconds)");
}
bool write_successful = handler->waitForResponse();
@@ -191,12 +188,9 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
std::string responseBody = handler->GetResponseBody();
if (responseBody.find("\"failed\" : 0") == std::string::npos)
{
- if (options_.console_debug_)
- {
- std::cout << "Logs were not written to Elasticsearch correctly, response body:" << std::endl;
- std::cout << responseBody << std::endl;
- }
-
+ OTEL_INTERNAL_LOG_ERROR(
+ "[ES Trace Exporter] Logs were not written to Elasticsearch correctly, response body: "
+ << responseBody);
// TODO: Retry logic
return sdk::common::ExportResult::kFailure;
}
diff --git a/exporters/jaeger/src/TUDPTransport.cc b/exporters/jaeger/src/TUDPTransport.cc
index 123ba66d96..c72881df91 100644
--- a/exporters/jaeger/src/TUDPTransport.cc
+++ b/exporters/jaeger/src/TUDPTransport.cc
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
+#include // std::stringstream
+
#include "TUDPTransport.h"
+#include "opentelemetry/sdk_config.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@@ -51,7 +54,7 @@ void TUDPTransport::open()
if (error)
{
- // TODO: log error
+ OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: getaddrinfo failed with error: " << error);
return;
}
diff --git a/exporters/jaeger/src/udp_transport.cc b/exporters/jaeger/src/udp_transport.cc
index 1470a4260f..6ae41e7b9a 100644
--- a/exporters/jaeger/src/udp_transport.cc
+++ b/exporters/jaeger/src/udp_transport.cc
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
+#include // std::stringstream
+
+#include "opentelemetry/sdk_config.h"
#include "udp_transport.h"
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -36,7 +39,7 @@ void UDPTransport::InitSocket()
int err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
- // TODO: handle error
+ OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: WSAStartup failed with error: " << error);
return;
}
diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc
index 42c0b5d300..2d522ca3cd 100644
--- a/exporters/otlp/src/otlp_grpc_exporter.cc
+++ b/exporters/otlp/src/otlp_grpc_exporter.cc
@@ -3,10 +3,11 @@
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_recordable.h"
+#include "opentelemetry/sdk_config.h"
#include
#include
-#include
+#include // std::stringstream
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@@ -112,7 +113,8 @@ sdk::common::ExportResult OtlpGrpcExporter::Export(
if (!status.ok())
{
- std::cerr << "[OTLP Exporter] Export() failed: " << status.error_message() << "\n";
+
+ OTEL_INTERNAL_LOG_ERROR("[OTLP Exporter] Export() failed: " << status.error_message());
return sdk::common::ExportResult::kFailure;
}
return sdk::common::ExportResult::kSuccess;
diff --git a/exporters/otlp/src/otlp_http_exporter.cc b/exporters/otlp/src/otlp_http_exporter.cc
index dec5268165..80cbfa40c7 100644
--- a/exporters/otlp/src/otlp_http_exporter.cc
+++ b/exporters/otlp/src/otlp_http_exporter.cc
@@ -16,11 +16,12 @@
#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h"
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
+#include "opentelemetry/sdk_config.h"
#include
#include
-#include
#include
+#include
#include
#include
@@ -66,14 +67,15 @@ class ResponseHandler : public http_client::EventHandler
if (console_debug_)
{
- std::cout << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << std::endl
- << "Header:" << std::endl;
- response.ForEachHeader([](opentelemetry::nostd::string_view header_name,
- opentelemetry::nostd::string_view header_value) {
- std::cout << "\t" << header_name.data() << " : " << header_value.data() << std::endl;
+ std::stringstream ss;
+ ss << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << "Header:";
+ response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name,
+ opentelemetry::nostd::string_view header_value) {
+ ss << "\t" << header_name.data() << " : " << header_value.data() << ",";
return true;
});
- std::cout << "Body:" << std::endl << body_ << std::endl;
+ ss << "Body:" << body_;
+ OTEL_INTERNAL_LOG_DEBUG(ss.str());
}
// Set the response_received_ flag to true and notify any threads waiting on this result
@@ -82,7 +84,7 @@ class ResponseHandler : public http_client::EventHandler
cv_.notify_all();
}
- /**
+ /**resource
* A method the user calls to block their thread until the response is received. The longest
* duration is the timeout of the request, set by SetTimeoutMs()
*/
@@ -111,114 +113,94 @@ class ResponseHandler : public http_client::EventHandler
switch (state)
{
case http_client::SessionState::CreateFailed:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: session create failed" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: session create failed");
cv_.notify_all();
break;
case http_client::SessionState::Created:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: session created" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: session created");
}
break;
case http_client::SessionState::Destroyed:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: session destroyed" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: session destroyed");
}
break;
case http_client::SessionState::Connecting:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: connecting to peer" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: connecting to peer");
}
break;
case http_client::SessionState::ConnectFailed:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: connection failed" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: connection failed");
cv_.notify_all();
break;
case http_client::SessionState::Connected:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: connected" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: connected");
}
break;
case http_client::SessionState::Sending:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: sending request" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: sending request");
}
break;
case http_client::SessionState::SendFailed:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: request send failed" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: request send failed");
cv_.notify_all();
break;
case http_client::SessionState::Response:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: response received" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: response received");
}
break;
case http_client::SessionState::SSLHandshakeFailed:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: SSL handshake failed" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: SSL handshake failed");
cv_.notify_all();
break;
case http_client::SessionState::TimedOut:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: request time out" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: request time out");
cv_.notify_all();
break;
case http_client::SessionState::NetworkError:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: network error" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: network error");
cv_.notify_all();
break;
case http_client::SessionState::ReadError:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: error reading response" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: error reading response");
}
break;
case http_client::SessionState::WriteError:
if (console_debug_)
{
- std::cerr << "[OTLP HTTP Exporter] Session state: error writing request" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG(
+ "[OTLP HTTP Exporter] DEBUG:Session state: error writing request");
}
break;
case http_client::SessionState::Cancelled:
- if (console_debug_)
- {
- std::cerr << "[OTLP HTTP Exporter] Session state: (manually) cancelled" << std::endl;
- }
+ OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: (manually) cancelled\n");
cv_.notify_all();
break;
@@ -612,16 +594,16 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
{
if (options_.console_debug)
{
- std::cout << "[OTLP HTTP Exporter] Request body(Binary):\n"
- << service_request.Utf8DebugString() << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG(
+ "[OTLP HTTP Exporter] Request body(Binary): " << service_request.Utf8DebugString());
}
}
else
{
if (options_.console_debug)
{
- std::cout << "[OTLP HTTP Exporter] Serialize body failed(Binary):"
- << service_request.InitializationErrorString() << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Serialize body failed(Binary):"
+ << service_request.InitializationErrorString());
}
return sdk::common::ExportResult::kFailure;
}
@@ -638,7 +620,7 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
json_request.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace);
if (options_.console_debug)
{
- std::cout << "[OTLP HTTP Exporter] Request body(Json):\n" << post_body_json << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Request body(Json)" << post_body_json);
}
body_vec.assign(post_body_json.begin(), post_body_json.end());
content_type = kHttpJsonContentType;
@@ -660,8 +642,9 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
// Wait for the response to be received
if (options_.console_debug)
{
- std::cout << "[OTLP HTTP Exporter] Waiting for response from " << options_.url
- << " (timeout = " << options_.timeout.count() << " milliseconds)" << std::endl;
+ OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] DEBUG: Waiting for response from "
+ << options_.url << " (timeout = " << options_.timeout.count()
+ << " milliseconds)");
}
bool write_successful = handler->waitForResponse();
diff --git a/exporters/zipkin/src/zipkin_exporter.cc b/exporters/zipkin/src/zipkin_exporter.cc
index 199a908b86..f09487becb 100644
--- a/exporters/zipkin/src/zipkin_exporter.cc
+++ b/exporters/zipkin/src/zipkin_exporter.cc
@@ -5,6 +5,7 @@
#include "opentelemetry/exporters/zipkin/recordable.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/ext/http/common/url_parser.h"
+#include "opentelemetry/sdk_config.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@@ -71,7 +72,7 @@ sdk::common::ExportResult ZipkinExporter::Export(
{
if (result.GetSessionState() == http_client::SessionState::ConnectFailed)
{
- // TODO -> Handle error / retries
+ OTEL_INTERNAL_LOG_ERROR("ZIPKIN EXPORTER] Zipkin Exporter: Connection failed");
}
return sdk::common::ExportResult::kFailure;
}
diff --git a/ext/include/opentelemetry/ext/http/client/http_client.h b/ext/include/opentelemetry/ext/http/client/http_client.h
index 4e3e9845e0..308335e492 100644
--- a/ext/include/opentelemetry/ext/http/client/http_client.h
+++ b/ext/include/opentelemetry/ext/http/client/http_client.h
@@ -183,8 +183,8 @@ class Result
{
if (response_ == nullptr)
{
- static NoopResponse res;
- return res;
+ // let's not return nullptr
+ response_.reset(new NoopResponse());
}
return *response_;
}
diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h
new file mode 100644
index 0000000000..f967111e3a
--- /dev/null
+++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h
@@ -0,0 +1,209 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+#pragma once
+
+#include
+#include
+
+#include "opentelemetry/nostd/shared_ptr.h"
+#include "opentelemetry/sdk/common/attribute_utils.h"
+#include "opentelemetry/version.h"
+
+#define OTEL_INTERNAL_LOG_LEVEL_ERROR 0
+#define OTEL_INTERNAL_LOG_LEVEL_WARN 1
+#define OTEL_INTERNAL_LOG_LEVEL_INFO 2
+#define OTEL_INTERNAL_LOG_LEVEL_DEBUG 3 // to be disabled in release
+
+#ifndef OTEL_INTERNAL_LOG_LEVEL
+# define OTEL_INTERNAL_LOG_LEVEL OTEL_INTERNAL_LOG_LEVEL_WARN // ERROR and WARN
+#endif
+
+OPENTELEMETRY_BEGIN_NAMESPACE
+namespace sdk
+{
+namespace common
+{
+namespace internal_log
+{
+
+enum class LogLevel
+{
+ Error = 0,
+ Warning,
+ Info,
+ Debug
+};
+
+inline std::string LevelToString(LogLevel level)
+{
+ switch (level)
+ {
+ case LogLevel::Error:
+ return "Error";
+ case LogLevel::Warning:
+ return "Warning";
+ case LogLevel::Info:
+ return "Info";
+ case LogLevel::Debug:
+ return "Debug";
+ }
+ return {};
+}
+
+class LogHandler
+{
+public:
+ virtual void Handle(LogLevel level,
+ const char *file,
+ int line,
+ const char *msg,
+ const sdk::common::AttributeMap &attributes) noexcept = 0;
+};
+
+class DefaultLogHandler : public LogHandler
+{
+public:
+ void Handle(LogLevel level,
+ const char *file,
+ int line,
+ const char *msg,
+ const sdk::common::AttributeMap &attributes) noexcept override
+ {
+ std::stringstream output_s;
+ output_s << "[" << LevelToString(level) << "] ";
+ if (file != nullptr)
+ {
+ output_s << "File: " << file << ":" << line;
+ }
+ if (msg != nullptr)
+ {
+ output_s << msg;
+ }
+ output_s << std::endl;
+ // TBD - print attributes
+ std::cout << output_s.str(); // thread safe.
+ }
+};
+
+class NoopLogHandler : public LogHandler
+{
+public:
+ void Handle(LogLevel level,
+ const char *file,
+ int line,
+ const char *msg,
+ const sdk::common::AttributeMap &error_attributes) noexcept override
+ {
+ // ignore the log message
+ }
+};
+
+/**
+ * Stores the singleton global LogHandler.
+ */
+class GlobalLogHandler
+{
+public:
+ /**
+ * Returns the singleton LogHandler.
+ *
+ * By default, a default LogHandler is returned. This will never return a
+ * nullptr LogHandler.
+ */
+ static nostd::shared_ptr GetLogHandler() noexcept
+ {
+ return nostd::shared_ptr(GetHandler());
+ }
+
+ /**
+ * Changes the singleton LogHandler.
+ * This should be called once at the start of application before creating TracerProvider
+ * instance.
+ */
+ static void SetLogHandler(nostd::shared_ptr eh) noexcept { GetHandler() = eh; }
+
+private:
+ static nostd::shared_ptr &GetHandler() noexcept
+ {
+ static nostd::shared_ptr handler(new DefaultLogHandler);
+ return handler;
+ }
+};
+
+} // namespace internal_log
+} // namespace common
+} // namespace sdk
+OPENTELEMETRY_END_NAMESPACE
+
+#define OTEL_INTERNAL_LOG_DISPATCH(level, message, attributes) \
+ do \
+ { \
+ using namespace opentelemetry::sdk::common::internal_log; \
+ std::stringstream tmp_stream; \
+ tmp_stream << message; \
+ GlobalLogHandler::GetLogHandler()->Handle(level, __FILE__, __LINE__, tmp_stream.str().c_str(), \
+ attributes); \
+ } while (0)
+
+#define OTEL_INTERNAL_LOG_GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
+
+#if OTEL_INTERNAL_LOG_LEVEL >= OTEL_INTERNAL_LOG_LEVEL_ERROR
+# define OTEL_INTERNAL_LOG_ERROR_1_ARGS(message) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Error, message, \
+ {})
+# define OTEL_INTERNAL_LOG_ERROR_2_ARGS(message, attributes) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Error, message, \
+ attributes)
+# define OTEL_INTERNAL_LOG_ERROR_MACRO(...) \
+ OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_ERROR_2_ARGS, \
+ OTEL_INTERNAL_LOG_ERROR_1_ARGS)
+# define OTEL_INTERNAL_LOG_ERROR(...) OTEL_INTERNAL_LOG_ERROR_MACRO(__VA_ARGS__)(__VA_ARGS__)
+#else
+# define OTEL_INTERNAL_LOG_ERROR(...)
+#endif
+
+#if OTEL_INTERNAL_LOG_LEVEL >= OTEL_INTERNAL_LOG_LEVEL_WARN
+# define OTEL_INTERNAL_LOG_WARN_1_ARGS(message) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Warn, message, \
+ {})
+# define OTEL_INTERNAL_LOG_WARN_2_ARGS(message, attributes) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Warn, message, \
+ attributes)
+# define OTEL_INTERNAL_LOG_WARN_MACRO(...) \
+ OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_WARN_2_ARGS, \
+ OTEL_INTERNAL_LOG_WARN_1_ARGS)
+# define OTEL_INTERNAL_LOG_WARN(...) OTEL_INTERNAL_LOG_WARN_MACRO(__VA_ARGS__)(__VA_ARGS__)
+#else
+# define OTEL_INTERNAL_LOG_ERROR(...)
+#endif
+
+#if OTEL_INTERNAL_LOG_LEVEL >= OTEL_INTERNAL_LOG_LEVEL_DEBUG
+# define OTEL_INTERNAL_LOG_DEBUG_1_ARGS(message) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_log::LogLevel::Debug, message, \
+ {})
+# define OTEL_INTERNAL_LOG_DEBUG_2_ARGS(message, attributes) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_logg::LogLevel::Debug, \
+ message, attributes)
+# define OTEL_INTERNAL_LOG_DEBUG_MACRO(...) \
+ OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_DEBUG_2_ARGS, \
+ OTEL_INTERNAL_LOG_DEBUG_1_ARGS)
+# define OTEL_INTERNAL_LOG_DEBUG(...) OTEL_INTERNAL_LOG_DEBUG_MACRO(__VA_ARGS__)(__VA_ARGS__)
+#else
+# define OTEL_INTERNAL_LOG_DEBUG(...)
+#endif
+
+#if OTEL_INTERNAL_LOG_LEVEL >= OTEL_INTERNAL_LOG_LEVEL_INFO
+# define OTEL_INTERNAL_LOG_INFO_1_ARGS(message) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_logger::LogLevel::Info, \
+ message, {})
+# define OTEL_INTERNAL_LOG_INFO_2_ARGS(message, attributes) \
+ OTEL_INTERNAL_LOG_DISPATCH(opentelemetry::sdk::common::internal_logger::LogLevel::Info, \
+ message, attributes)
+# define OTEL_INTERNAL_LOG_INFO_MACRO(...) \
+ OTEL_INTERNAL_LOG_GET_3RD_ARG(__VA_ARGS__, OTEL_INTERNAL_LOG_ERROR_2_ARGS, \
+ OTEL_INTERNAL_LOG_ERROR_1_ARGS)
+# define OTEL_INTERNAL_LOG_INFO(...) OTEL_INTERNAL_LOG_INFO_MACRO(__VA_ARGS__)(__VA_ARGS__)
+#else
+# define OTEL_INTERNAL_LOG_INFO(...)
+#endif
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
diff --git a/sdk/include/opentelemetry/sdk_config.h b/sdk/include/opentelemetry/sdk_config.h
new file mode 100644
index 0000000000..8ac72a10d5
--- /dev/null
+++ b/sdk/include/opentelemetry/sdk_config.h
@@ -0,0 +1,7 @@
+// Copyright The OpenTelemetry Authors
+// SPDX-License-Identifier: Apache-2.0
+
+#pragma once
+
+#include "opentelemetry/config.h"
+#include "opentelemetry/sdk/common/global_log_handler.h"
\ No newline at end of file
diff --git a/sdk/src/common/global_log_handler.cc b/sdk/src/common/global_log_handler.cc
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/sdk/src/logs/logger.cc b/sdk/src/logs/logger.cc
index 970f61b7e9..fe61dd4ce8 100644
--- a/sdk/src/logs/logger.cc
+++ b/sdk/src/logs/logger.cc
@@ -4,6 +4,7 @@
#ifdef ENABLE_LOGS_PREVIEW
# include "opentelemetry/sdk/logs/logger.h"
# include "opentelemetry/sdk/logs/log_record.h"
+# include "opentelemetry/sdk_config.h"
# include "opentelemetry/trace/provider.h"
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -48,7 +49,7 @@ void Logger::Log(opentelemetry::logs::Severity severity,
auto recordable = processor->MakeRecordable();
if (recordable == nullptr)
{
- // TODO: Error diagnostics should indicate "recordable creation failed" to user
+ OTEL_INTERNAL_LOG_ERROR("[LOGGER] Recordable creation failed");
return;
}
diff --git a/sdk/src/trace/tracer_provider.cc b/sdk/src/trace/tracer_provider.cc
index ed6853be67..911e66c2f0 100644
--- a/sdk/src/trace/tracer_provider.cc
+++ b/sdk/src/trace/tracer_provider.cc
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
#include "opentelemetry/sdk/trace/tracer_provider.h"
+#include "opentelemetry/sdk_config.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
@@ -40,9 +41,10 @@ nostd::shared_ptr TracerProvider::GetTracer(
{
library_name = "";
}
- // if (library_name == "") {
- // // TODO: log invalid library_name.
- // }
+ if (library_name == "")
+ {
+ OTEL_INTERNAL_LOG_ERROR("[TracerProvider::GetTracer] Library name is empty.");
+ }
const std::lock_guard guard(lock_);