- Notifications
You must be signed in to change notification settings - Fork 327
Non discardable api #2632
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
Merged
Merged
Non discardable api #2632
Changes from 4 commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
312efdc Adding to public API
eyalkoren e7ca85a Add to public API docs
eyalkoren 866c891 Add to OTel bridge
eyalkoren ce84906 Fix OpenTelemetryVersionIT
eyalkoren e119d8b Apply review suggestions and add to OTel docs
eyalkoren 950c622 Adding to annotation API
eyalkoren f83aec9 Custom attributes are not exposed
eyalkoren 9c6501a Change OTel attribute key and meaning
eyalkoren cb0bb77 Merge remote-tracking branch 'upstream/main' into non-discardable-api
eyalkoren 3d82597 Add to CHANGELOG
eyalkoren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions 80 apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDiscardingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package co.elastic.apm.api; | ||
| | ||
| import co.elastic.apm.AbstractApiTest; | ||
| import co.elastic.apm.agent.configuration.CoreConfiguration; | ||
| import co.elastic.apm.agent.configuration.converter.TimeDuration; | ||
| import org.junit.jupiter.api.Test; | ||
| | ||
| import java.util.List; | ||
| | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.doReturn; | ||
| | ||
| @SuppressWarnings("unused") | ||
| public class SpanDiscardingTest extends AbstractApiTest { | ||
| | ||
| @Test | ||
| void testSpanDiscarding() { | ||
| doReturn(TimeDuration.of("100ms")).when(config.getConfig(CoreConfiguration.class)).getSpanMinDuration(); | ||
| Transaction transaction = ElasticApm.startTransaction(); | ||
| try (Scope activate = transaction.activate()) { | ||
| parent(true); | ||
| parent(false); | ||
| } | ||
| List<co.elastic.apm.agent.impl.transaction.Span> spans = reporter.getSpans(); | ||
| assertThat(spans).hasSize(2); | ||
| assertThat(spans).anyMatch(span -> span.getNameAsString().equals("parent-false")); | ||
| assertThat(spans).anyMatch(span -> span.getNameAsString().equals("not-discarded")); | ||
| transaction.end(); | ||
| } | ||
| | ||
| private void parent(boolean discardChild) { | ||
eyalkoren marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| Span span = ElasticApm.currentSpan().startSpan().setName("parent-" + discardChild); | ||
| try (Scope activate = span.activate()) { | ||
| if (discardChild) { | ||
| discarded(); | ||
| } else { | ||
| notDiscarded(); | ||
| } | ||
| } | ||
| span.end(); | ||
| } | ||
| | ||
| private void discarded() { | ||
| Span span = ElasticApm.currentSpan().startSpan().setName("discarded"); | ||
| try (Scope activate = span.activate()) { | ||
| child(); | ||
| } | ||
| span.end(); | ||
| } | ||
| | ||
| private void notDiscarded() { | ||
| Span span = ElasticApm.currentSpan().startSpan().setName("not-discarded").setNonDiscardable(); | ||
| try (Scope activate = span.activate()) { | ||
| child(); | ||
| } | ||
| span.end(); | ||
| } | ||
| | ||
| private void child() { | ||
| ElasticApm.currentSpan().startSpan().setName("child").end(); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions 27 ...try-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/sdk/BehavioralAttributes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package co.elastic.apm.agent.opentelemetry.sdk; | ||
| | ||
| /** | ||
| * An extension to the OTel API that allows us to provide special tracing settings. | ||
| * Such settings may affect tracing behavior internally, but they are not added as data and not persisted as span attributes. | ||
| */ | ||
| public class BehavioralAttributes { | ||
| public static final String NON_DISCARDABLE = "Elastic-OpenTelemetry-NonDiscardable"; | ||
eyalkoren marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions 46 ...lugin/src/test/java/co/elastic/apm/agent/opentelemetry/sdk/AbstractOpenTelemetryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package co.elastic.apm.agent.opentelemetry.sdk; | ||
| | ||
| import co.elastic.apm.agent.AbstractInstrumentationTest; | ||
| import io.opentelemetry.api.GlobalOpenTelemetry; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.api.trace.Tracer; | ||
| import org.junit.Before; | ||
| | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| | ||
| public class AbstractOpenTelemetryTest extends AbstractInstrumentationTest { | ||
| | ||
| protected OpenTelemetry openTelemetry; | ||
| protected Tracer otelTracer; | ||
| | ||
| @Before | ||
| public void setUp() { | ||
| this.openTelemetry = GlobalOpenTelemetry.get(); | ||
| assertThat(openTelemetry).isSameAs(GlobalOpenTelemetry.get()); | ||
| otelTracer = openTelemetry.getTracer(null); | ||
| | ||
| // otel spans are not recycled for now | ||
| disableRecyclingValidation(); | ||
| | ||
| // otel spans should have unknown outcome by default unless explicitly set through API | ||
| reporter.disableCheckUnknownOutcome(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.