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

Use new propagation context API #281

Merged
merged 12 commits into from
May 22, 2023
Merged

Use new propagation context API #281

merged 12 commits into from
May 22, 2023

Conversation

dstepanov
Copy link
Contributor

@dstepanov dstepanov commented Apr 26, 2023

The PR is moving to the new propagation API introduced in Micronaut 4.
Also:

  • Opentracing is refactored into a separate module
  • Zipkin modules renamed to Brave
  • Extracted Brave HTTP

@dstepanov dstepanov marked this pull request as draft April 26, 2023 00:25
graemerocher pushed a commit to micronaut-projects/micronaut-core that referenced this pull request May 17, 2023
Initial version of the propagation API.

Main points:
- The propagated context is always immutable and consist of different propagated elements similar to Kotlin Coroutines context
- Propagated element can implement `ThreadPropagatedContextElement` to setup/restore thread locals
- The propagated state is never captured but the context needs to be extended and pushed down the downstream
- The capturing API is not needed anymore, this should eliminate a lot of overhead from the reactive code
- The context is automatically propagated to the Kotlin coroutines
- In the Reactor context should be propagated as whole with utility method to extract/extend it (The Reactor context needs to be modified manually)
- The implementation is using try-resources to propagate the contest without extra overhead, this might change in the future to support scoped local, but at this moment, I think this is the best solution.

I want to merge this first PR to have the orther work mergable.

Next PRs will remove the existing instrumentation propagation, add docs etc.

There are already examples how it should be used:
- Tracing micronaut-projects/micronaut-tracing#281
- Micronaut Data micronaut-projects/micronaut-data#2189 (This is a big PR because of the changes in the TX management and removal of forked Spring TX code)
@dstepanov
Copy link
Contributor Author

The build is failing locally with:

  
  Message: No bean of type [io.grpc.ManagedChannel] exists for the given qualifier: @Named('grpc-server'). Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
  Path Taken: OpenTelemetryGrpcClientSpec.setTestBean([TestBean testBean]) --> TestBean.setBlockingStub([GreeterBlockingStub blockingStub]) --> Clients.blockingStub([Channel channel])
      at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2322)
      at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)

@dstepanov dstepanov marked this pull request as ready for review May 17, 2023 17:29
Comment on lines 98 to 112
// Optional<?> body = response.getBody();
// if (body.isPresent()) {
// Object o = body.get();
// if (Publishers.isConvertibleToPublisher(o)) {
// Class<?> type = o.getClass();
// Publisher<?> resultPublisher = Publishers.convertPublisher(conversionService, o, Publisher.class);
// Publisher<?> scopedPublisher = new ScopePropagationPublisher<>(
// resultPublisher,
// openTracer,
// openTracer.activeSpan()
// );
//
// response.body(Publishers.convertPublisher(conversionService, scopedPublisher, type));
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

delete this code if it is not needed

@@ -14,4 +14,4 @@
# limitations under the License.
#

Args = --initialize-at-run-time=io.micronaut.tracing.instrument.kotlin.HttpCoroutineTracingDispatcherFactory
Args = --initialize-at-run-time=io.micronaut.tracing.brave.http.HttpTracingFactor
Copy link
Contributor

Choose a reason for hiding this comment

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

this file can be deleted

@@ -14,4 +14,4 @@
# limitations under the License.
#

Args = --initialize-at-run-time=io.micronaut.tracing.brave.BraveTracerFactory,io.micronaut.tracing.brave.instrument.http.HttpTracingFactory,io.micronaut.tracing.brave.log.Slf4jCurrentTraceContextFactory,io.micronaut.tracing.brave.sender.HttpClientSenderFactory
Args = --initialize-at-run-time=io.micronaut.tracing.brave.BraveTracerFactory,io.micronaut.tracing.brave.log.Slf4jCurrentTraceContextFactory,io.micronaut.tracing.brave.sender.HttpClientSenderFactory
Copy link
Contributor

Choose a reason for hiding this comment

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

this file can be deleted

@@ -802,15 +808,15 @@ class HttpTracingSpec extends Specification {
spanCustomizer.activeSpan()?.setBaggageItem('foo', 'bar')
Flux.from(tracedClient.continuedRx(name))
.flatMap({ String res ->
assert spanCustomizer.activeSpan()?.getBaggageItem('foo') == 'bar'
// assert spanCustomizer.activeSpan()?.getBaggageItem('foo') == 'bar'
Copy link
Member

Choose a reason for hiding this comment

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

Does this validation needs to be present or deleted?

return tracedClient.nestedReactive2(res)
})
}

@Get('/nestedReactive2/{name}')
@SingleResult
Publisher<Integer> nestedReactive2(String name) {
assert spanCustomizer.activeSpan()?.getBaggageItem('foo') == 'bar'
// assert spanCustomizer.activeSpan()?.getBaggageItem('foo') == 'bar'
Copy link
Member

Choose a reason for hiding this comment

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

Does this validation needs to be present or deleted?

@sonarcloud
Copy link

sonarcloud bot commented May 22, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 21 Code Smells

69.4% 69.4% Coverage
2.6% 2.6% Duplication

@graemerocher graemerocher merged commit 54921f0 into master May 22, 2023
@graemerocher graemerocher deleted the prop branch May 22, 2023 13:22
sdelamo added a commit to micronaut-projects/micronaut-core that referenced this pull request May 23, 2023
sdelamo added a commit to micronaut-projects/micronaut-core that referenced this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants