-
Notifications
You must be signed in to change notification settings - Fork 324
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
Avoid use of trace context static methods in favor of Tracer-defined behavior #3082
Conversation
…lementations and refactor use.
…their modification.
…tion in 'priority' values.
👋 @raphw 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. |
You can find an explanation of the usage of the headers in this spec.
|
apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceHeaderDisplay.java
Outdated
Show resolved
Hide resolved
apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java
Outdated
Show resolved
Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java
Outdated
Show resolved
Hide resolved
...gin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java
Outdated
Show resolved
Hide resolved
...-plugin/apm-jms-plugin-base/src/test/java/co/elastic/apm/agent/jms/JmsInstrumentationIT.java
Outdated
Show resolved
Hide resolved
...n/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessagePropertyAccessor.java
Outdated
Show resolved
Hide resolved
...lugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java
Outdated
Show resolved
Hide resolved
I understand this better now, thanks for the clarifications. I agree with your arguments in the respect that the responsibility for the very (optional) encoding should lie with the plugins. It feels more right, and the enum does not cover all possible cases anyways. I do however not agree that the need for such encoding will disappear. Imagine, for example, that you wanted to write some plugin for some service that only accepts captialized names as headers. In this case, the W3C headers would still need to be adjusted. I also think that the plugins for binary or JMS should keep a sanity check, in case some future header would, for some reason, fail some constraint. I don't think that the W3C has all JVM technologies in the back of their head when they write their specifications. I think one of the reason I went for this approach was to avoid allocation during tracing, but revisiting, the encoding still allocates. With wrapping header getters and setters, the relevant headers can however be translated ahead of time and then it's only an (allocation free) map lookup from there. The objects are already immutable and not reallocated anyways. What I would try to do would be to reduce the |
I removed the encoding and let the plugins handle the header name translation now. This seems much cleaner to me, as you suggested. |
…ugins responsibility.
# Conflicts: # apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java # apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java # apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebHelper.java
Good points, I agree 100% here. |
run elasticsearch-ci/docs |
Currently, the agent-core version of
TraceContext
offers different constant values such as header names, and static methods to operate on these headers. This hard-codes plugins to use specific header names, and also leaves some interpretation towards how these names should be translated if they contain characters that are not otherwise allowed.This change avoids all use of the
TraceContext
class and rather delegates to theTracer
API. TheElasticApmTracer
in turn simply implements the new methods by using the existingTraceContext
implementation. Additionally, the existing static constants are replaced by a getter via theTracer
API.In this context, I found one detail that I did not fully understand. In multiple plugins, there is a propagation of
W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME
andELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME
inline in code. Within the copy/remove/contains method, aTRACESTATE_HEADER_NAME
is however also considered. Is this meant to happen? I also wonder whycontainsTraceContextTextHeaders
only checks forW3C_TRACE_PARENT_TEXTUAL_HEADER_NAME
.The currently failing SQS tests are an example for this: they transfer
W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME
andTRACESTATE_HEADER_NAME
, but notELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME
. When is what header used?Also, I found that different plugins use custom flavours of headers. I moved all this to a
TraceHeaderDisplay
which encapsulates the logic for all flavors that are used throughout the project, such that all methods become "flavor sensitive".