Skip to content

Commit

Permalink
[SEMANTIC CONVENTIONS] Upgrade to semantic convention 1.25.0 (#2633)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Apr 16, 2024
1 parent 78947b2 commit 8f15440
Show file tree
Hide file tree
Showing 11 changed files with 2,018 additions and 1,681 deletions.
2,634 changes: 1,932 additions & 702 deletions api/include/opentelemetry/trace/semantic_conventions.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions buildscripts/semantic-convention/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ ROOT_DIR="${SCRIPT_DIR}/../../"
# https://github.com/open-telemetry/opentelemetry-specification
# Repository from 1.21.0:
# https://github.com/open-telemetry/semantic-conventions
SEMCONV_VERSION=1.24.0
SEMCONV_VERSION=1.25.0

# repository: https://github.com/open-telemetry/build-tools
GENERATOR_VERSION=0.23.0
GENERATOR_VERSION=0.24.0

SPEC_VERSION=v$SEMCONV_VERSION
SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION
Expand Down
16 changes: 9 additions & 7 deletions examples/grpc/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class GreeterClient
std::string span_name = "GreeterClient/Greet";
auto span = get_tracer("grpc")->StartSpan(
span_name,
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "grpc-example.GreetService"},
{SemanticConventions::kRpcMethod, "Greet"},
{SemanticConventions::kNetworkPeerAddress, ip},
{SemanticConventions::kNetworkPeerPort, port}},
{{opentelemetry::trace::SemanticConventions::kRpcSystem, "grpc"},
{opentelemetry::trace::SemanticConventions::kRpcService, "grpc-example.GreetService"},
{opentelemetry::trace::SemanticConventions::kRpcMethod, "Greet"},
{opentelemetry::trace::SemanticConventions::kNetworkPeerAddress, ip},
{opentelemetry::trace::SemanticConventions::kNetworkPeerPort, port}},
options);

auto scope = get_tracer("grpc-client")->WithActiveSpan(span);
Expand All @@ -70,7 +70,8 @@ class GreeterClient
if (status.ok())
{
span->SetStatus(StatusCode::kOk);
span->SetAttribute(SemanticConventions::kRpcGrpcStatusCode, status.error_code());
span->SetAttribute(opentelemetry::trace::SemanticConventions::kRpcGrpcStatusCode,
status.error_code());
// Make sure to end your spans!
span->End();
return response.response();
Expand All @@ -79,7 +80,8 @@ class GreeterClient
{
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
span->SetStatus(StatusCode::kError);
span->SetAttribute(SemanticConventions::kRpcGrpcStatusCode, status.error_code());
span->SetAttribute(opentelemetry::trace::SemanticConventions::kRpcGrpcStatusCode,
status.error_code());
// Make sure to end your spans!
span->End();
return "RPC failed";
Expand Down
15 changes: 8 additions & 7 deletions examples/grpc/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ class GreeterServer final : public Greeter::Service
options.parent = GetSpan(new_context)->GetContext();

std::string span_name = "GreeterService/Greet";
auto span = get_tracer("grpc")->StartSpan(span_name,
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "GreeterService"},
{SemanticConventions::kRpcMethod, "Greet"},
{SemanticConventions::kRpcGrpcStatusCode, 0}},
options);
auto scope = get_tracer("grpc")->WithActiveSpan(span);
auto span = get_tracer("grpc")->StartSpan(
span_name,
{{opentelemetry::trace::SemanticConventions::kRpcSystem, "grpc"},
{opentelemetry::trace::SemanticConventions::kRpcService, "GreeterService"},
{opentelemetry::trace::SemanticConventions::kRpcMethod, "Greet"},
{opentelemetry::trace::SemanticConventions::kRpcGrpcStatusCode, 0}},
options);
auto scope = get_tracer("grpc")->WithActiveSpan(span);

// Fetch and parse whatever HTTP headers we can from the gRPC request.
span->AddEvent("Processing client attributes");
Expand Down
16 changes: 9 additions & 7 deletions examples/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ void sendRequest(const std::string &url)
opentelemetry::ext::http::common::UrlParser url_parser(url);

std::string span_name = url_parser.path_;
auto span = get_tracer("http-client")
->StartSpan(span_name,
{{SemanticConventions::kUrlFull, url_parser.url_},
{SemanticConventions::kUrlScheme, url_parser.scheme_},
{SemanticConventions::kHttpRequestMethod, "GET"}},
options);
auto span =
get_tracer("http-client")
->StartSpan(span_name,
{{opentelemetry::trace::SemanticConventions::kUrlFull, url_parser.url_},
{opentelemetry::trace::SemanticConventions::kUrlScheme, url_parser.scheme_},
{opentelemetry::trace::SemanticConventions::kHttpRequestMethod, "GET"}},
options);
auto scope = get_tracer("http-client")->WithActiveSpan(span);

// inject current context into http header
Expand All @@ -44,7 +45,8 @@ void sendRequest(const std::string &url)
{
// set span attributes
auto status_code = result.GetResponse().GetStatusCode();
span->SetAttribute(SemanticConventions::kHttpResponseStatusCode, status_code);
span->SetAttribute(opentelemetry::trace::SemanticConventions::kHttpResponseStatusCode,
status_code);
result.GetResponse().ForEachHeader(
[&span](nostd::string_view header_name, nostd::string_view header_value) {
span->SetAttribute("http.header." + std::string(header_name.data()), header_value);
Expand Down
22 changes: 12 additions & 10 deletions examples/http/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback
options.parent = GetSpan(new_context)->GetContext();

// start span with parent context extracted from http header
auto span = get_tracer("http-server")
->StartSpan(span_name,
{{SemanticConventions::kServerAddress, server_name},
{SemanticConventions::kServerPort, server_port},
{SemanticConventions::kHttpRequestMethod, request.method},
{SemanticConventions::kUrlScheme, "http"},
{SemanticConventions::kHttpRequestBodySize,
static_cast<uint64_t>(request.content.length())},
{SemanticConventions::kClientAddress, request.client}},
options);
auto span =
get_tracer("http-server")
->StartSpan(
span_name,
{{opentelemetry::trace::SemanticConventions::kServerAddress, server_name},
{opentelemetry::trace::SemanticConventions::kServerPort, server_port},
{opentelemetry::trace::SemanticConventions::kHttpRequestMethod, request.method},
{opentelemetry::trace::SemanticConventions::kUrlScheme, "http"},
{opentelemetry::trace::SemanticConventions::kHttpRequestBodySize,
static_cast<uint64_t>(request.content.length())},
{opentelemetry::trace::SemanticConventions::kClientAddress, request.client}},
options);

auto scope = get_tracer("http_server")->WithActiveSpan(span);

Expand Down
5 changes: 3 additions & 2 deletions exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "opentelemetry/exporters/zipkin/recordable.h"
#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/sdk/resource/semantic_conventions.h"
#include "opentelemetry/trace/semantic_conventions.h"

#include <map>
#include <string>
Expand Down Expand Up @@ -223,9 +224,9 @@ void Recordable::SetResource(const sdk::resource::Resource &resource) noexcept
{
// only service.name attribute is supported by specs as of now.
auto attributes = resource.GetAttributes();
if (attributes.find(SemanticConventions::kServiceName) != attributes.end())
if (attributes.find(trace::SemanticConventions::kServiceName) != attributes.end())
{
service_name_ = nostd::get<std::string>(attributes[SemanticConventions::kServiceName]);
service_name_ = nostd::get<std::string>(attributes[trace::SemanticConventions::kServiceName]);
}
}

Expand Down
Loading

2 comments on commit 8f15440

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 8f15440 Previous: 78947b2 Ratio
BM_BaselineBuffer/1 15605113.506317139 ns/iter 5860335.826873779 ns/iter 2.66
BM_LockFreeBuffer/2 7070196.140634945 ns/iter 3028505.17308768 ns/iter 2.33

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 8f15440 Previous: 78947b2 Ratio
BM_NaiveSpinLockThrashing/2/process_time/real_time 0.7948622559056138 ms/iter 0.27125069835801113 ms/iter 2.93
BM_SpanIdDefaultConstructor 0.6828101652312323 ns/iter 0.31018762050526383 ns/iter 2.20
BM_SpanIdConstructor 0.7276901399543957 ns/iter 0.3103634645295908 ns/iter 2.34
BM_SpanIdIsValid 1.4025256350319228 ns/iter 0.6193511366303445 ns/iter 2.26

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.