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

Instrumentation API part 3 #422

Merged
merged 12 commits into from
Jun 17, 2024

Conversation

LikeTheSalad
Copy link
Contributor

This part focuses on the lifecycle observer tool, that's needed in different modules, becoming a service.

* Moving network provider tools to services

* Moving network service related tests

* Moving network attr init feature to the agent

* Making network instrumentation depend on the agent

* Initializing CurrentNetworkProvider as service

* Clean up config

* Created NetworkChangeInstrumentation

* Updated network monitor tests

* Clean up

* Renaming installOn by start

* Adding internal class docs

* Fixing visible for tests comment

* Rename .java to .kt

* Removing Carrier.Builder
@LikeTheSalad LikeTheSalad requested a review from a team June 7, 2024 07:41
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public interface ApplicationStateListener {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been copied from here. It should have been just moved, but the original interface is still referenced in all the modules that haven't been migrated, so I'm planning to remove it from the original place after all the modules are migrated, otherwise we wouldn't get a green build in the PRs in the meantime.

/**
* This class is internal and not for public use. Its APIs are unstable and can change at any time.
*/
internal class ApplicationStateWatcher : DefaultLifecycleObserver {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class is meant to replace this one.

Copy link
Contributor

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

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

LGTM. No blocking comments, just a couple about how the test classes are written and one about some commented out code

val tracer = sdk.getTracer(OpenTelemetryRum::class.java.simpleName)
sessionId.setSessionIdChangeListener(SessionIdChangeTracer(tracer))

// InstrumentedApplication instrumentedApplication =
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this commented code be restored in a later PR or were they accidentally left?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be replaced in one of the last PRs regarding the instrumentation changes, right now I left it commented to not forget about it 😅

/**
* This class is internal and not for public use. Its APIs are unstable and can change at any time.
*/
class AppLifecycleService internal constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason you prefer this particular setting of visibility modifier? It feels like making the entire class internal and change the visibility of the constructor ought to be good enough if we want to contain its instantiation to this module. I think given that we are spinning of the instrumentation from the agent module, this would be even more reasonable.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's probably a better way to address this, though at the moment the reasoning behind it is that all services are essentially helper tools that might be reused by our own submodules, such as instrumentations. Right now, this service provides app lifecycle info that's useful for the network change instrumentation, and I also think it will provide useful info for the activity/fragment instrumentations too iirc. We could replicate this service's functionality in other modules though, but for now, given that the instrumentations will have a dependency on the core agent anyway, which is where the AndroidInstrumentation interface lives, it seemed sensible to reuse those tools.

Copy link
Contributor

Choose a reason for hiding this comment

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

So this is effectively a private interface for "friends" but because of module boundaries, it's not declared internal? I wonder if we can just make it public but exclude it from docs, state it's not a part of the public interface, and is liable to be changed at any time, perhaps even add an annotation in there fore good measure? We're effectively hiding it, just making it hard to use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is effectively a private interface for "friends" but because of module boundaries, it's not declared internal?

That's right, this is currently the case for all services. This reminded me of a conversation we had in one of the meetings about potentially making them public for all instrumentations. I think this topic is big enough to have its own conversation, so I've created this issue to follow up on it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, pulling these in an internal package, putting comments to say this should not be depended on and can change at any time, and using the annotations like @hide to keep it out of auto generated docs is probably the best way of do this given the way Kotlin visibility works. Maybe we can put the implementation and API into different modules so apps will never have to explicitly pull in modules that contain the implementation, but we don't want to overdo this and make it too hard on ourselves either 😅 Definitely something to talk about for later and not now


@ExtendWith(MockitoExtension.class)
class OpenTelemetryRumBuilderTest {
@RunWith(RobolectricTestRunner.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can now use the AndroidJUnit4 runner which supercedes this one, even for Robolectric tests. You can have a look at the docs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! I wasn't aware of it, I'll make the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it's updated now!

@LikeTheSalad LikeTheSalad changed the base branch from feature/instrumentation-api to main June 14, 2024 05:57
# Conflicts:
#	android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManager.kt
#	android-agent/src/main/java/io/opentelemetry/android/internal/services/ServiceManagerImpl.kt
#	android-agent/src/test/java/io/opentelemetry/android/OpenTelemetryRumBuilderTest.java
#	android-agent/src/test/java/io/opentelemetry/android/internal/features/networkattrs/CurrentNetworkAttributesExtractorTest.java
#	instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkApplicationListener.java
#	instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeInstrumentation.java
#	instrumentation/network/src/main/java/io/opentelemetry/android/instrumentation/network/NetworkChangeMonitor.java
#	instrumentation/network/src/test/java/io/opentelemetry/android/instrumentation/network/NetworkChangeMonitorTest.java
@LikeTheSalad LikeTheSalad merged commit 53896cf into open-telemetry:main Jun 17, 2024
3 checks passed
@LikeTheSalad LikeTheSalad deleted the instrumentation-api-p3 branch June 17, 2024 09:03
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