Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Add constants for predefined tags. #67

Merged
merged 1 commit into from
Mar 20, 2018
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
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cc_library(
name = "opentracing",
srcs = glob(["src/*.cpp"], exclude=["src/dynamic_load_unsupported.cpp"]),
hdrs = glob(["include/opentracing/*.h"]) + [
srcs = glob(["src/**/*.cpp"], exclude=["src/dynamic_load_unsupported.cpp"]),
hdrs = glob(["include/opentracing/**/*.h"]) + [
":include/opentracing/config.h",
":include/opentracing/version.h",
],
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ set(SRCS src/propagation.cpp
src/dynamic_load.cpp
src/noop.cpp
src/tracer.cpp
src/tracer_factory.cpp)
src/tracer_factory.cpp
src/ext/tags.cpp)

if (BUILD_DYNAMIC_LOADING)
list(APPEND SRCS src/dynamic_load_unix.cpp)
Expand Down
121 changes: 121 additions & 0 deletions include/opentracing/ext/tags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#ifndef OPENTRACING_EXT_TAGS_H
#define OPENTRACING_EXT_TAGS_H

#include <opentracing/string_view.h>
#include <opentracing/version.h>

namespace opentracing {
BEGIN_OPENTRACING_ABI_NAMESPACE
namespace ext {
// The following tags are described in greater detail at the following url:
// https://github.com/opentracing/specification/blob/master/semantic_conventions.md
//
// Here we define standard names for tags that can be added to spans by the
// instrumentation code. The actual tracing systems are not required to
// retain these as tags in the stored spans if they have other means of
// representing the same data. For example, the SPAN_KIND='server' can be
// inferred from a Zipkin span by the presence of ss/sr annotations.

// ---------------------------------------------------------------------------
// span_kind hints at relationship between spans, e.g. client/server
// ---------------------------------------------------------------------------
extern const opentracing::string_view span_kind;

// Marks a span representing the client-side of an RPC or other remote call
extern const opentracing::string_view span_kind_rpc_client;

// Marks a span representing the server-side of an RPC or other remote call
extern const opentracing::string_view span_kind_rpc_server;

// ---------------------------------------------------------------------------
// error indicates whether a Span ended in an error state.
// ---------------------------------------------------------------------------
extern const opentracing::string_view error;

// ---------------------------------------------------------------------------
// component (string) ia s low-cardinality identifier of the module, library,
// or package that is generating a span.
// ---------------------------------------------------------------------------
extern const opentracing::string_view component;

// ---------------------------------------------------------------------------
// sampling_priority (uint16) determines the priority of sampling this Span.
// ---------------------------------------------------------------------------
extern const opentracing::string_view sampling_priority;

// ---------------------------------------------------------------------------
// peer_* tags can be emitted by either client-side of server-side to describe
// the other side/service in a peer-to-peer communications, like an RPC call.
// ---------------------------------------------------------------------------
// peer_service (string) records the service name of the peer
extern const opentracing::string_view peer_service;

// peer_hostname (string) records the host name of the peer
extern const opentracing::string_view peer_hostname;

// peer_address (string) suitable for use in a networking client library.
// This may be a "ip:port", a bare "hostname", a FQDN, or even a
// JDBC substring like "mysql://prod-db:3306"
extern const opentracing::string_view peer_address;

// peer_host_ipv4 (uint32) records IP v4 host address of the peer
extern const opentracing::string_view peer_host_ipv4;

// peer_host_ipv6 (string) records IP v6 host address of the peer
extern const opentracing::string_view peer_host_ipv6;

// peer_port (uint16) records port number of the peer
extern const opentracing::string_view peer_port;

// ---------------------------------------------------------------------------
// HTTP tags
// ---------------------------------------------------------------------------

// http_url (string) should be the URL of the request being handled in this
// segment of the trace, in standard URI format. The protocol is optional.
extern const opentracing::string_view http_url;

// http_method (string) is the HTTP method of the request.
// Both upper/lower case values are allowed.
extern const opentracing::string_view http_method;

// http_status_code (int) is the numeric HTTP status code (200, 404, etc)
// of the HTTP response.
extern const opentracing::string_view http_status_code;

// ---------------------------------------------------------------------------
// DATABASE tags
// ---------------------------------------------------------------------------

// database_instance (string) The database instance name. E.g., In java, if
// the jdbc.url="jdbc:mysql://127.0.0.1:3306/customers", the instance
// name is "customers"
extern const opentracing::string_view database_instance;

// database_statement (string) A database statement for the given database
// type. E.g., for db.type="SQL", "SELECT * FROM user_table";
// for db.type="redis", "SET mykey 'WuValue'".
extern const opentracing::string_view database_statement;

// database_type (string) For any SQL database, "sql". For others,
// the lower-case database category, e.g. "cassandra", "hbase", or "redis".
extern const opentracing::string_view database_type;

// database_user (string) Username for accessing database. E.g.,
// "readonly_user" or "reporting_user"
extern const opentracing::string_view database_user;

// ---------------------------------------------------------------------------
// message_bus tags
// ---------------------------------------------------------------------------

// message_bus_destination (string) An address at which messages can be
// exchanged. E.g. A Kafka record has an associated "topic name" that can
// be extracted by the instrumented producer or consumer and stored
// using this tag.
extern const opentracing::string_view message_bus_destination;
} // namespace ext
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing

#endif // OPENTRACING_EXT_TAGS_H
1 change: 1 addition & 0 deletions include/opentracing/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Value : public variant_type {

Value(const std::string& s) : variant_type(s) {}
Value(std::string&& s) : variant_type(std::move(s)) {}
Value(opentracing::string_view s) : variant_type(std::string{s}) {}

Value(const Values& values) : variant_type(values) {}
Value(Values&& values) : variant_type(std::move(values)) {}
Expand Down
37 changes: 37 additions & 0 deletions src/ext/tags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <opentracing/ext/tags.h>

namespace opentracing {
BEGIN_OPENTRACING_ABI_NAMESPACE
namespace ext {
const opentracing::string_view span_kind = "span.kind";
const opentracing::string_view span_kind_rpc_client = "client";
const opentracing::string_view span_kind_rpc_server = "server";

const opentracing::string_view error = "error";

const opentracing::string_view component = "component";

const opentracing::string_view sampling_priority = "sampling.priority";

const opentracing::string_view peer_service = "peer.service";

extern const opentracing::string_view peer_hostname = "peer.hostname";
extern const opentracing::string_view peer_address = "peer.address";
extern const opentracing::string_view peer_host_ipv4 = "peer.ipv4";
extern const opentracing::string_view peer_host_ipv6 = "peer.ipv6";
extern const opentracing::string_view peer_port = "peer.port";

extern const opentracing::string_view http_url = "http.url";
extern const opentracing::string_view http_method = "http.method";
extern const opentracing::string_view http_status_code = "http.status_code";

extern const opentracing::string_view database_instance = "db.instance";
extern const opentracing::string_view database_statement = "db.statement";
extern const opentracing::string_view database_type = "db.type";
extern const opentracing::string_view database_user = "db.user";

extern const opentracing::string_view message_bus_destination =
"message_bus.destination";
} // namespace ext
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing
3 changes: 3 additions & 0 deletions test/tracer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <opentracing/ext/tags.h>
#include <opentracing/noop.h>
#include <opentracing/tracer.h>
using namespace opentracing;
Expand All @@ -20,6 +21,8 @@ TEST_CASE("tracer") {
CHECK(span2);
span2->SetOperationName("b1");
span2->SetTag("x", true);
span2->SetTag(opentracing::ext::span_kind,
opentracing::ext::span_kind_rpc_client);
CHECK(span2->BaggageItem("y").empty());
span2->Log({{"event", "xyz"}, {"abc", 123}});
span2->Finish();
Expand Down