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

Handle structured body and attributes #7

Merged
merged 13 commits into from
Jan 24, 2024
Merged

Conversation

pellared
Copy link
Owner

@pellared pellared commented Jan 19, 2024

Why

Addresses open-telemetry#4809 (comment) and open-telemetry#4809 (comment).

The type definitions need to be compliant with https://opentelemetry.io/docs/specs/otel/logs/data-model/#type-any

  1. Log attributes are different than common (trace, metrics, resource) attributes.
  2. Body must handle structure data (not only string).

What

Here is the code containing new types: https://github.com/pellared/opentelemetry-go/blob/strucutred-values/log/value.go

The code adopted from https://github.com/golang/go/blob/master/src/log/slog/value.go to be compliant with https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-any

I am not sure if uint64 should be handled or not. I decided to postpone it as we can add it later without introducing any breaking change. Spec issue: open-telemetry/opentelemetry-specification#3836.

Benchmarks

Even a little faster and consuming less memory.

$ benchstat old.txt new.txt
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/log/internal
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
                        │    old.txt    │               new.txt                │
                        │    sec/op     │    sec/op     vs base                │
Emit/noop/no_attrs-16      6.494n ± 12%   4.898n ±  4%  -24.57% (p=0.000 n=10)
Emit/noop/3_attrs-16       17.63n ±  9%   12.95n ±  5%  -26.59% (p=0.000 n=10)
Emit/noop/5_attrs-16       24.73n ±  6%   17.89n ±  5%  -27.64% (p=0.000 n=10)
Emit/noop/10_attrs-16      266.9n ±  5%   192.8n ±  3%  -27.74% (p=0.000 n=10)
Emit/noop/40_attrs-16     1307.5n ±  5%   933.2n ±  3%  -28.63% (p=0.000 n=10)
Emit/writer/no_attrs-16    89.00n ±  1%   91.45n ±  6%        ~ (p=0.781 n=10)
Emit/writer/3_attrs-16     231.1n ±  7%   227.3n ±  6%        ~ (p=0.353 n=10)
Emit/writer/5_attrs-16     265.5n ±  4%   269.1n ±  4%        ~ (p=0.436 n=10)
Emit/writer/10_attrs-16    735.7n ±  6%   630.8n ± 10%  -14.27% (p=0.000 n=10)
Emit/writer/40_attrs-16    3.156µ ±  3%   2.699µ ±  3%  -14.50% (p=0.000 n=10)
Slog/no_attrs-16           151.9n ± 13%   159.2n ± 17%        ~ (p=0.315 n=10)
Slog/3_attrs-16            225.2n ±  8%   230.2n ±  9%        ~ (p=0.280 n=10)
Slog/5_attrs-16            270.8n ± 27%   271.3n ± 15%        ~ (p=0.529 n=10)
Slog/10_attrs-16           1.446µ ± 11%   1.083µ ±  5%  -25.08% (p=0.000 n=10)
Slog/40_attrs-16           6.917µ ±  5%   5.902µ ± 10%  -14.67% (p=0.000 n=10)
Logr/no_attrs-16           9.234n ±  5%   8.139n ±  7%  -11.86% (p=0.000 n=10)
Logr/3_attrs-16            160.5n ±  5%   158.4n ±  3%        ~ (p=0.171 n=10)
Logr/5_attrs-16            247.4n ±  6%   259.1n ±  4%   +4.71% (p=0.045 n=10)
Logr/10_attrs-16          1135.0n ± 11%   998.6n ±  6%  -12.02% (p=0.000 n=10)
Logr/40_attrs-16           6.881µ ±  7%   5.554µ ±  6%  -19.29% (p=0.000 n=10)
geomean                    266.7n         233.3n        -12.52%

                        │    old.txt     │                new.txt                 │
                        │      B/op      │     B/op      vs base                  │
Emit/noop/no_attrs-16       0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Emit/noop/3_attrs-16        0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Emit/noop/5_attrs-16        0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Emit/noop/10_attrs-16       320.0 ± 0%       208.0 ± 0%  -35.00% (p=0.000 n=10)
Emit/noop/40_attrs-16     2.250Ki ± 0%     1.375Ki ± 0%  -38.89% (p=0.000 n=10)
Emit/writer/no_attrs-16     16.00 ± 0%       16.00 ± 0%        ~ (p=1.000 n=10) ¹
Emit/writer/3_attrs-16      48.00 ± 0%       48.00 ± 0%        ~ (p=1.000 n=10) ¹
Emit/writer/5_attrs-16      48.00 ± 0%       48.00 ± 0%        ~ (p=1.000 n=10) ¹
Emit/writer/10_attrs-16     408.0 ± 0%       296.0 ± 0%  -27.45% (p=0.000 n=10)
Emit/writer/40_attrs-16   2.570Ki ± 0%     1.695Ki ± 0%  -34.04% (p=0.000 n=10)
Slog/no_attrs-16            0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Slog/3_attrs-16             0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Slog/5_attrs-16             0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Slog/10_attrs-16           1168.0 ± 0%       816.0 ± 0%  -30.14% (p=0.000 n=10)
Slog/40_attrs-16          9.312Ki ± 0%     6.469Ki ± 0%  -30.54% (p=0.000 n=10)
Logr/no_attrs-16            0.000 ± 0%       0.000 ± 0%        ~ (p=1.000 n=10) ¹
Logr/3_attrs-16             128.0 ± 0%       128.0 ± 0%        ~ (p=1.000 n=10) ¹
Logr/5_attrs-16             208.0 ± 0%       208.0 ± 0%        ~ (p=1.000 n=10) ¹
Logr/10_attrs-16          1.344Ki ± 0%     1.000Ki ± 0%  -25.58% (p=0.000 n=10)
Logr/40_attrs-16          9.562Ki ± 0%     6.719Ki ± 0%  -29.74% (p=0.000 n=10)
geomean                                ²                 -14.07%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                        │   old.txt    │               new.txt               │
                        │  allocs/op   │ allocs/op   vs base                 │
Emit/noop/no_attrs-16     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/noop/3_attrs-16      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/noop/5_attrs-16      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/noop/10_attrs-16     1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/noop/40_attrs-16     1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/writer/no_attrs-16   1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/writer/3_attrs-16    4.000 ± 0%     4.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/writer/5_attrs-16    4.000 ± 0%     4.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/writer/10_attrs-16   8.000 ± 0%     8.000 ± 0%       ~ (p=1.000 n=10) ¹
Emit/writer/40_attrs-16   26.00 ± 0%     26.00 ± 0%       ~ (p=1.000 n=10) ¹
Slog/no_attrs-16          0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Slog/3_attrs-16           0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Slog/5_attrs-16           0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Slog/10_attrs-16          5.000 ± 0%     5.000 ± 0%       ~ (p=1.000 n=10) ¹
Slog/40_attrs-16          8.000 ± 0%     8.000 ± 0%       ~ (p=1.000 n=10) ¹
Logr/no_attrs-16          0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
Logr/3_attrs-16           4.000 ± 0%     4.000 ± 0%       ~ (p=1.000 n=10) ¹
Logr/5_attrs-16           5.000 ± 0%     5.000 ± 0%       ~ (p=1.000 n=10) ¹
Logr/10_attrs-16          13.00 ± 0%     13.00 ± 0%       ~ (p=1.000 n=10) ¹
Logr/40_attrs-16          40.00 ± 0%     40.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                              ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@pellared pellared marked this pull request as ready for review January 19, 2024 11:52
@pellared pellared merged commit 5d8c58f into logs-design Jan 24, 2024
26 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.

1 participant