Skip to content

Commit

Permalink
Added Log overloads, GetName() method, fixed LogRecord attributes and…
Browse files Browse the repository at this point in the history
… resources
  • Loading branch information
MarkSeufert authored and Karen Xu committed Dec 4, 2020
1 parent daab565 commit 77fd8a4
Show file tree
Hide file tree
Showing 11 changed files with 427 additions and 97 deletions.
24 changes: 11 additions & 13 deletions api/include/opentelemetry/logs/log_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ enum class Severity : uint8_t
kDefault = kInfo // default severity is set to kInfo level, similar to what is done in ILogger
};

/* _nullKV is defined as a private variable that allows "resource" and
"attributes" fields to be instantiated using it as the default value */
static common::KeyValueIterableView<std::map<nostd::string_view, nostd::string_view>> _nullKV =
common::KeyValueIterableView<std::map<nostd::string_view, nostd::string_view>>{{}};

/**
* A default Event object to be passed in log statements,
* matching the 10 fields of the Log Data Model.
Expand All @@ -82,25 +77,28 @@ struct LogRecord
core::SystemTimestamp timestamp; // uint64 nanoseconds since Unix epoch
trace::TraceId trace_id; // byte sequence
trace::SpanId span_id; // byte sequence
trace::TraceFlags trace_flag; // byte
Severity severity; // Severity enum that combines severity_text and severity_number in the
// LogDataModel (can separate in SDK)
trace::TraceFlags trace_flags; // byte
Severity severity; // Severity enum that combines severity_text and severity_number

// other fields that will not be set by default
nostd::string_view name; // string
nostd::string_view body; // currently a simple string, but should be changed "Any" type
common::KeyValueIterable &resource; // key/value pair list
common::KeyValueIterable &attributes; // key/value pair list
nostd::shared_ptr<common::KeyValueIterable> resource; // key/value pair list
nostd::shared_ptr<common::KeyValueIterable> attributes; // key/value pair list

/* Default log record if user does not overwrite this.
* TODO: find better data type to represent the <Any> type for "body"
* Future enhancement: Potentially add other constructors to take default arguments
* from the user
**/
LogRecord() : resource(_nullKV), attributes(_nullKV)
LogRecord()
{
// TODO: in SDK, assign a default timestamp if not specified
name = "";
// Assign default values
timestamp = core::SystemTimestamp(std::chrono::seconds(0));
severity = Severity::kDefault;
trace_id = trace::TraceId();
span_id = trace::SpanId();
trace_flags = trace::TraceFlags();
}

/* for ease of use; user can use this function to convert a map into a KeyValueIterable for the
Expand Down
Loading

0 comments on commit 77fd8a4

Please sign in to comment.