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

Moving LogRecord implementation to SDK #1702

Merged
merged 23 commits into from
May 8, 2024

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented May 2, 2024

Fixes #1189

Changes

Opening as draft to get the initial feedback. The changes are:

  • Created LogRecord traits in the API.
  • Added corresponding struct LogRecord with implementation in the SDK.

Earlier:

        logger.emit(
            LogRecord::builder()
                .with_body("full log")
                .with_timestamp(now)
                .with_observed_timestamp(now)
                .with_severity_number(Severity::Warn)
                .with_severity_text(Severity::Warn.name())
                .with_attribute("name", "my-event-name")
                .with_attribute("event.id", 20)
                .with_attribute("user.name", "otel")
                .with_attribute("user.email", "otel@opentelemetry.io")
                .with_attribute("code.filename", "log.rs")
                .with_attribute("code.filepath", "opentelemetry_sdk/benches/log.rs")
                .with_attribute("code.lineno", 96)
                .with_attribute("code.namespace", "opentelemetry_sdk::benches::log")
                .with_attribute("log.target", "opentelemetry_sdk::benches::log")
                .build(),
        )

With PR:

        let mut log_record = logger.create_log_record();
        log_record.set_body("full log".into());
        log_record.set_timestamp(now);
        log_record.set_observed_timestamp(now);
        log_record.set_severity_number(Severity::Warn);
        log_record.set_severity_text(Severity::Warn.name().into());
        log_record.add_attribute("name", "my-event-name");
        log_record.add_attribute("event.id", 20);
        log_record.add_attribute("user.name", "otel");
        log_record.add_attribute("user.email", "otel@opentelemetry.io");
        log_record.add_attribute("code.filename", "log.rs");
        log_record.add_attribute("code.filepath", "opentelemetry_sdk/benches/log.rs");
        log_record.add_attribute("code.lineno", 96);
        log_record.add_attribute("code.namespace", "opentelemetry_sdk::benches::log");
        log_record.add_attribute("log.target", "opentelemetry_sdk::benches::log");
        logger.emit(log_record);

Note - with the new design, the log record creation through chaining required cloning eventually while emitting, so haven't implemented the chaining. The tracing appender also doesn't require chaining as all these log data are populated separately.

This allows us to change the internal SDK implementation for LogRecord without breaking the Bridge API. While there are no current perf benefits with the approach, it enables us to add more optimizations in the SDK to optionally allow the serialization of the log records in the export format without any intermediate allocations within the SDK. I plan to add those optimizations in subsequent PRs once this is finalized.

Benchmark

Test Name Main PR
simple-log/no-context [105.28 ns] [89.896 ns]
simple-log/with-context time [115.49 ns] [90.293 ns]
simple-log-with-int/no-context [141.40 ns] [123.36 ns]
simple-log-with-int/with-context [147.15 ns] [123.61 ns]
simple-log-with-double/no-context [145.43 ns] [123.32 ns]
simple-log-with-double/with-context [153.33 ns] [122.28 ns]
simple-log-with-string/no-context [144.01 ns] [122.61 ns]
simple-log-with-string/with-context [149.85 ns] [123.61 ns]
simple-log-with-bool/no-context [146.57 ns] [121.77 ns]
simple-log-with-bool/with-context [152.56 ns] [123.12 ns]
simple-log-with-bytes/no-context [161.11 ns] [139.43 ns]
simple-log-with-bytes/with-context [171.69 ns] [140.73 ns]
simple-log-with-a-lot-of-bytes/no-context [164.77 ns] [140.72 ns]
simple-log-with-a-lot-of-bytes/with-context [172.50 ns] [142.45 ns]
simple-log-with-vec-any-value/no-context [205.88 ns] [194.93 ns]
simple-log-with-vec-any-value/with-context [214.82 ns] [194.06 ns]
simple-log-with-inner-vec-any-value/no-context [275.55 ns] [256.61 ns]
simple-log-with-inner-vec-any-value/with-context [280.79 ns] [255.82 ns]
simple-log-with-map-any-value/no-context [234.09 ns] [207.90 ns]
simple-log-with-map-any-value/with-context [244.29 ns] [207.57 ns]
simple-log-with-inner-map-any-value/no-context [335.55 ns] [303.23 ns]
simple-log-with-inner-map-any-value/with-context [344.18 ns] [304.65 ns]
long-log/no-context [106.17 ns] [89.779 ns]
long-log/with-context [118.93 ns] [91.673 ns]
full-log/no-context [143.31 ns] [95.529 ns]
full-log/with-context [145.20 ns] [96.720 ns]
full-log-with-4-attributes/no-context [315.31 ns] [227.49 ns]
full-log-with-4-attributes/with-context [312.81 ns] [235.11 ns]
full-log-with-9-attributes/no-context [548.88 ns] [406.99 ns]
full-log-with-9-attributes/with-context [501.88 ns] [418.26 ns]
full-log-with-attributes/no-context [322.71 ns] [277.63 ns]
full-log-with-attributes/with-context [328.19 ns] [279.08 ns]

Stress Test (20 threads)
Main: ~35 million iterations/sec
PR: ~39 million iterations/sec

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team as a code owner May 2, 2024 07:24
@lalitb lalitb marked this pull request as draft May 2, 2024 07:28
@lalitb lalitb marked this pull request as draft May 2, 2024 07:28
@lalitb lalitb changed the title Logrecord to sdk Moving LogRecord implementation to SDK May 2, 2024

/// Implementation for LogRecordBuilder
#[derive(Debug, Default)]
pub struct SdkLogRecordBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need a builder for LogRecord? Looking at the trait all it provides are method to change fields. So LogRecord by itself looks like a builder to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think I over-engineered a bit. Have removed the builder trait now :)

@cijothomas
Copy link
Member

While there are no current perf benefits with the approach,

Can you post benchmarks/stress tests with the changes, to confirm that we are not regressing either. (Just curiosity! I agree that this PR is the right direction)

@lalitb
Copy link
Member Author

lalitb commented May 3, 2024

While there are no current perf benefits with the approach,

Can you post benchmarks/stress tests with the changes, to confirm that we are not regressing either. (Just curiosity! I agree that this PR is the right direction)

Have added the stress and benchmark results in the description. Surprisingly I see the improvement, but don't want to read much out of that as of now :)

@lalitb lalitb marked this pull request as ready for review May 6, 2024 19:58
/// Span Id
pub span_id: SpanId,
/// Trace flags
pub trace_flags: Option<TraceFlags>,
Copy link
Member

Choose a reason for hiding this comment

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

wondering why is this optional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this was existing code in API. I can have a look into this separately.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

LGTM.
Waiting to add changelog, and remove the API to set span/trace context before approving.

lalitb and others added 4 commits May 6, 2024 19:21
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
@lalitb
Copy link
Member Author

lalitb commented May 7, 2024

LGTM. Waiting to add changelog, and remove the API to set span/trace context before approving.

changelog is added now. Thanks for the review.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Thanks! Great to see API getting leaner and delegating things to the SDK!

@cijothomas
Copy link
Member

@TommyCpp could you take another look?

@lalitb the CI is red, I think it is related to doc failure in this pr. can you fix that?

@cijothomas
Copy link
Member

@lalitb also - can you update PR desc. to reflect the final change in the PR? (Set vs Add and anything else) Thank you!

@lalitb
Copy link
Member Author

lalitb commented May 8, 2024

@lalitb the CI is red, I think it is related to doc failure in this pr. can you fix that?

done

@lalitb also - can you update PR desc. to reflect the final change in the PR? (Set vs Add and anything else) Thank you!

done.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the change

@cijothomas cijothomas merged commit b5fe16e into open-telemetry:main May 8, 2024
18 checks passed
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.

Logs API/SDK - Move LogRecord implementation details from API to SDK
4 participants