Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Apr 18, 2024
2 parents 5563a7c + 7aea1a6 commit 24af331
Show file tree
Hide file tree
Showing 10 changed files with 3,700 additions and 65 deletions.
2 changes: 1 addition & 1 deletion buildscripts/semantic-convention/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ docker run --rm \
-v ${SCRIPT_DIR}/templates:/templates${USE_MOUNT_OPTION} \
-v ${ROOT_DIR}/sdk/include/opentelemetry/sdk/resource/:/output${USE_MOUNT_OPTION} \
otel/semconvgen:$GENERATOR_VERSION \
--only resource \
--only resource,attribute_group \
-f /source code \
--template /templates/SemanticAttributes.h.j2 \
--output /output/semantic_conventions.h \
Expand Down
16 changes: 7 additions & 9 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,
{{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}},
{{SemanticConventions::kRpcSystem, "grpc"},
{SemanticConventions::kRpcService, "grpc-example.GreetService"},
{SemanticConventions::kRpcMethod, "Greet"},
{SemanticConventions::kNetworkPeerAddress, ip},
{SemanticConventions::kNetworkPeerPort, port}},
options);

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

// Fetch and parse whatever HTTP headers we can from the gRPC request.
span->AddEvent("Processing client attributes");
Expand Down
16 changes: 7 additions & 9 deletions examples/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ 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,
{{opentelemetry::trace::SemanticConventions::kUrlFull, url_parser.url_},
{opentelemetry::trace::SemanticConventions::kUrlScheme, url_parser.scheme_},
{opentelemetry::trace::SemanticConventions::kHttpRequestMethod, "GET"}},
options);
auto span = get_tracer("http-client")
->StartSpan(span_name,
{{SemanticConventions::kUrlFull, url_parser.url_},
{SemanticConventions::kUrlScheme, url_parser.scheme_},
{SemanticConventions::kHttpRequestMethod, "GET"}},
options);
auto scope = get_tracer("http-client")->WithActiveSpan(span);

// inject current context into http header
Expand All @@ -45,8 +44,7 @@ void sendRequest(const std::string &url)
{
// set span attributes
auto status_code = result.GetResponse().GetStatusCode();
span->SetAttribute(opentelemetry::trace::SemanticConventions::kHttpResponseStatusCode,
status_code);
span->SetAttribute(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: 10 additions & 12 deletions examples/http/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ 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,
{{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 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 scope = get_tracer("http_server")->WithActiveSpan(span);

Expand Down
5 changes: 2 additions & 3 deletions exporters/zipkin/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#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 @@ -224,9 +223,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(trace::SemanticConventions::kServiceName) != attributes.end())
if (attributes.find(SemanticConventions::kServiceName) != attributes.end())
{
service_name_ = nostd::get<std::string>(attributes[trace::SemanticConventions::kServiceName]);
service_name_ = nostd::get<std::string>(attributes[SemanticConventions::kServiceName]);
}
}

Expand Down
Loading

0 comments on commit 24af331

Please sign in to comment.