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

added WithSpanInstrumentation #3406

Merged
merged 19 commits into from Nov 27, 2023
Merged

Conversation

videnkz
Copy link
Contributor

@videnkz videnkz commented Nov 2, 2023

What does this PR do?

closes #2753

Added instrumentation for opentelemetry annotation WithSpan

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation

TODO:
[x] - support of annotation WithSpan
[x] - support of annotation SpanAtribute

@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage labels Nov 2, 2023
Copy link

github-actions bot commented Nov 2, 2023

👋 @videnkz Thanks a lot for your contribution!

It may take some time before we review a PR, so even if you don’t see activity for some time, it does not mean that we have forgotten about it.

Every once in a while we go through a process of prioritization, after which we are focussing on the tasks that were planned for the upcoming milestone. The prioritization status is typically reflected through the PR labels. It could be pending triage, a candidate for a future milestone, or have a target milestone set to it.

@videnkz videnkz marked this pull request as ready for review November 3, 2023 11:56
Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

LGTM, I only have one minor question about custom annotation in tests.

SylvainJuge
SylvainJuge previously approved these changes Nov 20, 2023
@@ -38,6 +38,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
* Capture bucket and object key to Lambda transaction as OTel attributes - `aws.s3.bueckt`, `aws.s3.key` - {pull}3364[#3364]
* Added `context_propagation_only` configuration option - {pull}3358[#3358]
* Added attribute[*] for JMX pattern metrics (all metrics can now be generated with `object_name[*:type=*,name=*] attribute[*]`) - {pull}3376[#3376]
* Added support for OpenTelemetry annotations - `WithSpan` and `CaptureAttribute` - {pull}3406[#3406]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is CaptureAttribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jackshirazi ,
My apologize, I fixed name of annotation: CaptureAttribute -> SpanAttribute.

@jackshirazi
Copy link
Contributor

We should alter the CoreConfiguration.enablePublicApiAnnotationInheritance description line from

        .description("A boolean specifying if the agent should search the class hierarchy for public api annotations (`@CaptureTransaction`, `@CaptureSpan`, `@Traced`).\n " +

to

        .description("A boolean specifying if the agent should search the class hierarchy for public api annotations (`@CaptureTransaction`, `@CaptureSpan`, `@Traced` and from 1.44.0 `@WithSpan`).\n " +

@videnkz
Copy link
Contributor Author

videnkz commented Nov 21, 2023

We should alter the CoreConfiguration.enablePublicApiAnnotationInheritance description line from

        .description("A boolean specifying if the agent should search the class hierarchy for public api annotations (`@CaptureTransaction`, `@CaptureSpan`, `@Traced`).\n " +

to

        .description("A boolean specifying if the agent should search the class hierarchy for public api annotations (`@CaptureTransaction`, `@CaptureSpan`, `@Traced` and from 1.44.0 `@WithSpan`).\n " +

updated

@jackshirazi
Copy link
Contributor

@mergify rebase

Copy link
Contributor

mergify bot commented Nov 23, 2023

rebase

❌ Base branch update has failed

Git reported the following error:

Rebasing (1/9)
Rebasing (2/9)
Rebasing (3/9)
Rebasing (4/9)
Rebasing (5/9)
Auto-merging CHANGELOG.asciidoc
CONFLICT (content): Merge conflict in CHANGELOG.asciidoc
error: could not apply e86c762a0... added entry to changelog
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply e86c762a0... added entry to changelog

@jackshirazi
Copy link
Contributor

@videnkz needs merging to main and ConfigurationExporterTest run to regenerate docs

@videnkz
Copy link
Contributor Author

videnkz commented Nov 23, 2023

@videnkz needs merging to main and ConfigurationExporterTest run to regenerate docs

Done

@jackshirazi
Copy link
Contributor

The test is failing, it doesn't fail locally but it looks like a real failure on CI, class visibility. I don't think I'm going to have time to look at fixing it this week, @videnkz if you have time please do

@videnkz
Copy link
Contributor Author

videnkz commented Nov 24, 2023

The test is failing, it doesn't fail locally but it looks like a real failure on CI, class visibility. I don't think I'm going to have time to look at fixing it this week, @videnkz if you have time please do

I fixed it

@jackshirazi
Copy link
Contributor

different failure now, again passes locally, failing in CI. Getting no spans for this in ElasticOpenTelemetryTest when executed from OpenTelemetryVersionIT

assertThat(reporter.getSpans()).hasSize(1);

@videnkz
Copy link
Contributor Author

videnkz commented Nov 24, 2023

different failure now, again passes locally, failing in CI. Getting no spans for this in ElasticOpenTelemetryTest when executed from OpenTelemetryVersionIT

assertThat(reporter.getSpans()).hasSize(1);

@jackshirazi I did minor fixes in ElasticOpenTelemetryTest, I moved annotations related tests to separate test class. Can you check again plz?

@jackshirazi
Copy link
Contributor

@elasticmachine run elasticsearch-ci/docs


@Override
public Collection<String> getInstrumentationGroupNames() {
return Collections.singletonList("opentelemetry-annotations");
Copy link
Contributor

Choose a reason for hiding this comment

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

The returned list should include super.getInstrumentationGroupNames(): Otherwise this instrumentation would stay enabled even if users added opentelemetry to the disabled instrumentations config option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

doStaff();
}

private void doStaff() {
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 doStaff() really required? I think simply empty, annotated methods should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not required

@@ -140,4 +140,30 @@ void testUnsupportedMetricsSdkVersionsIgnored(String apiVersion, String sdkVersi
runner.run();
}

@ParameterizedTest
@ValueSource(strings = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think testing with just 1.20.0 should be fine here. The latest version will be run outside of this integration.
There were no changes between 1.20.0 and the latest one on the annotations (I think), so there is no need to spend time on testing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

docs/api-opentelemetry.asciidoc Outdated Show resolved Hide resolved
@@ -44,6 +44,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
* Capture bucket and object key to Lambda transaction as OTel attributes - `aws.s3.bueckt`, `aws.s3.key` - {pull}3364[#3364]
* Added `context_propagation_only` configuration option - {pull}3358[#3358]
* Added attribute[*] for JMX pattern metrics (all metrics can now be generated with `object_name[*:type=*,name=*] attribute[*]`) - {pull}3376[#3376]
* Added support for OpenTelemetry annotations - `WithSpan` and `SpanAttribute` - {pull}3406[#3406]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this up into a new section under the unreleased heading at the top, because 1.44.0 was released in the meantime:

=== Unreleased

[float]
===== Features
* Added support for OpenTelemetry annotations - `WithSpan` and `SpanAttribute` - {pull}3406[#3406]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved

Copy link

cla-checker-service bot commented Nov 27, 2023

💚 CLA has been signed

Update apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java
Update docs/api-opentelemetry.asciidoc
Update apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java

Update docs/api-opentelemetry.asciidoc
@JonasKunz
Copy link
Contributor

@videnkz I think you need to rerun ConfigurationExporterTest locally and commit the resulting documentation changes: One of my suggestions altered the docs, so they need to be regenerated.

@videnkz
Copy link
Contributor Author

videnkz commented Nov 27, 2023

@videnkz I think you need to rerun ConfigurationExporterTest locally and commit the resulting documentation changes: One of my suggestions altered the docs, so they need to be regenerated.

Done

@JonasKunz
Copy link
Contributor

@elasticmachine run elasticsearch-ci/docs

@JonasKunz JonasKunz merged commit 59da6ee into elastic:main Nov 27, 2023
13 checks passed
@JonasKunz
Copy link
Contributor

@videnkz Thanks for all the time & effort you invested to implement this! ❤️

@royteeuwen
Copy link

Very nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for OpenTelemetry annotations
5 participants