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

Use auto-instrumentation SDK in global tracing #5920

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Oct 24, 2024

When the auto-instrumentation attaches to a process using the global TracerProvider, and there has not been a delegate set, create a span from the go.opentelemetry.io/auto/sdk package so the OTel Go auto-instrumentation can instrument the application by default.

Resolve #5702

Benchmarks

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/internal/global
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                    │   old.txt    │            new.txt             │
                    │    sec/op    │    sec/op     vs base          │
StartEndSpanNoSDK-8   244.2n ± 21%   250.2n ± 23%  ~ (p=0.739 n=10)

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.0%. Comparing base (078b2dd) to head (c39b4c1).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5920     +/-   ##
=======================================
- Coverage   84.6%   82.0%   -2.6%     
=======================================
  Files        272     273      +1     
  Lines      22839   23571    +732     
=======================================
+ Hits       19325   19344     +19     
- Misses      3170    3883    +713     
  Partials     344     344             

see 4 files with indirect coverage changes

When the auto-instrumentation attaches to a process using the global
TracerProvider, and there has not been a delegate set, create a span
from the go.opentelemetry.io/auto/sdk package so the OTel Go
auto-instrumentation can instrument the application by default.
@MrAlias MrAlias marked this pull request as ready for review October 25, 2024 14:59
go.mod Outdated

require (
github.com/go-logr/logr v1.4.2
github.com/go-logr/stdr v1.2.2
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/auto/sdk v0.1.0-alpha
Copy link
Member

@pellared pellared Oct 28, 2024

Choose a reason for hiding this comment

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

Wouldn't coupling most modules of OTel Go to an unstable dependency occur too problematic for the users? I think the probability of a conflict is very low, but I would feel safer if we describe the possible consequences even in the PR description.

I think that as long as only the API modules are using go.opentelemetry.io/auto/sdk directly then it won't be an issue.

However, the user may have trouble if they also want to directly use go.opentelemetry.io/auto/sdk. Is it possible that a user may want to use API packages from go.opentelemetry.io/otel and instrumentation libraries, use instrumentation libraries for capturing telemetry and configure go.opentelemetry.io/auto/sdk on their own (the users would not use OTel SDK at all)? Given the package description of https://pkg.go.dev/go.opentelemetry.io/auto/sdk, I think that such scenario is possible then users of this module would get build issues each time there is a breaking change in https://pkg.go.dev/go.opentelemetry.io/auto/sdk and before they switch the newer version of OTel API that uses the new changes of auto/sdk.

This looks like a sort of a circular dependency.

Maybe auto could be sub-packages of API modules? It looks bad, but this is what this PR kind of does implicitly.

Copy link
Contributor Author

@MrAlias MrAlias Oct 28, 2024

Choose a reason for hiding this comment

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

This looks like a sort of a circular dependency.

sdk never imports otel or auto. How do you see the circular dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe auto could be sub-packages of API modules? It looks bad, but this is what this PR kind of does implicitly.

auto is a full auto-instrumentation package. It is run as a separate process to manage eBPF instrumentation. I'm not following why we would want that as a sub-package of the API modules?

Copy link
Member

@pellared pellared Oct 28, 2024

Choose a reason for hiding this comment

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

This looks like a sort of a circular dependency.

sdk never imports otel or auto. How do you see the circular dependency?

I mean auto/sdk and otel Go modules

https://pkg.go.dev/go.opentelemetry.io/auto/sdk?tab=imports

Circular dependency of Go modules (not packages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Circular dependency of Go modules (not packages)

Gotcha. Yeah, that's not a problem for Go. It's something we tested when developing that module and didn't have any issues.

Copy link
Member

@pellared pellared Oct 28, 2024

Choose a reason for hiding this comment

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

I think it may be an acceptable design trade-off. More https://github.com/open-telemetry/opentelemetry-go/pull/5920/files#r1819394158

// should not be read from the global.

if *autoSpan {
tracer := sdk.GetTracerProvider().Tracer(t.name, t.opts...)
Copy link
Member

@pellared pellared Oct 28, 2024

Choose a reason for hiding this comment

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

As long as only sdk.GetTracerProvider() is here and its signalture is not changed then the circular dependency of Go modules should not be a problem. I think we should make some automation e.g. using golangci-lint to make sure we will limit usage of auto/sdk to bare minimum. Also in auto/sdk add something to minimize the possibility of changing this function signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess the ask is if we can make auto/sdk stable.

I'm not opposed to bringing that request back to the auto SIG. But it may mean there is a greater chance of a v2 for this package if we find an issue implementing this here.

Copy link
Member

Choose a reason for hiding this comment

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

Alternativly it may be good enough to request stability of only this one function without making a V1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternativly it may be good enough to request stability of only this one function without making a V1.

I mean, that I can almost guarantee. It's just that it would only be codified in a commented agreement between developers instead of a version number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing I'm thinking through is the embedding of the default type for the Tracer and Span from that package. If we add a method to those interfaces here, we would need to update the sdk pkg with some implementation and include it in the release that would add the methods here. Otherwise, there would be compilation error of the otel package.

That is something we could do. But, I'm wondering if we should be embedding a noop there`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is something we could do. But, I'm wondering if we should be embedding a noop there`.

You mean change https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/f9241162a20bd4beb20d4347db3d8a77280920b1/sdk/trace.go#L34

to type tracerProvider struct{ noop.TracerProvider }?

If so then, I think it would be good and should mitigate a chicken-egg problem when introducing a new method to Trace API.

Yeah, that's what I'm thinking: 👍

Shouldn't be needed for this PR, but would be needed before we release this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated depguard. There is no way to ignore use outside of the import statement. I've just ignored these files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pellared should we just have the auto/sdk{,/telemetry} packages live here?

We originally published them under auto to allow development in the SIG they are designed for, but I wonder if the better user-story is one where they are hosted under otel/internal/global/...?

It would add code for auto-instrumentation here and add development burden, but it would also ensure there is never an otel release that could be broke by an independent upgrade of auto/sdk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pellared should we just have the auto/sdk{,/telemetry} packages live here?

We originally published them under auto to allow development in the SIG they are designed for, but I wonder if the better user-story is one where they are hosted under otel/internal/global/...?

It would add code for auto-instrumentation here and add development burden, but it would also ensure there is never an otel release that could be broke by an independent upgrade of auto/sdk.

This would require open-telemetry/opentelemetry-go-instrumentation#1207 or something similar so we would no longer depend on auto/sdk/telemetry in the auto module.

Copy link
Member

@pellared pellared Oct 29, 2024

Choose a reason for hiding this comment

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

We originally published them under auto to allow development in the SIG they are designed for, but I wonder if the better user-story is one where they are hosted under otel/internal/global/...?

I have a "feeling" that this would be a better design as this repository would be less (not?) dependent on go.opentelemetry.io/auto. Maybe it would be good to explore?

PS. This is kind of what I meant by

Maybe auto could be sub-packages of API modules?

Sorry that my comments are not very precise, but I also also having unprecise thoughts 😅

MrAlias and others added 2 commits October 28, 2024 10:39
Do not allow use of auto/sdk outside of global pkg.
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Discussed offline with @MrAlias.

We think that before merging this it would be good to:

  1. rename sdk.GetTracerProvider to sdk.TracerProvider; reason: https://go.dev/doc/effective_go#Getters
  2. make a v1 release of go.opentelemetry.io/auto/sdk

.golangci.yml Show resolved Hide resolved
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.

Update the no-op trace implementations to support auto-instrumentation
5 participants