Skip to content

Commit

Permalink
[doc] Enhance context propagation reference documentation (#2841)
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Jun 23, 2023
1 parent e957482 commit 135802a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 18 deletions.
10 changes: 9 additions & 1 deletion docs/asciidoc/http-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,17 @@ include::{examplesdir}/tracing/custom/Application.java[lines=18..85]
<1> Initializes Brave, Zipkin, and the Observation registry.
<2> Templated URIs are used as an URI tag value when possible.
<3> Enables the built-in integration with Micrometer.
<4> Custom `ChannelHandler` that uses context propagation library.
<4> Custom `ChannelHandler` that uses context propagation library. This concrete example overrides only
`ChannelOutboundHandlerAdapter#write`, if it is needed, the same logic can be used for the rest of the methods.
Also, this concrete example sets all `ThreadLocal` values for which there is a value in the given `Channel`,
if another behaviour is needed please check https://micrometer.io/docs/contextPropagation[`context propagation library API`].
For example, you may want to set only some of the `ThreadLocal` values.
====

NOTE: When you enable Reactor Netty tracing within a framework, you may need to let Reactor Netty use the `ObservationRegistry` created by this framework.
For this purpose you need to invoke {javadoc}/reactor/netty/Metrics.html#observationRegistry-io.micrometer.observation.ObservationRegistry-[`reactor.netty.Metrics#observationRegistry`].
You may also need to configure the Reactor Netty `ObservationHandlers` using the API provided by the framework.

== Unix Domain Sockets
The `HTTP` client supports Unix Domain Sockets (UDS) when native transport is in use.

Expand Down
10 changes: 9 additions & 1 deletion docs/asciidoc/http-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,17 @@ include::{examplesdir}/tracing/custom/Application.java[lines=18..85]
<1> Initializes Brave, Zipkin, and the Observation registry.
<2> Templated URIs are used as an URI tag value when possible.
<3> Enables the built-in integration with Micrometer.
<4> Custom `ChannelHandler` that uses context propagation library.
<4> Custom `ChannelHandler` that uses context propagation library. This concrete example overrides only
`ChannelOutboundHandlerAdapter#write`, if it is needed, the same logic can be used for the rest of the methods.
Also, this concrete example sets all `ThreadLocal` values for which there is a value in the given `Channel`,
if another behaviour is needed please check https://micrometer.io/docs/contextPropagation[`context propagation library API`].
For example, you may want to set only some of the `ThreadLocal` values.
====

NOTE: When you enable Reactor Netty tracing within a framework, you may need to let Reactor Netty use the `ObservationRegistry` created by this framework.
For this purpose you need to invoke {javadoc}/reactor/netty/Metrics.html#observationRegistry-io.micrometer.observation.ObservationRegistry-[`reactor.netty.Metrics#observationRegistry`].
You may also need to configure the Reactor Netty `ObservationHandlers` using the API provided by the framework.

== Unix Domain Sockets
The `HTTP` server supports Unix Domain Sockets (UDS) when native transport is in use.

Expand Down
10 changes: 9 additions & 1 deletion docs/asciidoc/tcp-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,17 @@ include::{examplesdir}/tracing/custom/Application.java[lines=18..80]
----
<1> Initializes Brave, Zipkin, and the Observation registry.
<2> Enables the built-in integration with Micrometer.
<3> Custom `ChannelHandler` that uses context propagation library.
<3> Custom `ChannelHandler` that uses context propagation library. This concrete example overrides only
`ChannelOutboundHandlerAdapter#connect`, if it is needed, the same logic can be used for the rest of the methods.
Also, this concrete example sets all `ThreadLocal` values for which there is a value in the given `Channel`,
if another behaviour is needed please check https://micrometer.io/docs/contextPropagation[`context propagation library API`].
For example, you may want to set only some of the `ThreadLocal` values.
====

NOTE: When you enable Reactor Netty tracing within a framework, you may need to let Reactor Netty use the `ObservationRegistry` created by this framework.
For this purpose you need to invoke {javadoc}/reactor/netty/Metrics.html#observationRegistry-io.micrometer.observation.ObservationRegistry-[`reactor.netty.Metrics#observationRegistry`].
You may also need to configure the Reactor Netty `ObservationHandlers` using the API provided by the framework.

== Unix Domain Sockets
The `TCP` client supports Unix Domain Sockets (UDS) when native transport is in use.

Expand Down
10 changes: 9 additions & 1 deletion docs/asciidoc/tcp-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,17 @@ include::{examplesdir}/tracing/custom/Application.java[lines=18..86]
----
<1> Initializes Brave, Zipkin, and the Observation registry.
<2> Enables the built-in integration with Micrometer.
<3> Custom `ChannelHandler` that uses context propagation library.
<3> Custom `ChannelHandler` that uses context propagation library. This concrete example overrides only
`ChannelInboundHandlerAdapter#channelActive`, if it is needed, the same logic can be used for the rest of the methods.
Also, this concrete example sets all `ThreadLocal` values for which there is a value in the given `Channel`,
if another behaviour is needed please check https://micrometer.io/docs/contextPropagation[`context propagation library API`].
For example, you may want to set only some of the `ThreadLocal` values.
====

NOTE: When you enable Reactor Netty tracing within a framework, you may need to let Reactor Netty use the `ObservationRegistry` created by this framework.
For this purpose you need to invoke {javadoc}/reactor/netty/Metrics.html#observationRegistry-io.micrometer.observation.ObservationRegistry-[`reactor.netty.Metrics#observationRegistry`].
You may also need to configure the Reactor Netty `ObservationHandlers` using the API provided by the framework.

== Unix Domain Sockets
The `TCP` server supports Unix Domain Sockets (UDS) when native transport is in use.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ void test(Context context, String expectation) {

TestThreadLocalHolder.value("test2");

try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(channel).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(channel)) {
assertThat(TestThreadLocalHolder.value()).isEqualTo(expectation);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -134,7 +134,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
}
if (msg instanceof ByteBuf) {
ByteBuf buffer1;
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
buffer1 = Unpooled.wrappedBuffer(TestThreadLocalHolder.value().getBytes(Charset.defaultCharset()));
}
ByteBuf buffer2 = Unpooled.wrappedBuffer(TestThreadLocalHolder.value().getBytes(Charset.defaultCharset()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,7 +75,7 @@ public boolean isSharable() {
@Override
@SuppressWarnings({"FutureReturnValueIgnored", "try"})
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
System.out.println("Current Observation in Scope: " + OBSERVATION_REGISTRY.getCurrentObservation());
//"FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,7 +75,7 @@ public boolean isSharable() {
@Override
@SuppressWarnings({"FutureReturnValueIgnored", "try"})
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
System.out.println("Current Observation in Scope: " + OBSERVATION_REGISTRY.getCurrentObservation());
//"FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,7 +70,7 @@ public boolean isSharable() {
@Override
@SuppressWarnings({"FutureReturnValueIgnored", "try"})
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
System.out.println("Current Observation in Scope: " + OBSERVATION_REGISTRY.getCurrentObservation());
//"FutureReturnValueIgnored" this is deliberate
ctx.connect(remoteAddress, localAddress, promise);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,7 @@ static final class CustomChannelInboundHandler extends ChannelInboundHandlerAdap
@Override
@SuppressWarnings("try")
public void channelActive(ChannelHandlerContext ctx) {
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
System.out.println("Current Observation in Scope: " + OBSERVATION_REGISTRY.getCurrentObservation());
ctx.fireChannelActive();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2022-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -182,7 +182,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
TestThreadLocalHolder.value(threadLocalValue);
if (msg instanceof FullHttpRequest) {
ByteBuf buffer1;
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(ctx.channel()).setThreadLocals()) {
try (ContextSnapshot.Scope scope = ContextSnapshot.setAllThreadLocalsFrom(ctx.channel())) {
buffer1 = Unpooled.wrappedBuffer(TestThreadLocalHolder.value().getBytes(Charset.defaultCharset()));
}
ByteBuf buffer2 = Unpooled.wrappedBuffer(TestThreadLocalHolder.value().getBytes(Charset.defaultCharset()));
Expand Down

0 comments on commit 135802a

Please sign in to comment.