Skip to content

Conversation

@pellared
Copy link
Member

@pellared pellared commented Feb 7, 2025

Per #6271 (comment)

This introduces a new go.opentelemetry.io/otel/sdk/log/xlog module.
I created it because of two reasons:

The SDK supports xlog using reflect (duck typing) and the sdk/log production code does not depend on xlog so users should never experience build failures because of breaking changes in xlog.

EDIT: The performance difference is huge because of using reflect. It makes the feature even almost unusable as in most cases calling Enabled (when all Processors are FilterProcessors) would be a lot more expensive than creating a heavy log record. But maybe it is a cost that we need to accept when providing experimental feature with a new types? The reflect overhead would be removed if the types would be stabilized and moved to go.opentelemetry.io/otel/sdk/log.

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
                 │   old.txt   │                  new.txt                  │
                 │   sec/op    │     sec/op      vs base                   │
LoggerEnabled-20   4.589n ± 1%   1977.500n ± 3%  +42992.18% (p=0.000 n=10)

                 │   old.txt    │            new.txt             │
                 │     B/op     │     B/op      vs base          │
LoggerEnabled-20   0.000Ki ± 0%   1.811Ki ± 6%  ? (p=0.000 n=10)

                 │  old.txt  │           new.txt            │
                 │ allocs/op │ allocs/op   vs base          │
LoggerEnabled-20   0.00 ± 0%   16.00 ± 0%  ? (p=0.000 n=10)

Maybe I should just use this PR as a prototype for sake of open-telemetry/opentelemetry-specification#4363. Then we could add the FilterProcessor straight to the go.opentelemetry.io/otel/sdk/log. However, then I have no idea how long we would need to wait for stability of Logs SDK.

The other alternative is to go with #6271 to achieve performance for the cost of coupling the sdk/log to sdk/log/xlog (similarly to what Collector does). I think the performance overhead is less acceptable than the potential build failures that users can run into. Trade-offs...

@pellared
Copy link
Member Author

pellared commented Feb 7, 2025

I think that we can make it working if we use reflect instead of type assertions.

sdk/log/go.mod Outdated
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/log v0.10.0
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/sdk/log/xlog v0.0.0-00010101000000-000000000000
Copy link
Member Author

@pellared pellared Feb 7, 2025

Choose a reason for hiding this comment

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

What is interesting if the dependency is used only used in tests then it does not come up as an indirect dependency for modules using go.opentelemetry.io/otel/sdk/log 🎉

It looks like the Go module graph pruning has been improved at some point.

I think that it means that we could get rid of test modules 😉

Copy link
Member

Choose a reason for hiding this comment

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

This is a bit strange. I've just tried that for otelhttp, and the SDK does come as an indirect dependency.

Copy link
Member Author

@pellared pellared Feb 11, 2025

Choose a reason for hiding this comment

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

Then I think we cannot rely on the Go modules pruning and I will get rid of this dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adressed 08ac146

Copy link
Member Author

@pellared pellared Feb 12, 2025

Choose a reason for hiding this comment

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

This is a bit strange. I've just tried that for otelhttp, and the SDK does come as an indirect dependency.

@dmathieu , I tried it once more and actually it does NOT come as an indirect dependency.

See: open-telemetry/opentelemetry-go-contrib#6763

I had to run make go-mod-tidy twice. Probably if we used crosslink tidylist then it would not be necessary

We can could consider revert 08ac146. But I am fine with the current approach as well. It looks cleaner. I propose to keep the current way.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it looks like the difference is that you used a different package name. So that'd be the trick.

Copy link
Member Author

@pellared pellared Feb 12, 2025

Choose a reason for hiding this comment

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

Ah, it looks like the difference is that you used a different package name. So that'd be the trick.

I do not follow. The SDK is used in tests of both of otelhttp and otelhttp_test packages.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but when I tried it, I kept the otelhttp package name for the tests. I think that's why the dependency still showed up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some tests still use it. Can you double check it? Make sure to run make go-mod-tidy more than once 😉

@pellared pellared requested a review from dmathieu as a code owner February 7, 2025 13:33
- go.opentelemetry.io/otel/schema
excluded-modules:
- go.opentelemetry.io/otel/internal/tools
- go.opentelemetry.io/otel/sdk/log/xlog
Copy link
Member Author

@pellared pellared Feb 7, 2025

Choose a reason for hiding this comment

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

I think that relying on git hashes may be very annoying for the users.
It would be hard for them to keep sdk/log and sdk/log/xlog in sync.

  1. We are making commits very frequently so they may even not bump it
  2. It would be hard to figure it out which version of xlog is compatible with log with we do any breaking change.

On the other side, we can wait for making a release until people actually complain.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

For comparison, the collector keeps x packages within the normal release process.

I have doubts about the idea, but if we want to allow folks to be able to get very fresh code, we could setup auto nightly/weekly releases for the x packages. Then, they wouldn't rely on commits, but would remain on the latest.

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

Would it be possible to add a linter to ensure no stable module uses an x one?

@pellared
Copy link
Member Author

pellared commented Feb 11, 2025

Would it be possible to add a linter to ensure no stable module uses an x one?

I created #6298 to avoid scope creeping.
I added it to Logs GA project to make sure we address it before stabilizing the logs.

@pellared
Copy link
Member Author

Would it be possible to add a linter to ensure no stable module uses an x one?

I created #6298 to avoid scope creeping. I added it to Logs GA project to make sure we address it before stabilizing the logs.

I found some time and I added the rule: 25937e0

@pellared pellared changed the title sdk/log/xlog: Add FilterProcessor and EnabledParameters [reflect] sdk/log/xlog: Add FilterProcessor and EnabledParameters Feb 13, 2025
@pellared
Copy link
Member Author

pellared commented Feb 13, 2025

I think that the performance overhead is huge (probably not acceptable, it would only make sense for users to call in case of enormous log records) and that we should reconsider #6271.

@pellared
Copy link
Member Author

SIG meeting notes:
We agreed that we can move FilterProcessor directly to sdk/log as Logs SDK does not look to be stabilized soon.

@pellared pellared closed this Feb 13, 2025
pellared added a commit that referenced this pull request Feb 18, 2025
Per
#6271 (comment)

> We agreed that we can move `FilterProcessor` directly to `sdk/log` as
Logs SDK does not look to be stabilized soon.

- Add the possibility to filter based on the resource and scope which is
available for the SDK. The scope information is the most important as it
gives the possibility to e.g. filter out logs emitted for a given
logger. Thus e.g.
open-telemetry/opentelemetry-specification#4364
is not necessary. See
open-telemetry/opentelemetry-specification#4290 (comment)
for more context.
- It is going be an example for
open-telemetry/opentelemetry-specification#4363

There is a little overhead (IMO totally acceptable) because of data
transformation. Most importantly, there is no new heap allocation.

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
                 │   old.txt   │                 new.txt                  │
                 │   sec/op    │     sec/op      vs base                  │
LoggerEnabled-20   4.589n ± 1%   319.750n ± 16%  +6867.75% (p=0.000 n=10)

                 │   old.txt    │             new.txt             │
                 │     B/op     │     B/op       vs base          │
LoggerEnabled-20   0.000Ki ± 0%   1.093Ki ± 13%  ? (p=0.000 n=10)

                 │  old.txt   │            new.txt             │
                 │ allocs/op  │ allocs/op   vs base            │
LoggerEnabled-20   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
```

`Logger.Enabled` is still more efficient than `Logger.Emit` (benchmarks
from #6315).

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkLoggerEmit/5_attributes-20               559934              2391 ns/op           39088 B/op          1 allocs/op
BenchmarkLoggerEmit/10_attributes-20             1000000              5910 ns/op           49483 B/op          5 allocs/op
BenchmarkLoggerEnabled-20                        1605697               968.7 ns/op          1272 B/op          0 allocs/op
PASS
ok      go.opentelemetry.io/otel/sdk/log        10.789s
```

Prior art:
- #6271
- #6286

I also created for tracking purposes:
- https://github.com/open-telemetry/opentelemetry-go/issues/6328
@pellared pellared deleted the xlog-not-used-by-sdk branch May 20, 2025 09:00
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.

2 participants