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

New Spring controller instrumentation modules #1675

Merged
merged 17 commits into from Jan 19, 2024

Conversation

jtduffy
Copy link
Contributor

@jtduffy jtduffy commented Dec 22, 2023

Overview

Resolves #1576
These instrumentation modules support proper transaction naming (route + HTTP method) of traditional annotated spring controllers as well as controllers that inherit annotations from interfaces, super classes or custom annotations. Check one of the README files in the PR for a full description.

spring-4.3.0: This module provides instrumentation for Spring Controllers utilizing Spring Web-MVC v4.3.0 up to but not including v6.0.0. (v6.0.0 instrumentation is provided by another module).
spring-6.0.0: Identical to spring-4.3.0 except for javax -> jakarta namespace.
spring-webflux-controller-mappings-5.0.0: Same functionality as the above modules except for Webflux rather than WebMVC.

Note that because the new instrumentation can change transaction names, enabling this "enhanced transaction naming" is gated by a configuration flag enhanced_spring_transaction_naming, which is false by default:

class_transformer:
    # Enhanced Spring transaction naming.
    # This feature will name any transaction that originates from a Spring controller after
    # the defined route and HTTP method. For example: "/customer/v1/edit (POST)".
    # This includes controllers that implement or extend interfaces/classes with WebMVC related
    # annotations (@RestController, @Controller, @RequestMapping, etc). By default, this is configured
    # to false, which will name transactions for those types of controllers based on the controller
    # class name and method. For example; "CustomerController/edit". This is the naming logic carried
    # over from previous agent versions. "Standard" controllers, with all relevant annotations
    # present on the actual class, will still get named based on route and HTTP method.
    enhanced_spring_transaction_naming: false

Testing

The agent includes a suite of tests which should be used to
verify your changes don't break existing functionality. These tests will run with
Github Actions when a pull request is made. More details on running the tests locally can be found
here,

Checks

  • Your contributions are backwards compatible with relevant frameworks and APIs.
  • Your code does not contain any breaking changes. Otherwise please describe.
  • Your code does not introduce any new dependencies. Otherwise please describe.

@jtduffy jtduffy requested a review from a team December 22, 2023 18:48
settings.gradle Outdated
@@ -340,6 +341,8 @@ include 'instrumentation:spring-webflux-6.0.0'
include 'instrumentation:spring-webflux-5.0.0'
include 'instrumentation:spring-webflux-5.1.0'
include 'instrumentation:spring-webflux-5.3.0'
include 'instrumentation:spring-webflux-controller-mappings-5.0.0'
include 'instrumentation:spring-webclient-5.0'
Copy link
Contributor

@meiao meiao Jan 11, 2024

Choose a reason for hiding this comment

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

Looks like you re added this webclient that I had moved as it was not in alphabetical order.

@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (0d98b3a) 70.70% compared to head (3d39ef5) 69.89%.
Report is 1 commits behind head on main.

Files Patch % Lines
...relic/agent/config/ClassTransformerConfigImpl.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1675      +/-   ##
============================================
- Coverage     70.70%   69.89%   -0.82%     
+ Complexity     9929     9826     -103     
============================================
  Files           830      829       -1     
  Lines         39880    39861      -19     
  Branches       6030     6033       +3     
============================================
- Hits          28197    27860     -337     
- Misses         8960     9315     +355     
+ Partials       2723     2686      -37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meiao meiao self-assigned this Jan 12, 2024
if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "SpringControllerUtility::assignTransactionNameFromControllerAndMethodRoutes (6.0.0): calling transaction.setTransactionName to [{0}] " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this 6.0.0 supposed to be the module version? This is in the 4.3.0 module.

if (NewRelic.getAgent().getLogger().isLoggable(Level.FINEST)) {
NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "SpringControllerUtility::assignTransactionNameFromControllerAndMethod (6.0.0): " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Same 6.0.0 here.
And , on the line below.

NewRelic.getAgent()
.getLogger()
.log(Level.FINEST, "SpringControllerUtility::assignTransactionNameFromControllerAndMethodRoutes (6.0.0): calling transaction.setTransactionName to [{0}] " +
"with FRAMEWORK_HIGH and override false, txn {1}, ", txnName, AgentBridge.getAgent().getTransaction().toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

You already have the transaction here. Any reason to get it again from the API?
The log message is ending with , . This gives the impression that there would me more content on this log message. Was there supposed to be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll address this in all 3 modules.

implementation("org.springframework:spring-web:4.3.0.RELEASE")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.21")
implementation("org.springframework:spring-webmvc:4.3.0.RELEASE")
implementation('jakarta.servlet:jakarta.servlet-api:4.0.4')
}

jar {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need the weave-violation-filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to create another issue to discuss this later. I don't know if it has any applicability outside of the spring controller stuff or not.

}

@Test
public void handleInternal_whenNoAnnotationPresent_namesTxnBasedOnControllerClassAndMethod() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the case of a RouterFunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this checks the case of a controller method that has no Spring controller annotations at all (like actuator endpoints or error handlers).


//If this setting is false, attempt to name transactions the way the legacy point cut
//named them
boolean isEnhancedNaming = NewRelic.getAgent().getConfig().getValue("class_transformer.enhanced_spring_transaction_naming", false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a constant in SpringControllerUtility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll address this in all 3 modules.

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.spring-6.0.0',
'Implementation-Title-Alias': 'spring_annotations',
'Weave-Violation-Filter': 'METHOD_MISSING_REQUIRED_ANNOTATIONS,CLASS_MISSING_REQUIRED_ANNOTATIONS' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for weave violation filter.

@@ -0,0 +1,193 @@
package com.nr.agent.instrumentation;
Copy link
Contributor

Choose a reason for hiding this comment

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

All tests are missing copyright.

@@ -0,0 +1,275 @@
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Old copyright

@@ -0,0 +1,274 @@
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Old Copyright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants