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

Add span events #833

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from

Conversation

nepridumalnik
Copy link
Contributor

Add span events to opentelemetry

@nepridumalnik nepridumalnik requested a review from segoon as a code owner January 16, 2025 11:05
core/include/userver/tracing/span.hpp Outdated Show resolved Hide resolved

for (const auto& [key, value] : events.attributes) {
builder.Key(key);
EventAttributeWriteVisitor write_visitor(builder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use only one visitor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One visitor converts to JSON, and the other to a Span Event. A template visitor would still need to write two different functions, so I decided that this way there would be less code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed them to avoid confusion

core/src/tracing/span.cpp Outdated Show resolved Hide resolved
core/src/tracing/span.cpp Show resolved Hide resolved
otlp/src/otlp/logs/logger.cpp Outdated Show resolved Hide resolved
otlp/src/otlp/logs/logger.cpp Show resolved Hide resolved
otlp/src/otlp/logs/logger.cpp Outdated Show resolved Hide resolved
otlp/src/otlp/logs/logger.cpp Outdated Show resolved Hide resolved
@nepridumalnik nepridumalnik requested a review from fdr400 January 20, 2025 08:44

for (const auto& item : json_value) {
tracing::Span::Event event{item.As<tracing::Span::Event>()};
GetAttributes(item, event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse attributes in Parse function
after that, you do just json_value.As<std::vector<tracing::Span::Event>>() (probably, use should include proper header for containers parsing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see
Fixed


for (const auto& [key, value] : events.attributes) {
builder.Key(key);
std::visit(AttributeToJsonVisitor{builder}, value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i implied that maybe you can create only one visitor object and reuse it in this loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nepridumalnik nepridumalnik requested a review from fdr400 January 20, 2025 08:55

const auto logs_raw = GetStreamString();

EXPECT_THAT(logs_raw, HasSubstr("events=[{\"name\":\"important_event\""));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно использовать R" чтобы не эскейпить все подряд

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил использование

@@ -176,12 +273,17 @@ void Logger::Trace(logging::Level level, std::string_view msg) {
if (key == "timestamp" || key == "text") {
return true;
}
if (key == "events") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это место скоро поменяется, у меня уже есть патч на добавление JSON логов
подожди, пока он приземлится, и тогда нужно будет поменять это место

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ок

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants