Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEMANTIC CONVENTIONS] Upgrade to semantic convention 1.25.0 (#2633) #26

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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