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

4.x Add support for @SpanAttribute annotation, use entire path for REST resource span name #8216

Merged
merged 11 commits into from
Jan 11, 2024

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Jan 9, 2024

Description

Resolves #8157
Resolves #8162

Highlights:

  • Enhance WithSpanInterceptor so it also processes @SpanAttribute annotations.
  • Add tests to check span name and attributes.
  • Fix derivation of OTel span name for REST endpoints to reflect OpenTelemetry span naming semantic conventions.
  • Add tests for REST endpoint span naming.

Documentation

Bug fix; no doc impact.

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
@tjquinno tjquinno self-assigned this Jan 9, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 9, 2024
@tjquinno tjquinno marked this pull request as draft January 9, 2024 23:51
@tjquinno tjquinno marked this pull request as ready for review January 10, 2024 23:54
if (app == null) {
return "";
}
ApplicationPath applicationPath = getRealClass(app.getClass()).getAnnotation(ApplicationPath.class);
Copy link
Member

Choose a reason for hiding this comment

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

Since you've already used things like ExtendedUriInfo maybe there's a Jersey class that will give you whatever the @ApplicationPath annotation ends up setting indirectly?

Copy link
Member Author

@tjquinno tjquinno Jan 11, 2024

Choose a reason for hiding this comment

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

I didn't see a way to do that, after quite some looking.

If you have a specific suggestion I'd welcome it but I didn't find a way to do what you suggested. The security code Tomas pointed to (in internal Slack) uses the same technique to get the Application.

Copy link
Member

@ljnelson ljnelson left a comment

Choose a reason for hiding this comment

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

Got some assignability stuff backwards, I think; have a peek

Comment on lines 93 to 103
if (paramType.isAssignableFrom(String.class)) {
spanBuilder.setAttribute(attrName, (String) pValue);
} else if (paramType.isAssignableFrom(long.class) || paramType.isAssignableFrom(Long.class)) {
spanBuilder.setAttribute(attrName, (long) pValue);
} else if (paramType.isAssignableFrom(double.class) || paramType.isAssignableFrom(Double.class)) {
spanBuilder.setAttribute(attrName, (double) pValue);
} else if (paramType.isAssignableFrom(boolean.class) || paramType.isAssignableFrom(Boolean.class)) {
spanBuilder.setAttribute(attrName, (boolean) pValue);
} else {
spanBuilder.setAttribute(attrName, pValue.toString());
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure these are backwards. You want String.class.isAssignableFrom(paramType). Or you want to do something like:

switch (paramType) {
case Class<?> x when Long.class.isAssignableFrom(paramType): // this may? work for primitives too? can't remember if autoboxing kicks in?
  spanBuilder.setAttribute(attrName, x.cast(pValue));
  break;
case Class<?> x when Double.class.isAssignableFrom(paramType):
  spanBuilder.setAttribute(attrName, x.cast(pValue));
  break;
case Class<?> x when Boolean.class.isAssignableFrom(paramType):
  spanBuilder.setAttribute(attrName, x.cast(pValue));
  break;
default:
  spanBuilder.setAttribute(attrName, pValue.toString());
  break;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes. Fixed.

We could use the switch-case-with-break approach but I chose to stay with the if-then-else-if because to me at least it's slightly clearer.

ljnelson
ljnelson previously approved these changes Jan 11, 2024
Copy link
Member

@ljnelson ljnelson left a comment

Choose a reason for hiding this comment

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

LGTM (not an expert in this area)

… name to pass TCK tests that do not expect it
@tjquinno tjquinno changed the title 4.x Add support for @SpanAttribute annotation 4.x Add support for @SpanAttribute annotation, use entire path for REST resource span name Jan 11, 2024
Copy link
Member

@tomas-langer tomas-langer left a comment

Choose a reason for hiding this comment

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

LGTM

@tomas-langer tomas-langer removed the request for review from dalexandrov January 11, 2024 17:46
@tjquinno tjquinno merged commit b95ad0b into helidon-io:main Jan 11, 2024
12 checks passed
@tjquinno tjquinno deleted the 4.x-span-attr-anno branch January 11, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
3 participants