Skip to content

Commit

Permalink
Add Tags and Fields enums.
Browse files Browse the repository at this point in the history
This changeset adds the tags and fields enums as they are
currently represented in the java implementation.

Completes #7
  • Loading branch information
daschl committed Feb 20, 2018
1 parent d745d6a commit 316e768
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
32 changes: 32 additions & 0 deletions opentracing-api/src/field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// The following log fields are recommended for instrumentors who are trying to capture more
/// information about a logged event. Tracers may expose additional features based on these
/// standardized data points.
pub enum Fields {
/// The type or "kind" of an error (only for event="error" logs). E.g., "Exception", "OSError".
ErrorKind,
/// The actual Throwable/Exception/Error object instance itself.
ErrorObject,
/// A stable identifier for some notable moment in the lifetime of a Span. For instance, a mutex
/// lock acquisition or release or the sorts of lifetime events in a browser page load described
/// in the Performance.timing specification. E.g., from Zipkin, "cs", "sr", "ss", or "cr". Or,
/// more generally, "initialized" or "timed out". For errors, "error".
Event,
/// A concise, human-readable, one-line message explaining the event. E.g., "Could not connect
/// to backend", "Cache invalidation succeeded".
Message,
/// A stack trace in platform-conventional format; may or may not pertain to an error.
Stack,
}

impl Fields {
/// Returns the string representation for the enum reference variant.
pub fn as_str(&self) -> &'static str {
match *self {
Fields::ErrorKind => "error.kind",
Fields::ErrorObject => "error.object",
Fields::Event => "event",
Fields::Message => "message",
Fields::Stack => "stack",
}
}
}
8 changes: 7 additions & 1 deletion opentracing-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#![doc(html_root_url = "https://docs.rs/opentracing-api/0.1.0")]
#![doc(html_root_url = "https://docs.rs/opentracing-api/0.1.0")]

mod tag;
mod field;

pub use tag::Tags;
pub use field::Fields;
83 changes: 83 additions & 0 deletions opentracing-api/src/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/// The following span tags are recommended for instrumentors who are trying to capture more
/// semantic information about the spans. Tracers may expose additional features based on these
/// standardized data points. Tag names follow a general structure of namespacing.
///
/// See also [Semantic Conventions](https://github.com/opentracing/specification/blob/master/semantic_conventions.md)
pub enum Tags {
/// A constant for setting the span kind to indicate that it represents a client span.
SpanKindClient,
/// A constant for setting the span kind to indicate that it represents a server span.
SpanKindServer,
/// A constant for setting the span kind to indicate that it represents a producer span,
/// in a messaging scenario.
SpanKindProducer,
/// A constant for setting the span kind to indicate that it represents a consumer span,
/// in a messaging scenario.
SpanKindConsumer,
/// HTTP_URL records the url of the incoming request.
HttpUrl,
/// HTTP_STATUS records the http status code of the response.
HttpStatus,
/// HTTP_METHOD records the http method. Case-insensitive.
HttpMethod,
/// PEER_HOST_IPV4 records IPv4 host address of the peer.
PeerHostIpv4,
/// PEER_HOST_IPV6 records the IPv6 host address of the peer.
PeerHostIpv6,
/// PEER_SERVICE records the service name of the peer.
PeerService,
/// PEER_HOSTNAME records the host name of the peer.
PeerHostname,
/// PEER_PORT records the port number of the peer.
PeerPort,
/// SAMPLING_PRIORITY determines the priority of sampling this Span.
SamplingPriority,
/// SPAN_KIND hints at the relationship between spans, e.g. client/server.
SpanKind,
/// COMPONENT is a low-cardinality identifier of the module, library, or
/// package that is instrumented.
Component,
/// ERROR indicates whether a Span ended in an error state.
Error,
/// DB_TYPE indicates the type of Database.
DbType,
/// DB_INSTANCE indicates the instance name of Database.
DbInstance,
/// DB_USER indicates the user name of Database, e.g. "readonly_user" or
/// "reporting_user"
DbUser,
/// DB_STATEMENT records a database statement for the given database type.
DbStatement,
/// MESSAGE_BUS_DESTINATION records an address at which messages can be
/// exchanged.
MessageBusDestination,
}

impl Tags {
/// Returns the string representation for the enum reference variant.
pub fn as_str(&self) -> &'static str {
match *self {
Tags::SpanKindClient => "client",
Tags::SpanKindServer => "server",
Tags::SpanKindProducer => "producer",
Tags::SpanKindConsumer => "consumer",
Tags::HttpUrl => "http.url",
Tags::HttpStatus => "http.status_code",
Tags::HttpMethod => "http.method",
Tags::PeerHostIpv4 => "peer.ipv4",
Tags::PeerHostIpv6 => "peer.ipv6",
Tags::PeerService => "peer.service",
Tags::PeerHostname => "peer.hostname",
Tags::PeerPort => "peer.port",
Tags::SamplingPriority => "sampling.priority",
Tags::SpanKind => "span.kind",
Tags::Component => "component",
Tags::Error => "error",
Tags::DbType => "db.type",
Tags::DbInstance => "db.instance",
Tags::DbUser => "db.user",
Tags::DbStatement => "db.statement",
Tags::MessageBusDestination => "message_bus.destination",
}
}
}

0 comments on commit 316e768

Please sign in to comment.