Provides instrumentation of both the client and server sides of Ktor. This includes support for distributed tracing between the client and the server.
It is recommended to use version 8.25.1 or later of the Java Agent as those versions contain instrumentation for Kotlin Coroutines. If you use an earlier version of the Java Agent then use the last set of instrumentation in the archived repo for Kotlin Coroutines (https://github.com/newrelic/newrelic-java-kotlin-coroutines/releases/tag/v1.0.8).
Additionally it recommended to version 8.20.0 of the New Relic Java Agent in order to avoid problems with the retransformation of Kotlin classes. This requires you to include a system property in the startup arguments of your application. Include -Dnewrelic.config.class_transformer.clear_return_stacks=true
See 8.20.0 Release Notes for more details (https://docs.newrelic.com/docs/release-notes/agent-release-notes/java-release-notes/java-agent-8200/)
This use this instrumentation.
- Download the latest release.
- In the New Relic Java Agent directory (directory containing newrelic.jar), create a directory named extensions if it doe not already exist.
- Copy the jars into the extensions directory.
- Add System Property described above to the startup arguments.
- Restart the application.
After deployment, you should get route names for your web transactions instead of the generic name provided by the agent.
You should also see deeper visibiity into what is happening in your application via the enhanced transaction traces/distributed traces provided by this instrumentation.
Ktor initiates a long running lazy Coroutine that will dominate the transaction times for your application unless it is ignored. Please use this version or later (https://github.com/newrelic/newrelic-java-kotlin-coroutines/releases/tag/v1.0.4) to enable this feature and add io.ktor.server.netty.cio.RequestBodyHandler to the scopes elemeent in the Coroutines stanza in newrelic.yml as shown here: https://github.com/newrelic/newrelic-java-kotlin-coroutines?tab=readme-ov-file#configuring-scopes-to-ignore
The Kotlin Coroutines instrumentation also will trace suspend functions so it recommended that you ignore internal Ktor suspend functions by adding the regular expression ".*io\.ktor\..*" to the list of suspends to ignore.
If using the Ktor CIO Http Client, it currently splits into several different transactions. Two of these are the major ones, the first will track the actual external call response time and the second will track the request timeout. The others are typically of short duration.
This problem requires a change to the Kotlin Coroutine instrumentation that will be fixed in an upcoming Java Agent release. After the release there will be a single transaction.
New Relic has open-sourced this project. Issues and contributions should be reported to the project here on GitHub.
We encourage your contributions to improve Salesforce Commerce Cloud for New Relic Browser! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.
New Relic Java Instrumentation for Ktor is licensed under the Apache 2.0 License.
